Garm commited on
Commit
3d4e512
·
1 Parent(s): 6de75aa

Polish rebased display-session stack

Browse files
headroom/proxy/savings_tracker.py CHANGED
@@ -824,7 +824,10 @@ class SavingsTracker:
824
  delta_tokens = max(total_tokens_saved - prev_total_tokens, 0)
825
  delta_usd = max(total_usd - prev_total_usd, 0.0)
826
  delta_input_tokens = max(total_input_tokens - prev_total_input_tokens, 0)
827
- delta_input_cost_usd = max(total_input_cost_usd - prev_total_input_cost_usd, 0.0)
 
 
 
828
 
829
  prev_total_tokens = total_tokens_saved
830
  prev_total_usd = total_usd
 
824
  delta_tokens = max(total_tokens_saved - prev_total_tokens, 0)
825
  delta_usd = max(total_usd - prev_total_usd, 0.0)
826
  delta_input_tokens = max(total_input_tokens - prev_total_input_tokens, 0)
827
+ delta_input_cost_usd = max(
828
+ total_input_cost_usd - prev_total_input_cost_usd,
829
+ 0.0,
830
+ )
831
 
832
  prev_total_tokens = total_tokens_saved
833
  prev_total_usd = total_usd
tests/test_proxy_savings_history.py CHANGED
@@ -362,7 +362,9 @@ def test_display_session_rolls_after_inactivity_and_counts_zero_savings_requests
362
  }
363
 
364
 
365
- def test_savings_tracker_rollups_preserve_spend_and_input_history(tmp_path, monkeypatch):
 
 
366
  path = tmp_path / "proxy_savings.json"
367
  tracker = SavingsTracker(
368
  path=str(path),
@@ -553,9 +555,9 @@ def test_stats_history_persists_across_restarts_and_stats_stays_compatible(
553
  ]
554
  assert history_data["exports"]["available_series"][-2:] == ["weekly", "monthly"]
555
  assert history_data["series"]["hourly"][0]["total_input_tokens_delta"] == 120
556
- assert history_data["series"]["hourly"][0]["total_input_cost_usd_delta"] == pytest.approx(
557
- 0.24
558
- )
559
 
560
  assert stats_data["display_session"] == history_data["display_session"]
561
  assert (
@@ -582,7 +584,9 @@ def test_stats_history_persists_across_restarts_and_stats_stays_compatible(
582
  assert updated["display_session"]["total_input_tokens"] == 240
583
  assert updated["display_session"]["savings_percent"] == pytest.approx(18.64)
584
  assert updated["series"]["daily"][0]["total_input_tokens_delta"] == 240
585
- assert updated["series"]["daily"][0]["total_input_cost_usd_delta"] == pytest.approx(0.48)
 
 
586
 
587
  persisted = json.loads(savings_path.read_text())
588
  assert persisted["lifetime"]["tokens_saved"] == 55
 
362
  }
363
 
364
 
365
+ def test_savings_tracker_rollups_preserve_spend_and_input_history(
366
+ tmp_path, monkeypatch
367
+ ):
368
  path = tmp_path / "proxy_savings.json"
369
  tracker = SavingsTracker(
370
  path=str(path),
 
555
  ]
556
  assert history_data["exports"]["available_series"][-2:] == ["weekly", "monthly"]
557
  assert history_data["series"]["hourly"][0]["total_input_tokens_delta"] == 120
558
+ assert history_data["series"]["hourly"][0][
559
+ "total_input_cost_usd_delta"
560
+ ] == pytest.approx(0.24)
561
 
562
  assert stats_data["display_session"] == history_data["display_session"]
563
  assert (
 
584
  assert updated["display_session"]["total_input_tokens"] == 240
585
  assert updated["display_session"]["savings_percent"] == pytest.approx(18.64)
586
  assert updated["series"]["daily"][0]["total_input_tokens_delta"] == 240
587
+ assert updated["series"]["daily"][0][
588
+ "total_input_cost_usd_delta"
589
+ ] == pytest.approx(0.48)
590
 
591
  persisted = json.loads(savings_path.read_text())
592
  assert persisted["lifetime"]["tokens_saved"] == 55