Skip to main content

khive_fold/objective/
context.rs

1//! Objective evaluation context
2
3use chrono::{DateTime, Utc};
4#[cfg(feature = "serde")]
5use serde::{Deserialize, Serialize};
6
7/// Context for objective evaluation; `as_of` defaults to Unix epoch.
8#[derive(Debug, Clone, Default)]
9#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10pub struct ObjectiveContext {
11    /// Evaluation time
12    pub as_of: DateTime<Utc>,
13    /// Maximum candidates to consider
14    pub max_candidates: Option<usize>,
15    /// Minimum score threshold
16    pub min_score: Option<f64>,
17    /// Extra context data
18    #[cfg_attr(feature = "serde", serde(default))]
19    pub extra: serde_json::Value,
20}
21
22impl ObjectiveContext {
23    /// Create a new context with the Unix epoch as `as_of`.
24    pub fn new() -> Self {
25        Self::default()
26    }
27
28    /// Create context for a specific time
29    pub fn at(time: DateTime<Utc>) -> Self {
30        Self {
31            as_of: time,
32            ..Default::default()
33        }
34    }
35
36    /// Set maximum candidates
37    pub fn with_max_candidates(mut self, n: usize) -> Self {
38        self.max_candidates = Some(n);
39        self
40    }
41
42    /// Set minimum score threshold
43    pub fn with_min_score(mut self, score: f64) -> Self {
44        self.min_score = Some(score);
45        self
46    }
47
48    /// Set extra context
49    pub fn with_extra(mut self, extra: serde_json::Value) -> Self {
50        self.extra = extra;
51        self
52    }
53}