MCPcopy Create free account
hub / github.com/ccusage/ccusage / aggregate_rows

Function aggregate_rows

rust/crates/ccusage/src/adapter/all/loader.rs:620–640  ·  view source on GitHub ↗
(rows: Vec<AllRow>, kind: AgentReportKind)

Source from the content-addressed store, hash-verified

618}
619
620pub(super) fn aggregate_rows(rows: Vec<AllRow>, kind: AgentReportKind) -> Vec<AllRow> {
621 let mut groups = BTreeMap::<String, AllAccumulator>::new();
622 for mut row in rows {
623 let period = match kind {
624 AgentReportKind::Daily => row.period.clone(),
625 AgentReportKind::Monthly => row
626 .period
627 .get(..7)
628 .map_or_else(|| row.period.clone(), str::to_string),
629 AgentReportKind::Weekly => crate::week_start(&row.period, WeekDay::Monday)
630 .unwrap_or_else(|| row.period.clone()),
631 AgentReportKind::Session => row.period.clone(),
632 };
633 row.period = period.clone();
634 groups.entry(period).or_default().add(row);
635 }
636 groups
637 .into_iter()
638 .map(|(period, group)| group.into_row(period))
639 .collect()
640}
641
642#[cfg(test)]
643mod tests {

Calls 3

week_startFunction · 0.85
addMethod · 0.80
into_rowMethod · 0.80