Spaces:
Running on Zero
Running on Zero
Show successful usage over the last 30 days including today
Browse files- SUCCESS_COUNTS.md +3 -3
- space_success_stats.py +27 -36
SUCCESS_COUNTS.md
CHANGED
|
@@ -5,11 +5,11 @@ their GPU calls return successfully. The Scene Space embeds the same backend,
|
|
| 5 |
so a scene generated through either entry point counts once for Scene. Mesh
|
| 6 |
extraction, camera previews, downloads, visits, and failed requests do not count.
|
| 7 |
|
| 8 |
-
Badges at the right edge of each title row show the
|
| 9 |
successful runs. The **Daily success history** panel contains the daily table
|
| 10 |
-
for
|
| 11 |
`America/Los_Angeles`. History before instrumentation starts is unavailable;
|
| 12 |
-
|
| 13 |
|
| 14 |
The private dataset `CaiYuanhao/space-success-stats` stores the aggregate counts.
|
| 15 |
Add a long-lived fine-grained token with read/write permission only for that
|
|
|
|
| 5 |
so a scene generated through either entry point counts once for Scene. Mesh
|
| 6 |
extraction, camera previews, downloads, visits, and failed requests do not count.
|
| 7 |
|
| 8 |
+
Badges at the right edge of each title row show the last 30 days' total and today's
|
| 9 |
successful runs. The **Daily success history** panel contains the daily table
|
| 10 |
+
for today and the preceding 29 days. Dates use
|
| 11 |
`America/Los_Angeles`. History before instrumentation starts is unavailable;
|
| 12 |
+
the total includes the available recorded activity without waiting for a full month.
|
| 13 |
|
| 14 |
The private dataset `CaiYuanhao/space-success-stats` stores the aggregate counts.
|
| 15 |
Add a long-lived fine-grained token with read/write permission only for that
|
space_success_stats.py
CHANGED
|
@@ -167,58 +167,49 @@ class SuccessStats:
|
|
| 167 |
return summarize(data, channel, now=now)
|
| 168 |
|
| 169 |
|
| 170 |
-
def
|
|
|
|
| 171 |
local = (now or datetime.now(timezone.utc)).astimezone(ZoneInfo(TIMEZONE))
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
previous_start = previous_end.replace(day=1)
|
| 175 |
-
label = previous_start.strftime("%Y-%m")
|
| 176 |
-
start = data["started_at"].get(channel)
|
| 177 |
if not start:
|
| 178 |
-
return
|
| 179 |
started = datetime.fromisoformat(start).astimezone(ZoneInfo(TIMEZONE))
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
rows = []
|
| 190 |
day = local.date()
|
| 191 |
-
earliest = max(
|
| 192 |
while day >= earliest:
|
| 193 |
rows.append([day.isoformat(), data["days"].get(day.isoformat(), {}).get(channel, 0)])
|
| 194 |
day -= timedelta(days=1)
|
| 195 |
-
summary = (f"**Last
|
| 196 |
-
f"
|
|
|
|
|
|
|
| 197 |
"Earlier activity is not included. Only completed enhancement or generation runs count.")
|
| 198 |
return summary, rows
|
| 199 |
|
| 200 |
|
| 201 |
def success_badges(data, channel, *, now=None, title=None):
|
| 202 |
"""Keep unavailable history distinct from a measured count of zero."""
|
| 203 |
-
local = (
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
previous, today = "—", "—"
|
| 207 |
-
previous_note = "No historical data"
|
| 208 |
today_note = "Success counts are temporarily unavailable"
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
started = datetime.fromisoformat(started_at).astimezone(ZoneInfo(TIMEZONE))
|
| 212 |
today = f'{data["days"].get(local.date().isoformat(), {}).get(channel, 0):,}'
|
| 213 |
today_note = f"Successful runs on {local:%Y-%m-%d} ({TIMEZONE})"
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
if previous_start.isoformat() <= day <= previous_end.isoformat())
|
| 217 |
-
previous = f"{total:,}"
|
| 218 |
-
beginning = datetime.combine(previous_start, datetime.min.time(), tzinfo=ZoneInfo(TIMEZONE))
|
| 219 |
-
if started > beginning:
|
| 220 |
-
previous += " (partial)"
|
| 221 |
-
previous_note = f"Successful runs in {previous_start:%Y-%m}; tracking started {started:%Y-%m-%d}"
|
| 222 |
|
| 223 |
def chip(label, value, note):
|
| 224 |
return (
|
|
@@ -233,7 +224,7 @@ def success_badges(data, channel, *, now=None, title=None):
|
|
| 233 |
badges = ('<div style="display:flex;flex-wrap:wrap;justify-content:flex-end;gap:10px;'
|
| 234 |
'margin-left:auto;flex:0 0 auto;" '
|
| 235 |
'aria-label="Successful runs">'
|
| 236 |
-
+ chip("Last
|
| 237 |
+ chip("Today", today, today_note) + '</div>')
|
| 238 |
if title is None:
|
| 239 |
return badges
|
|
|
|
| 167 |
return summarize(data, channel, now=now)
|
| 168 |
|
| 169 |
|
| 170 |
+
def rolling_period(data, channel, *, now=None):
|
| 171 |
+
"""Today and the preceding 29 local dates, using the stored daily counts."""
|
| 172 |
local = (now or datetime.now(timezone.utc)).astimezone(ZoneInfo(TIMEZONE))
|
| 173 |
+
first_day = local.date() - timedelta(days=29)
|
| 174 |
+
start = data["started_at"].get(channel) if data else None
|
|
|
|
|
|
|
|
|
|
| 175 |
if not start:
|
| 176 |
+
return local, first_day, None, None
|
| 177 |
started = datetime.fromisoformat(start).astimezone(ZoneInfo(TIMEZONE))
|
| 178 |
+
total = sum(values.get(channel, 0) for day, values in data["days"].items()
|
| 179 |
+
if first_day.isoformat() <= day <= local.date().isoformat())
|
| 180 |
+
return local, first_day, started, total
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def summarize(data, channel, *, now=None):
|
| 184 |
+
local, first_day, started, total = rolling_period(data, channel, now=now)
|
| 185 |
+
if started is None:
|
| 186 |
+
return "**Last 30 days:** No historical data. Tracking has not started.", []
|
| 187 |
rows = []
|
| 188 |
day = local.date()
|
| 189 |
+
earliest = max(first_day, started.date())
|
| 190 |
while day >= earliest:
|
| 191 |
rows.append([day.isoformat(), data["days"].get(day.isoformat(), {}).get(channel, 0)])
|
| 192 |
day -= timedelta(days=1)
|
| 193 |
+
summary = (f"**Last 30 days ({first_day:%Y-%m-%d} – {local:%Y-%m-%d}):** "
|
| 194 |
+
f"{total:,} successful runs.\n\n"
|
| 195 |
+
f"The total includes today and the preceding 29 days, using {TIMEZONE}. "
|
| 196 |
+
f"Tracking started {started:%Y-%m-%d %H:%M %Z}. "
|
| 197 |
"Earlier activity is not included. Only completed enhancement or generation runs count.")
|
| 198 |
return summary, rows
|
| 199 |
|
| 200 |
|
| 201 |
def success_badges(data, channel, *, now=None, title=None):
|
| 202 |
"""Keep unavailable history distinct from a measured count of zero."""
|
| 203 |
+
local, first_day, started, total = rolling_period(data, channel, now=now)
|
| 204 |
+
recent, today = "—", "—"
|
| 205 |
+
recent_note = "No historical data"
|
|
|
|
|
|
|
| 206 |
today_note = "Success counts are temporarily unavailable"
|
| 207 |
+
if started is not None:
|
| 208 |
+
recent = f"{total:,}"
|
|
|
|
| 209 |
today = f'{data["days"].get(local.date().isoformat(), {}).get(channel, 0):,}'
|
| 210 |
today_note = f"Successful runs on {local:%Y-%m-%d} ({TIMEZONE})"
|
| 211 |
+
recent_note = (f"Successful runs from {first_day:%Y-%m-%d} through {local:%Y-%m-%d} "
|
| 212 |
+
f"({TIMEZONE}); recorded since {started:%Y-%m-%d}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
def chip(label, value, note):
|
| 215 |
return (
|
|
|
|
| 224 |
badges = ('<div style="display:flex;flex-wrap:wrap;justify-content:flex-end;gap:10px;'
|
| 225 |
'margin-left:auto;flex:0 0 auto;" '
|
| 226 |
'aria-label="Successful runs">'
|
| 227 |
+
+ chip("Last 30 days", recent, recent_note)
|
| 228 |
+ chip("Today", today, today_note) + '</div>')
|
| 229 |
if title is None:
|
| 230 |
return badges
|