CaiYuanhao commited on
Commit
6121ddd
·
verified ·
1 Parent(s): 55cc09b

Show successful usage over the last 30 days including today

Browse files
Files changed (2) hide show
  1. SUCCESS_COUNTS.md +3 -3
  2. 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 previous calendar month's total and today's
9
  successful runs. The **Daily success history** panel contains the daily table
10
- for the previous and current months. Dates use
11
  `America/Los_Angeles`. History before instrumentation starts is unavailable;
12
- an incomplete first month is explicitly marked as partial.
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 summarize(data, channel, *, now=None):
 
171
  local = (now or datetime.now(timezone.utc)).astimezone(ZoneInfo(TIMEZONE))
172
- month_start = local.date().replace(day=1)
173
- previous_end = month_start - timedelta(days=1)
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 f"**Last month ({label}):** No historical data. Tracking has not started.", []
179
  started = datetime.fromisoformat(start).astimezone(ZoneInfo(TIMEZONE))
180
- if started.date() > previous_end:
181
- total_text = "No historical data"
182
- else:
183
- total = sum(values.get(channel, 0) for day, values in data["days"].items()
184
- if previous_start.isoformat() <= day <= previous_end.isoformat())
185
- total_text = f"{total:,} successful runs"
186
- beginning = datetime.combine(previous_start, datetime.min.time(), tzinfo=ZoneInfo(TIMEZONE))
187
- if started > beginning:
188
- total_text += " (partial month)"
189
  rows = []
190
  day = local.date()
191
- earliest = max(previous_start, started.date())
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 month ({label}):** {total_text}.\n\n"
196
- f"Daily counts use {TIMEZONE}. 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 = (now or datetime.now(timezone.utc)).astimezone(ZoneInfo(TIMEZONE))
204
- previous_end = local.date().replace(day=1) - timedelta(days=1)
205
- previous_start = previous_end.replace(day=1)
206
- previous, today = "—", "—"
207
- previous_note = "No historical data"
208
  today_note = "Success counts are temporarily unavailable"
209
- started_at = data["started_at"].get(channel) if data else None
210
- if started_at:
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
- if started.date() <= previous_end:
215
- total = sum(values.get(channel, 0) for day, values in data["days"].items()
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 month", previous, previous_note)
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