workspace: initial clean commit
This commit is contained in:
116
tasks/scripts/token_summary.py
Normal file
116
tasks/scripts/token_summary.py
Normal file
@@ -0,0 +1,116 @@
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
import glob
|
||||
|
||||
def parse_iso(timestamp):
|
||||
# Parse ISO timestamp with timezone
|
||||
try:
|
||||
dt = datetime.fromisoformat(timestamp.replace('Z', '+00:00'))
|
||||
return dt
|
||||
except Exception as e:
|
||||
print(f'Error parsing {timestamp}: {e}')
|
||||
return None
|
||||
|
||||
def process_session_file(path):
|
||||
today = datetime(2026, 3, 22, tzinfo=timezone.utc)
|
||||
total_input = 0
|
||||
total_output = 0
|
||||
total_cost = 0.0
|
||||
model_counts = {}
|
||||
|
||||
with open(path, 'r') as f:
|
||||
for line_num, line in enumerate(f, 1):
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
try:
|
||||
data = json.loads(line)
|
||||
except json.JSONDecodeError as e:
|
||||
continue
|
||||
|
||||
# Check timestamp for today
|
||||
timestamp = data.get('timestamp')
|
||||
if not timestamp:
|
||||
continue
|
||||
dt = parse_iso(timestamp)
|
||||
if not dt:
|
||||
continue
|
||||
if dt.date() != today.date():
|
||||
continue
|
||||
|
||||
# We need messages with usage (assistant responses)
|
||||
if data.get('type') == 'message':
|
||||
msg = data.get('message', {})
|
||||
if msg.get('role') == 'assistant' and 'usage' in msg:
|
||||
usage = msg['usage']
|
||||
input_tokens = usage.get('input', 0)
|
||||
output_tokens = usage.get('output', 0)
|
||||
cache_read = usage.get('cacheRead', 0)
|
||||
cache_write = usage.get('cacheWrite', 0)
|
||||
# cost may be inside usage['cost']
|
||||
cost = usage.get('cost', {})
|
||||
cost_total = cost.get('total', 0.0)
|
||||
model = msg.get('model', 'unknown')
|
||||
|
||||
total_input += input_tokens
|
||||
total_output += output_tokens
|
||||
total_cost += cost_total
|
||||
|
||||
# Track per model
|
||||
if model not in model_counts:
|
||||
model_counts[model] = {'input': 0, 'output': 0, 'cost': 0.0}
|
||||
model_counts[model]['input'] += input_tokens
|
||||
model_counts[model]['output'] += output_tokens
|
||||
model_counts[model]['cost'] += cost_total
|
||||
|
||||
return total_input, total_output, total_cost, model_counts
|
||||
|
||||
sessions_dir = '/home/node/.openclaw/agents/main/sessions'
|
||||
jsonl_files = glob.glob(os.path.join(sessions_dir, '*.jsonl'))
|
||||
|
||||
print('📊 Сводка использования токенов за сегодня (2026-03-22)')
|
||||
print('=' * 60)
|
||||
|
||||
overall_input = 0
|
||||
overall_output = 0
|
||||
overall_cost = 0.0
|
||||
all_model_counts = {}
|
||||
|
||||
for file_path in jsonl_files:
|
||||
file_name = os.path.basename(file_path)
|
||||
print(f'\n📁 Файл сессии: {file_name}')
|
||||
inp, out, cost, models = process_session_file(file_path)
|
||||
print(f' Входные токены: {inp:,}')
|
||||
print(f' Выходные токены: {out:,}')
|
||||
print(f' Примерная стоимость: ${cost:.6f}')
|
||||
if models:
|
||||
for model, counts in models.items():
|
||||
print(f' Модель: {model}')
|
||||
print(f' вход: {counts[\"input\"]:,}, выход: {counts[\"output\"]:,}, стоимость: ${counts[\"cost\"]:.6f}')
|
||||
# Aggregate across files
|
||||
if model not in all_model_counts:
|
||||
all_model_counts[model] = counts.copy()
|
||||
else:
|
||||
all_model_counts[model]['input'] += counts['input']
|
||||
all_model_counts[model]['output'] += counts['output']
|
||||
all_model_counts[model]['cost'] += counts['cost']
|
||||
|
||||
overall_input += inp
|
||||
overall_output += out
|
||||
overall_cost += cost
|
||||
|
||||
print('\n' + '=' * 60)
|
||||
print('📈 ОБЩИЙ ИТОГ за сегодня:')
|
||||
print(f' Всего входных токенов: {overall_input:,}')
|
||||
print(f' Всего выходных токенов: {overall_output:,}')
|
||||
print(f' Общая стоимость: ${overall_cost:.6f}')
|
||||
print()
|
||||
print('📋 По моделям:')
|
||||
for model, counts in all_model_counts.items():
|
||||
print(f' • {model}')
|
||||
print(f' вход: {counts[\"input\"]:,} токенов, выход: {counts[\"output\"]:,} токенов')
|
||||
print(f' стоимость: ${counts[\"cost\"]:.6f}')
|
||||
print()
|
||||
print('💡 Примечание: стоимость может не включать кэшированные токены.')
|
||||
print(' Данные основаны на записях сессий.')
|
||||
91
tasks/scripts/usage_summary.py
Normal file
91
tasks/scripts/usage_summary.py
Normal file
@@ -0,0 +1,91 @@
|
||||
import json
|
||||
import glob
|
||||
from datetime import datetime
|
||||
|
||||
def parse_iso(timestamp):
|
||||
try:
|
||||
return datetime.fromisoformat(timestamp.replace('Z', '+00:00'))
|
||||
except:
|
||||
return None
|
||||
|
||||
today = datetime(2026, 3, 22).date()
|
||||
sessions_dir = '/home/node/.openclaw/agents/main/sessions'
|
||||
jsonl_files = glob.glob(sessions_dir + '/*.jsonl')
|
||||
|
||||
claude_input = 0
|
||||
claude_output = 0
|
||||
claude_cost = 0.0
|
||||
deepseek_input = 0
|
||||
deepseek_output = 0
|
||||
deepseek_cost = 0.0
|
||||
|
||||
for file_path in jsonl_files:
|
||||
with open(file_path, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
try:
|
||||
data = json.loads(line)
|
||||
except:
|
||||
continue
|
||||
if data.get('type') != 'message':
|
||||
continue
|
||||
msg = data.get('message', {})
|
||||
if msg.get('role') != 'assistant' or 'usage' not in msg:
|
||||
continue
|
||||
timestamp = data.get('timestamp')
|
||||
if not timestamp:
|
||||
continue
|
||||
dt = parse_iso(timestamp)
|
||||
if not dt or dt.date() != today:
|
||||
continue
|
||||
usage = msg['usage']
|
||||
inp = usage.get('input', 0)
|
||||
out = usage.get('output', 0)
|
||||
cost = usage.get('cost', {}).get('total', 0.0)
|
||||
model = msg.get('model', '')
|
||||
if 'claude' in model.lower():
|
||||
claude_input += inp
|
||||
claude_output += out
|
||||
claude_cost += cost
|
||||
elif 'deepseek' in model.lower():
|
||||
deepseek_input += inp
|
||||
deepseek_output += out
|
||||
deepseek_cost += cost
|
||||
|
||||
total_input = claude_input + deepseek_input
|
||||
total_output = claude_output + deepseek_output
|
||||
total_cost = claude_cost + deepseek_cost
|
||||
|
||||
print('=== Сводка использования OpenRouter за 22 марта 2026 ===')
|
||||
print()
|
||||
print('📊 По моделям:')
|
||||
print('1. Claude Sonnet 4.6')
|
||||
print(' • Входные токены:', f'{claude_input:,}')
|
||||
print(' • Выходные токены:', f'{claude_output:,}')
|
||||
print(' • Стоимость: $' + f'{claude_cost:.6f}')
|
||||
print()
|
||||
print('2. DeepSeek V3.2')
|
||||
print(' • Входные токены:', f'{deepseek_input:,}')
|
||||
print(' • Выходные токены:', f'{deepseek_output:,}')
|
||||
print(' • Стоимость: $' + f'{deepseek_cost:.6f}')
|
||||
print()
|
||||
print('📈 ИТОГО:')
|
||||
print(' Всего входных токенов:', f'{total_input:,}')
|
||||
print(' Всего выходных токенов:', f'{total_output:,}')
|
||||
print(' Общая стоимость: $' + f'{total_cost:.6f}')
|
||||
print()
|
||||
print('💎 Средняя стоимость за 1 тыс. входных токенов:')
|
||||
if total_input > 0:
|
||||
avg = total_cost / total_input * 1000
|
||||
print(' $' + f'{avg:.6f}')
|
||||
else:
|
||||
print(' N/A')
|
||||
print()
|
||||
print('🔄 Переход на DeepSeek:')
|
||||
print(' • Claude использовался до ~06:30 UTC')
|
||||
print(' • DeepSeek используется с ~06:30 UTC')
|
||||
print()
|
||||
print('💡 Примечание: входные токены включают контекст всей сессии,')
|
||||
print(' который пересылается при каждом запросе. Выходные токены — ответы модели.')
|
||||
Reference in New Issue
Block a user