@homie-rocks/studio 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/worker/stats.mjs CHANGED
@@ -284,19 +284,22 @@ export async function readStats(env, cat, { range, only = null, studios = new Se
284
284
  },
285
285
  crossings: { fromHub: byKind('hub'), fromStudios: byKind('studio'), fromSearch: byKind('search'), fromWeb: byKind('web'), fromLinks: byKind('link') },
286
286
  // The studio's own pages: its home, and the /music/ and /videos/ lists (a catalogue's road).
287
- pages: { home: sum((r) => r.metric === 'visit' && r.subject === 'home'), music: sum((r) => r.metric === 'visit' && r.subject === 'music'), videos: sum((r) => r.metric === 'visit' && r.subject === 'videos') },
287
+ pages: Object.fromEntries(['home', 'games', 'rooms', 'posts', 'music', 'videos'].map((p) => [p, sum((r) => r.metric === 'visit' && r.subject === p)])),
288
288
  games: perGame, songs: media(songs, 'song', 'music'), videos: media(videos, 'video', 'videos'), referrers, days,
289
289
  note: 'Counts, never people: a visit is a page a browser opened, a play is a Play press, a round is a finished round. Prefetches, crawlers and house QA are not counted. Times are UTC days.',
290
290
  };
291
291
  }
292
292
 
293
- /** What a studio that shares may tell the directory: Play presses and rounds with people in the last 7 days. */
294
- export async function playedThisWeek(env) {
293
+ /**
294
+ * What a studio that shares may tell the directory: Play presses and rounds with people in the last 7 days. With
295
+ * `game`, one game's (a landing shows them).
296
+ */
297
+ export async function playedThisWeek(env, game = null) {
295
298
  if (!env?.DB) return null;
296
299
  const to = today();
297
300
  try {
298
- const row = await env.DB.prepare("SELECT SUM(CASE WHEN metric = 'play' THEN n ELSE 0 END) AS plays, SUM(CASE WHEN metric = 'round' AND source = 'people' THEN n ELSE 0 END) AS rounds FROM stats_daily WHERE day >= ?1 AND day <= ?2 AND metric IN ('play', 'round')")
299
- .bind(dayOffset(to, -6), to).first();
301
+ const row = await env.DB.prepare(`SELECT SUM(CASE WHEN metric = 'play' THEN n ELSE 0 END) AS plays, SUM(CASE WHEN metric = 'round' AND source = 'people' THEN n ELSE 0 END) AS rounds FROM stats_daily WHERE day >= ?1 AND day <= ?2 AND metric IN ('play', 'round')${game ? ' AND subject = ?3' : ''}`)
302
+ .bind(dayOffset(to, -6), to, ...(game ? [String(game)] : [])).first();
300
303
  return { days: 7, plays: Number(row?.plays) || 0, rounds: Number(row?.rounds) || 0, to };
301
304
  } catch { return null; }
302
305
  }
@@ -0,0 +1,2 @@
1
+ /** The @homie-rocks/studio version this Worker code is (package.json's; a test keeps them equal). Cache-busts /_homie/site.js. */
2
+ export const STUDIO_VERSION_TAG = '0.8.0';