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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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 evaluator: EvaluatorChoice,
    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 EvaluatorChoice {
    ClosureBased,
    Interpreted,
}

#[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,
        evaluator: EvaluatorChoice,
        mode: ExecutionMode,
        time_presentation: TimeRepresentation,
    ) -> Self {
        EvalConfig { source, statistics, verbosity, output_channel: output, evaluator, mode, time_presentation }
    }

    pub fn debug() -> Self {
        let mut cfg = EvalConfig::default();
        cfg.statistics = Statistics::Debug;
        cfg.verbosity = Verbosity::Debug;
        cfg
    }

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

    pub fn api(time_representation: TimeRepresentation) -> Self {
        EvalConfig::new(
            EventSourceConfig::API,
            Statistics::None,
            Verbosity::Triggers,
            OutputChannel::None,
            EvaluatorChoice::ClosureBased,
            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,
            evaluator: EvaluatorChoice::ClosureBased,
            mode: ExecutionMode::Offline,
            time_presentation: TimeRepresentation::Hide,
        }
    }
}