Real-account read check of the desktop tabs: analytics snapshot stops when every store failed, compare names why a store has no days (Growth shows it), listing screenshot count skips contact sheets; Growth chart as an index on one axis; recorded price answers round-trip the price sheet

This commit is contained in:
CRTkafa 2026-10-11 00:06:26 +00:00
parent ffe64c5648
commit c2b0a0d8a3
15 changed files with 468 additions and 31 deletions

View file

@ -14,7 +14,7 @@ import { ascClient, type Asc, type J } from './apple/asc';
import type { Ctx } from './lib/ctx';
import {
type AppleDay, APPLE_REPORTS, appleDaily, appleTotals, bucketName, checksumOk, compareAroundEvents, decodeText, effectMarkdown, effectTable, inWindow,
latestPerDate, mergeSeries, monthsBetween, parseGitLog, parseReport, pickReport, type PlayDay, playDaily, playObjects, playTotals, type Snapshot,
latestPerDate, mergeSeries, monthsBetween, snapshotProblem, storeErrors, parseGitLog, parseReport, pickReport, type PlayDay, playDaily, playObjects, playTotals, type Snapshot,
} from './lib/analytics';
import { STORAGE_READ_SCOPE } from './lib/google-auth';
import { done, log, printJson, warn } from './lib/log';
@ -127,6 +127,8 @@ export async function run(ctx: Ctx): Promise<void> {
if (snap.play && !('error' in snap.play)) { const t = snap.play.totals; rows.push(['play', `${t.visitors} visitors`, `${t.acquisitions} acquisitions`, `${t.installs} installs`, pct(t.conversion ?? null)]); }
if (rows.length) console.log(textTable(['store', 'reach', 'interest', 'installs', 'conversion'], rows));
const file = join(dir, `${snap.date}.json`);
const problem = snapshotProblem(snap);
if (problem) throw new Error(`no store data, nothing written (${problem})`);
if (dry) { done(TAG, `dry run: would write ${file} (${start} to ${end})`); return; }
mkdirSync(dir, { recursive: true });
writeFileSync(file, JSON.stringify(snap, null, 2) + '\n');
@ -145,7 +147,7 @@ export async function run(ctx: Ctx): Promise<void> {
const events = parseGitLog(g.stdout.toString()).reverse();
log(TAG, `${snaps.length} snapshot(s), ${series.apple.length} App Store day(s), ${series.play.length} Play day(s), ${events.length} store change(s) since ${first}`);
const fx = compareAroundEvents(series, events, a.num('days', 7));
if (a.has('json')) { printJson({ snapshots: snaps.length, since: first, series, effects: fx }); return; }
if (a.has('json')) { printJson({ snapshots: snaps.length, since: first, series, effects: fx, errors: storeErrors(snaps) }); return; }
console.log(a.has('md') ? effectMarkdown(fx) : effectTable(fx));
log(TAG, 'reading: a change needs several days on both sides and enough traffic; seasonality, featuring and ads move these numbers too');
return;

View file

@ -125,6 +125,30 @@ export interface Snapshot {
play?: { daily: PlayDay[]; totals: Totals } | { error: string };
}
/**
* Why a fresh snapshot is not worth writing: every store it read failed (no ONGOING report request yet, no reports
* bucket, no access). Null when at least one store has days. A snapshot of errors only would make `snapshot` look done
* while `compare` and the desktop chart stay empty.
*/
export function snapshotProblem(s: Snapshot): string | null {
const parts = (['apple', 'play'] as const).filter(k => s[k]);
if (!parts.length) return 'no store to read (no apple or play section in the config, or --store names none)';
if (parts.some(k => !('error' in s[k]!))) return null;
return parts.map(k => `${k}: ${(s[k] as { error: string }).error}`).join('; ');
}
/** The newest error per store when that store has no days in any snapshot (shown instead of an empty chart). */
export function storeErrors(snaps: Snapshot[]): { apple?: string; play?: string } {
const out: { apple?: string; play?: string } = {};
const series = mergeSeries(snaps);
for (const k of ['apple', 'play'] as const) {
if (series[k].length) continue;
const last = [...snaps].sort((x, y) => x.date.localeCompare(y.date)).reverse().find(s => s[k] && 'error' in s[k]!);
if (last) out[k] = (last[k] as { error: string }).error;
}
return out;
}
export const inWindow = <T extends { date: string }>(rows: T[], start: string, end: string): T[] => rows.filter(r => r.date >= start && r.date <= end);
// ---- compare with listing changes ----

View file

@ -319,4 +319,6 @@ export interface AnalyticsCompare {
play: { date: string; visitors: number; acquisitions: number; installs: number }[];
};
effects: { event: { date: string; commit: string; subject: string; files: string[] }; store: 'apple' | 'play'; before: AnalyticsTotals; after: AnalyticsTotals; daysBefore: number; daysAfter: number }[];
/** Per store with no days in any snapshot: why the newest snapshot has none (no report request yet, no bucket). */
errors?: { apple?: string; play?: string };
}

View file

@ -90,12 +90,14 @@ export function appleSections(md: string): Map<string, Record<string, string | u
return out;
}
function countImages(dir: string): number {
/** Store images of one language: the images in its size folders (<lang>/<size>/...). Files right in the language
* folder (a contact sheet, a preview collage) are not store images and are not counted, like the gallery. */
export function countImages(dir: string, depth = 0): number {
let n = 0;
try {
for (const e of readdirSync(dir, { withFileTypes: true })) {
if (e.isDirectory()) n += countImages(join(dir, e.name));
else if (/\.(png|jpe?g)$/i.test(e.name)) n++;
if (e.isDirectory()) n += countImages(join(dir, e.name), depth + 1);
else if (depth > 0 && /\.(png|jpe?g)$/i.test(e.name)) n++;
}
} catch { /* unreadable: 0 */ }
return n;