修正 Codex 当日 token 日期口径
This commit is contained in:
parent
b4e55e067e
commit
2ab6a4e4b0
@ -584,9 +584,8 @@ class CodexRateLimitReader:
|
||||
|
||||
@staticmethod
|
||||
def _daily_bars_from_buckets(buckets: list[dict]) -> tuple[int, str]:
|
||||
today = date.today()
|
||||
wanted_days = [(today - timedelta(days=offset)).isoformat() for offset in range(CODEX_DAILY_BAR_COUNT - 1, -1, -1)]
|
||||
tokens_by_day: dict[str, int] = {}
|
||||
latest_day: date | None = None
|
||||
|
||||
for bucket in buckets:
|
||||
if not isinstance(bucket, dict):
|
||||
@ -595,6 +594,20 @@ class CodexRateLimitReader:
|
||||
tokens = bucket.get("tokens")
|
||||
if isinstance(start_date, str) and isinstance(tokens, (int, float)) and tokens >= 0:
|
||||
tokens_by_day[start_date] = int(tokens)
|
||||
try:
|
||||
bucket_day = date.fromisoformat(start_date)
|
||||
except ValueError:
|
||||
continue
|
||||
if latest_day is None or bucket_day > latest_day:
|
||||
latest_day = bucket_day
|
||||
|
||||
if latest_day is None:
|
||||
return -1, ""
|
||||
|
||||
wanted_days = [
|
||||
(latest_day - timedelta(days=offset)).isoformat()
|
||||
for offset in range(CODEX_DAILY_BAR_COUNT - 1, -1, -1)
|
||||
]
|
||||
|
||||
values = [tokens_by_day.get(day, 0) for day in wanted_days]
|
||||
max_value = max(values) if values else 0
|
||||
@ -603,7 +616,7 @@ class CodexRateLimitReader:
|
||||
else:
|
||||
percents = [0 for _ in values]
|
||||
|
||||
today_tokens_m10 = CodexRateLimitReader._tokens_to_m10(tokens_by_day.get(today.isoformat(), -1))
|
||||
today_tokens_m10 = CodexRateLimitReader._tokens_to_m10(tokens_by_day.get(latest_day.isoformat(), -1))
|
||||
return today_tokens_m10, ":".join(str(value) for value in percents)
|
||||
|
||||
def read_usage_snapshot(self) -> tuple[int, str]:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user