|
7 | 7 | import argparse |
8 | 8 | from dataclasses import dataclass |
9 | 9 | from datetime import datetime |
| 10 | +from decimal import Decimal |
10 | 11 | import sys |
11 | 12 | from typing import Any, Dict, List |
12 | 13 | import urllib3 |
|
22 | 23 | @dataclass |
23 | 24 | class JobStats: |
24 | 25 | count: int |
| 26 | + coins: Decimal |
25 | 27 | earliest: datetime |
26 | 28 | latest: datetime |
27 | 29 |
|
28 | 30 | def __repr__(self) -> str: |
29 | | - return f'{self.count} {self.earliest.date()}/{self.latest.date()}' |
| 31 | + i_str = 'Instance' if self.count == 1 else 'Instances' |
| 32 | + return f'{self.coins} Coins {self.count} {i_str} From {self.earliest.date()} Until {self.latest.date()}' |
30 | 33 |
|
31 | 34 |
|
32 | 35 | def main(c_args: argparse.Namespace) -> None: |
@@ -67,20 +70,22 @@ def main(c_args: argparse.Namespace) -> None: |
67 | 70 | if "processing_charges" in c_rv.msg: |
68 | 71 | for processing_charge in c_rv.msg["processing_charges"]: |
69 | 72 | if "additional_data" in processing_charge["charge"]: |
| 73 | + coins: Decimal = Decimal(processing_charge["charge"]["coins"]) |
70 | 74 | timestamp: datetime = datetime.fromisoformat(processing_charge["charge"]["timestamp"]) |
71 | 75 | ad: Dict[str, Any] = processing_charge["charge"]["additional_data"] |
72 | 76 | if "job_collection" in ad: |
73 | 77 | job_str: str = f'{ad["job_collection"]}|{ad["job_job"]}|{ad["job_version"]}' |
74 | 78 | if job_str in org_jobs: |
75 | 79 | job_stats = org_jobs[job_str] |
76 | 80 | job_stats.count += 1 |
| 81 | + job_stats.coins += coins |
77 | 82 | if timestamp < job_stats.earliest: |
78 | 83 | job_stats.earliest = timestamp |
79 | 84 | elif timestamp > job_stats.latest: |
80 | 85 | job_stats.latest = timestamp |
81 | 86 | org_jobs[job_str] = job_stats |
82 | 87 | else: |
83 | | - org_jobs[job_str] = JobStats(count=1, earliest=timestamp, latest=timestamp) |
| 88 | + org_jobs[job_str] = JobStats(count=1, coins=coins, earliest=timestamp, latest=timestamp) |
84 | 89 | jobs: List[str] = org_jobs.keys() |
85 | 90 | for job in sorted(jobs): |
86 | 91 | print(f'{job}: ({org_jobs[job]})') |
|
0 commit comments