Cost control
This commit is contained in:
60
src/view_costs.py
Normal file
60
src/view_costs.py
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python3
|
||||
"""View cost statistics from the database"""
|
||||
|
||||
import asyncio
|
||||
from .config import get_config
|
||||
from .storage.database import Database
|
||||
|
||||
|
||||
async def main():
|
||||
"""Display cost statistics"""
|
||||
config = get_config()
|
||||
db = Database(config.database.path)
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("News Agent Cost Statistics")
|
||||
print("=" * 60 + "\n")
|
||||
|
||||
# Get total cost
|
||||
total_cost = await db.get_total_cost()
|
||||
print(f"💰 Total Cumulative Cost: ${total_cost:.4f}")
|
||||
print()
|
||||
|
||||
# Get recent runs
|
||||
runs = await db.get_run_stats(limit=20)
|
||||
|
||||
if not runs:
|
||||
print("No runs recorded yet.")
|
||||
return
|
||||
|
||||
print(f"Recent Runs (last {len(runs)}):")
|
||||
print("-" * 60)
|
||||
print(f"{'Date':<12} {'Articles':<10} {'Included':<10} {'Cost':<10}")
|
||||
print("-" * 60)
|
||||
|
||||
for run in runs:
|
||||
date = run["run_date"]
|
||||
articles = run["articles_processed"]
|
||||
included = run["articles_included"]
|
||||
cost = run["total_cost"]
|
||||
|
||||
print(f"{date:<12} {articles:<10} {included:<10} ${cost:<9.4f}")
|
||||
|
||||
print("-" * 60)
|
||||
|
||||
# Calculate averages
|
||||
if runs:
|
||||
avg_cost = sum(r["total_cost"] for r in runs) / len(runs)
|
||||
avg_articles = sum(r["articles_included"] for r in runs) / len(runs)
|
||||
|
||||
print(f"\nAverages (last {len(runs)} runs):")
|
||||
print(f" Cost per run: ${avg_cost:.4f}")
|
||||
print(f" Articles per digest: {avg_articles:.1f}")
|
||||
if avg_articles > 0:
|
||||
print(f" Cost per article: ${avg_cost / avg_articles:.4f}")
|
||||
|
||||
print("\n" + "=" * 60 + "\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user