pumpkin_core/statistics/
statistic_logger.rs

1use std::fmt::Display;
2
3use itertools::Itertools;
4
5use super::statistic_logging::log_statistic;
6#[cfg(doc)]
7use crate::engine::propagation::Propagator;
8
9/// Responsible for logging the statistics with the provided prefix; currently used when logging
10/// the statistics of propagators.
11#[derive(Debug, Default, Clone)]
12pub struct StatisticLogger {
13    /// The prefix which will be attached to the statistic name
14    name_prefix: String,
15}
16
17impl StatisticLogger {
18    pub fn new<Input: IntoIterator<Item = impl Display>>(name_prefix: Input) -> Self {
19        Self {
20            name_prefix: name_prefix.into_iter().join("_"),
21        }
22    }
23
24    /// Attaches the provided `addition_to_prefix` to the stored internal prefix and returns a new
25    /// [`StatisticLogger`] with these two prefixes.
26    pub fn attach_to_prefix(&self, addition_to_prefix: impl Display) -> Self {
27        Self {
28            name_prefix: format!("{}_{}", self.name_prefix, addition_to_prefix),
29        }
30    }
31
32    pub fn log_statistic(&self, value: impl Display) {
33        log_statistic(&self.name_prefix, value);
34    }
35}