Add operations overview and category usage tracking
This commit is contained in:
+10
-2
@@ -124,6 +124,7 @@ def scheduled_codex_usage(directory, start, end):
|
||||
totals = {k: 0 for k in ('input_tokens', 'cached_input_tokens', 'output_tokens', 'reasoning_output_tokens')}
|
||||
api_totals = dict.fromkeys(totals, 0)
|
||||
runs = failed = 0
|
||||
categories = {}
|
||||
api_runs = api_uncertain = api_usage_events = 0
|
||||
for path in Path(directory).glob('*.summary.json'):
|
||||
try:
|
||||
@@ -142,12 +143,19 @@ def scheduled_codex_usage(directory, start, end):
|
||||
for k in api_totals:
|
||||
api_totals[k] += max(0, int(usage.get(k, 0)))
|
||||
continue
|
||||
category = record.get('category') if record.get('category') in ('content', 'engineering', 'research', 'community', 'management') else 'unattributed'
|
||||
lane = categories.setdefault(category, {'runs': 0, 'elapsed_seconds': 0, 'elapsed_missing': 0, **dict.fromkeys(totals, 0)})
|
||||
lane['runs'] += 1
|
||||
if isinstance(record.get('elapsed_seconds'), (int, float)) and record['elapsed_seconds'] >= 0: lane['elapsed_seconds'] += record['elapsed_seconds']
|
||||
else: lane['elapsed_missing'] += 1
|
||||
for usage in record.get('usage', []):
|
||||
for k in totals:
|
||||
totals[k] += max(0, int(usage.get(k, 0)))
|
||||
amount = max(0, int(usage.get(k, 0)))
|
||||
totals[k] += amount
|
||||
lane[k] += amount
|
||||
except (ValueError, OSError, KeyError, TypeError, AttributeError):
|
||||
continue
|
||||
return {'available': True, 'runs': runs, 'failed_runs': failed, 'api_runs_separate': api_runs, 'api_runs_uncertain': api_uncertain, 'api_observed_usage': api_totals if api_usage_events else None, **totals,
|
||||
return {'available': True, 'runs': runs, 'failed_runs': failed, 'api_runs_separate': api_runs, 'api_runs_uncertain': api_uncertain, 'api_observed_usage': api_totals if api_usage_events else None, 'by_category': categories, **totals,
|
||||
'measurement_note': '来自独立定时会话的运行汇总,与交互会话分开统计;API 备用调用不计入订阅 token,实际成本单独核算。失败或中断可能没有完整用量。'}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user