1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use super::{CsvInputSource, EventSourceConfig, OutputChannel};

#[derive(Clone, Debug)]
pub struct EvalConfig {
    pub source: EventSourceConfig,
    pub statistics: Statistics,
    pub verbosity: Verbosity,
    pub output_channel: OutputChannel,
    pub mode: ExecutionMode,
    pub time_presentation: TimeRepresentation,
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub enum Statistics {
    None,
    Debug,
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub enum Verbosity {
    /// Suppresses any kind of logging.
    Silent,
    /// Prints statistical information like number of events, triggers, etc.
    Progress,
    /// Prints nothing but runtime warnings about potentially critical states, e.g. dropped
    /// evaluation cycles.
    WarningsOnly,
    /// Prints only triggers and runtime warnings.
    Triggers,
    /// Prints information about all or a subset of output streams whenever they produce a new
    /// value.
    Outputs,
    /// Prints fine-grained debug information. Not suitable for production.
    Debug,
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum ExecutionMode {
    Offline,
    Online,
    Api,
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum TimeRepresentation {
    Hide,
    Relative(TimeFormat),
    Absolute(TimeFormat),
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum TimeFormat {
    UIntNanos,
    FloatSecs,
    HumanTime,
}

impl EvalConfig {
    pub fn new(
        source: EventSourceConfig,
        statistics: Statistics,
        verbosity: Verbosity,
        output: OutputChannel,
        mode: ExecutionMode,
        time_presentation: TimeRepresentation,
    ) -> Self {
        EvalConfig { source, statistics, verbosity, output_channel: output, mode, time_presentation }
    }

    pub fn debug() -> Self {
        EvalConfig { statistics: Statistics::Debug, verbosity: Verbosity::Debug, ..Default::default() }
    }

    pub fn release(
        path: String,
        output: OutputChannel,
        mode: ExecutionMode,
        time_presentation: TimeRepresentation,
    ) -> Self {
        EvalConfig::new(
            EventSourceConfig::Csv { src: CsvInputSource::file(path, None, None) },
            Statistics::None,
            Verbosity::Triggers,
            output,
            mode,
            time_presentation,
        )
    }

    pub fn api(time_representation: TimeRepresentation) -> Self {
        EvalConfig::new(
            EventSourceConfig::Api,
            Statistics::None,
            Verbosity::Triggers,
            OutputChannel::None,
            ExecutionMode::Api,
            time_representation,
        )
    }
}

impl Default for EvalConfig {
    fn default() -> EvalConfig {
        EvalConfig {
            source: EventSourceConfig::Csv { src: CsvInputSource::StdIn },
            statistics: Statistics::None,
            verbosity: Verbosity::Triggers,
            output_channel: OutputChannel::StdOut,
            mode: ExecutionMode::Offline,
            time_presentation: TimeRepresentation::Hide,
        }
    }
}