use crate::schema::NodeEvent;
pub(crate) fn parse_time_token(tok: &str) -> Option<f64> {
let t = tok.trim();
let (num, mul) = if let Some(n) = t.strip_suffix('s') {
(n, 1.0)
} else if let Some(n) = t.strip_suffix('m') {
(n, 60.0)
} else if let Some(n) = t.strip_suffix('h') {
(n, 3600.0)
} else {
(t, 1.0)
};
num.parse::<f64>().ok().map(|v| v * mul)
}
pub(crate) fn parse_or_dash(tok: &str) -> Option<f64> {
let t = tok.trim();
if t == "-" || t.is_empty() {
None
} else {
t.parse().ok()
}
}
pub(crate) fn parse_gap(tok: &str) -> Option<f64> {
let t = tok.trim();
if t == "-" || t.is_empty() || t.eq_ignore_ascii_case("inf") {
return None;
}
let s = t.strip_suffix('%').unwrap_or(t).trim();
s.parse::<f64>().ok().map(|v| v / 100.0)
}
pub(crate) fn event_from_marker(marker: char) -> Option<NodeEvent> {
match marker {
' ' | '\t' => None,
'H' | 'h' => Some(NodeEvent::Heuristic),
'*' => Some(NodeEvent::BranchSolution),
other => Some(NodeEvent::Other(other.to_string())),
}
}