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:
parent
ffe64c5648
commit
c2b0a0d8a3
15 changed files with 468 additions and 31 deletions
|
|
@ -52,7 +52,7 @@ export function errorText(e: unknown): string {
|
|||
}
|
||||
|
||||
/** Dev-only fixture mode (VITE_FIXTURES=1): every command answered from src/dev/fixtures.ts. */
|
||||
export const FIXTURES: boolean = import.meta.env.DEV && !!import.meta.env.VITE_FIXTURES;
|
||||
export const FIXTURES: boolean = !!(import.meta.env.DEV && import.meta.env.VITE_FIXTURES);
|
||||
|
||||
async function invoke<T>(cmd: string, args?: Record<string, unknown>): Promise<T> {
|
||||
if (import.meta.env.DEV && import.meta.env.VITE_FIXTURES) return (await import('./dev/fixtures')).mockInvoke<T>(cmd, args ?? {});
|
||||
|
|
|
|||
|
|
@ -1045,6 +1045,9 @@ export const en = {
|
|||
'gr.chartAria': 'Daily store traffic on {store} with listing changes',
|
||||
'gr.changes': '{count} listing changes',
|
||||
'gr.changes_one': '1 listing change',
|
||||
'gr.indexLabel': 'Index: 100 = each line\'s own average over these days. Hover for the real numbers.',
|
||||
'gr.noDataTitle': 'No {store} days in the snapshots yet',
|
||||
'gr.noDataText': 'The snapshots read no daily numbers for this store yet. Take a new snapshot once the store has data.',
|
||||
'gr.oneDay': 'One day of data so far: the chart starts with the second day.',
|
||||
'gr.change': 'Listing change (git)',
|
||||
'gr.before': 'Before',
|
||||
|
|
|
|||
|
|
@ -1047,6 +1047,9 @@ export const tr: Record<keyof typeof en, string> = {
|
|||
'gr.chartAria': '{store} üzerinde günlük mağaza trafiği ve mağaza metni değişiklikleri',
|
||||
'gr.changes': '{count} mağaza metni değişikliği',
|
||||
'gr.changes_one': '1 mağaza metni değişikliği',
|
||||
'gr.indexLabel': 'Endeks: 100 = her çizginin bu günlerdeki kendi ortalaması. Gerçek sayılar için üzerine gelin.',
|
||||
'gr.noDataTitle': 'Anlık görüntülerde henüz {store} günü yok',
|
||||
'gr.noDataText': 'Anlık görüntüler bu mağaza için henüz günlük sayı okumadı. Mağazada veri olunca yeni bir anlık görüntü alın.',
|
||||
'gr.oneDay': 'Şimdilik bir günlük veri var: grafik ikinci günle başlar.',
|
||||
'gr.change': 'Mağaza değişikliği (git)',
|
||||
'gr.before': 'Önce',
|
||||
|
|
|
|||
|
|
@ -76,6 +76,17 @@ export function chartSeries(a: AnalyticsCompare, store: 'apple' | 'play'): Chart
|
|||
return { dates: pts.map(p => p.date), reach: pts.map(p => p.reach), installs: pts.map(p => p.installs), conversion: pts.map(p => (p.reach ? p.installs / p.reach : null)), events };
|
||||
}
|
||||
|
||||
/**
|
||||
* A daily series as an index: 100 = the average of its own non-empty days, so reach, installs and conversion share one
|
||||
* axis although they differ by orders of magnitude (installs on a count axis next to impressions lie flat). Empty days
|
||||
* stay empty; a series whose average is 0 has no index (all null).
|
||||
*/
|
||||
export function indexSeries(values: (number | null)[]): (number | null)[] {
|
||||
const xs = values.filter((v): v is number => v !== null && Number.isFinite(v));
|
||||
const mean = xs.length ? xs.reduce((n, v) => n + v, 0) / xs.length : 0;
|
||||
return values.map(v => (v === null || !Number.isFinite(v) || !mean ? null : (v / mean) * 100));
|
||||
}
|
||||
|
||||
/** Conversion before vs after one change (null when a side has no data). */
|
||||
export const effectDelta = (before?: number | null, after?: number | null): number | null => (before && after !== undefined && after !== null ? ((after - before) / before) * 100 : null);
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ function Analytics({ projectId, hasApple, hasPlay, name, playReports }: { projec
|
|||
actions={<>{stores.length > 1 && <Seg value={st} onChange={setStore} label={t('col.store')} options={[['apple', 'App Store'], ['play', 'Google Play']]} />}{actions}</>}>
|
||||
{none ? (
|
||||
<Empty illo="pulse" title={t('gr.noneTitle')}>{t('gr.noneText')}{hasPlay && !playReports ? ` ${t('gr.noBucket')}` : ''}</Empty>
|
||||
) : r.error ? <div className="card-body"><ErrorNotice error={r.error} /></div> : !a || !s ? <div className="card-body"><Skeleton lines={5} block /></div> : (
|
||||
) : r.error ? <div className="card-body"><ErrorNotice error={r.error} /></div> : !a || !s ? <div className="card-body"><Skeleton lines={5} block /></div> : !s.dates.length ? (
|
||||
<Empty illo="pulse" title={t('gr.noDataTitle', { store: st === 'apple' ? 'App Store' : 'Google Play' })}>{a.errors?.[st] ?? t('gr.noDataText')}{st === 'play' && !playReports ? ` ${t('gr.noBucket')}` : ''}</Empty>
|
||||
) : (
|
||||
<div className="card-body stack" style={{ gap: 16 }}>
|
||||
<div className="kpis" style={{ gridTemplateColumns: 'repeat(3, minmax(0, 1fr))' }}>
|
||||
<Kpi icon="eye" label={st === 'apple' ? t('gr.impressions') : t('gr.visitors')} value={num(reach)} sub={t('gr.days', { count: s.dates.length })} />
|
||||
|
|
@ -56,10 +58,11 @@ function Analytics({ projectId, hasApple, hasPlay, name, playReports }: { projec
|
|||
</div>
|
||||
{s.dates.length > 1 ? (
|
||||
<LineChart dates={s.dates} label={t('gr.chartAria', { store: st === 'apple' ? 'App Store' : 'Google Play' })} eventsLabel={t('gr.changes', { count: s.events.length })} events={s.events}
|
||||
indexLabel={t('gr.indexLabel')}
|
||||
lines={[
|
||||
{ label: st === 'apple' ? t('gr.impressions') : t('gr.visitors'), values: s.reach, cls: 'l1', axis: 'left' },
|
||||
{ label: st === 'apple' ? t('gr.downloads') : t('gr.acquisitions'), values: s.installs, cls: 'l2', axis: 'left' },
|
||||
{ label: t('gr.conversion'), values: s.conversion, cls: 'l3', axis: 'right' },
|
||||
{ label: st === 'apple' ? t('gr.impressions') : t('gr.visitors'), values: s.reach, cls: 'l1', unit: 'count' },
|
||||
{ label: st === 'apple' ? t('gr.downloads') : t('gr.acquisitions'), values: s.installs, cls: 'l2', unit: 'count' },
|
||||
{ label: t('gr.conversion'), values: s.conversion, cls: 'l3', unit: 'rate' },
|
||||
]} />
|
||||
) : <Notice tone="info">{t('gr.oneDay')}</Notice>}
|
||||
{effects.length > 0 && (
|
||||
|
|
|
|||
|
|
@ -855,6 +855,7 @@ textarea.input { height: auto; padding: 8px 10px; line-height: 1.45; resize: ver
|
|||
.lchart svg { width: 100%; height: auto; display: block; overflow: visible; outline: none; border-radius: 8px; }
|
||||
.lchart svg:focus-visible { box-shadow: 0 0 0 2px var(--focus); }
|
||||
.lchart .grid-l line { stroke: var(--line); stroke-width: 1; }
|
||||
.lchart line.base { stroke: var(--line-2); stroke-width: 1; stroke-dasharray: 2 3; }
|
||||
.lchart text { font-size: 10.5px; fill: var(--muted); font-variant-numeric: tabular-nums; }
|
||||
.lchart .stop-a { stop-color: var(--accent-solid); stop-opacity: .18; }
|
||||
.lchart .stop-b { stop-color: var(--accent-solid); stop-opacity: 0; }
|
||||
|
|
@ -868,6 +869,7 @@ textarea.input { height: auto; padding: 8px 10px; line-height: 1.45; resize: ver
|
|||
.lchart .hov line { stroke: var(--line-2); stroke-width: 1; }
|
||||
.lchart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: var(--t-meta); color: var(--muted); align-items: center; }
|
||||
.lchart-legend .lg { display: inline-flex; align-items: center; gap: 6px; }
|
||||
.lchart-legend .lg.idx { flex-basis: 100%; }
|
||||
.lchart-legend b { color: var(--ink); font-weight: 650; }
|
||||
.lchart-legend .sw { width: 14px; height: 3px; border-radius: 2px; background: var(--accent-solid); }
|
||||
.lchart-legend .sw.l2 { background: var(--ok-solid); }
|
||||
|
|
|
|||
|
|
@ -1,22 +1,42 @@
|
|||
// A small two-axis line chart for daily store analytics: counts on the left axis (reach, installs), a rate on the
|
||||
// right (conversion), store changes from git as dashed markers. Hover (or arrow keys when focused) shows one day.
|
||||
// A small line chart for daily store analytics. Reach (impressions, visitors), installs and conversion differ by one
|
||||
// to three orders of magnitude, so on one count axis installs lay flat at the bottom. The chart therefore plots each
|
||||
// line as an index (100 = that line's own average over the days shown, views.ts indexSeries) on one shared axis: every
|
||||
// line uses the full height and a listing change shows as lines moving apart. Hover (or arrow keys when focused) shows
|
||||
// the real values of one day; store changes from git are dashed markers.
|
||||
import { type KeyboardEvent, useId, useState } from 'react';
|
||||
import { date, num, pct } from '../lib/format';
|
||||
import { indexSeries } from '../lib/views';
|
||||
|
||||
export interface ChartLine { label: string; values: (number | null)[]; cls: 'l1' | 'l2' | 'l3'; axis: 'left' | 'right' }
|
||||
export interface ChartLine {
|
||||
label: string;
|
||||
/** Real daily values (counts, or a 0-1 rate with unit "rate"); plotted as an index, shown as they are on hover. */
|
||||
values: (number | null)[];
|
||||
cls: 'l1' | 'l2' | 'l3';
|
||||
unit: 'count' | 'rate';
|
||||
}
|
||||
|
||||
export function LineChart({ dates, lines, events, label, eventsLabel }: { dates: string[]; lines: ChartLine[]; events: { date: string; subject: string }[]; label: string; eventsLabel: string }) {
|
||||
const W = 800, H = 230, L = 46, R = 46, T = 12, B = 26;
|
||||
const W = 800, H = 230, L = 46, R = 18, T = 14, B = 26;
|
||||
|
||||
/** Index axis: a round top above the highest point (at least 150 so 100 sits in the lower two thirds) and 4 ticks. */
|
||||
export function indexAxis(lines: (number | null)[][]): { max: number; ticks: number[] } {
|
||||
const hi = Math.max(150, ...lines.flat().filter((v): v is number => v !== null));
|
||||
const step = hi <= 200 ? 50 : hi <= 400 ? 100 : Math.ceil(hi / 4 / 100) * 100;
|
||||
const max = Math.ceil(hi / step) * step;
|
||||
return { max, ticks: Array.from({ length: max / step + 1 }, (_, i) => i * step) };
|
||||
}
|
||||
|
||||
export function LineChart({ dates, lines, events, label, eventsLabel, indexLabel }: {
|
||||
dates: string[]; lines: ChartLine[]; events: { date: string; subject: string }[]; label: string; eventsLabel: string; indexLabel: string;
|
||||
}) {
|
||||
const gid = useId().replace(/:/g, '');
|
||||
const [hover, setHover] = useState<number | null>(null);
|
||||
const n = dates.length;
|
||||
if (n < 2) return null;
|
||||
const plotted = lines.map(l => indexSeries(l.values));
|
||||
const { max, ticks } = indexAxis(plotted);
|
||||
const x = (i: number) => L + (i / (n - 1)) * (W - L - R);
|
||||
const max = (axis: 'left' | 'right') => Math.max(...lines.filter(l => l.axis === axis).flatMap(l => l.values.filter((v): v is number => v !== null)), axis === 'right' ? 0.001 : 1) * 1.1;
|
||||
const mL = max('left'), mR = max('right');
|
||||
const y = (v: number, axis: 'left' | 'right') => H - B - (v / (axis === 'left' ? mL : mR)) * (H - T - B);
|
||||
const path = (l: ChartLine) => l.values.map((v, i) => (v === null ? '' : `${i && l.values[i - 1] !== null ? 'L' : 'M'}${x(i).toFixed(1)} ${y(v, l.axis).toFixed(1)}`)).join(' ');
|
||||
const ticks = [0, 0.5, 1];
|
||||
const y = (v: number) => H - B - (v / max) * (H - T - B);
|
||||
const path = (vs: (number | null)[]) => vs.map((v, i) => (v === null ? '' : `${i && vs[i - 1] !== null ? 'L' : 'M'}${x(i).toFixed(1)} ${y(v).toFixed(1)}`)).join(' ');
|
||||
const onMove = (ev: React.MouseEvent<SVGSVGElement>) => {
|
||||
const r = ev.currentTarget.getBoundingClientRect();
|
||||
const px = ((ev.clientX - r.left) / r.width) * W;
|
||||
|
|
@ -26,30 +46,31 @@ export function LineChart({ dates, lines, events, label, eventsLabel }: { dates:
|
|||
if (ev.key === 'ArrowRight') { ev.preventDefault(); setHover(h => Math.min(n - 1, (h ?? -1) + 1)); }
|
||||
if (ev.key === 'ArrowLeft') { ev.preventDefault(); setHover(h => Math.max(0, (h ?? n) - 1)); }
|
||||
};
|
||||
const fmt = (l: ChartLine, v: number | null) => (v === null ? '–' : l.axis === 'right' ? pct(v, 1) : num(v));
|
||||
const fmt = (l: ChartLine, v: number | null) => (v === null ? '–' : l.unit === 'rate' ? pct(v, 1) : num(v));
|
||||
return (
|
||||
<div className="lchart">
|
||||
<svg viewBox={`0 0 ${W} ${H}`} role="img" aria-label={label} tabIndex={0} onMouseMove={onMove} onMouseLeave={() => setHover(null)} onKeyDown={onKey} onBlur={() => setHover(null)}>
|
||||
<svg viewBox={`0 0 ${W} ${H}`} role="img" aria-label={`${label} (${indexLabel})`} tabIndex={0} onMouseMove={onMove} onMouseLeave={() => setHover(null)} onKeyDown={onKey} onBlur={() => setHover(null)}>
|
||||
<defs><linearGradient id={`lg${gid}`} x1="0" y1="0" x2="0" y2="1"><stop offset="0" className="stop-a" /><stop offset="1" className="stop-b" /></linearGradient></defs>
|
||||
{ticks.map(f => (
|
||||
<g key={f} className="grid-l">
|
||||
<line x1={L} x2={W - R} y1={H - B - f * (H - T - B)} y2={H - B - f * (H - T - B)} />
|
||||
<text x={L - 6} y={H - B - f * (H - T - B) + 4} textAnchor="end">{num(f * mL / 1.1)}</text>
|
||||
<text x={W - R + 6} y={H - B - f * (H - T - B) + 4}>{pct(f * mR / 1.1, 1)}</text>
|
||||
{ticks.map(v => (
|
||||
<g key={v} className="grid-l">
|
||||
<line x1={L} x2={W - R} y1={y(v)} y2={y(v)} />
|
||||
<text x={L - 6} y={y(v) + 4} textAnchor="end">{v}</text>
|
||||
</g>
|
||||
))}
|
||||
<line className="base" x1={L} x2={W - R} y1={y(100)} y2={y(100)} />
|
||||
{events.map((e, i) => {
|
||||
const k = dates.indexOf(e.date);
|
||||
if (k < 0) return null;
|
||||
return <g key={i} className="ev"><line x1={x(k)} x2={x(k)} y1={T} y2={H - B} /><circle cx={x(k)} cy={T + 4} r={4}><title>{`${date(e.date)} · ${e.subject}`}</title></circle></g>;
|
||||
})}
|
||||
{lines[0] && <path className="area" d={`${path(lines[0])} L${x(n - 1)} ${H - B} L${x(0)} ${H - B} Z`} fill={`url(#lg${gid})`} />}
|
||||
{lines.map(l => <path key={l.label} className={`ln ${l.cls}`} d={path(l)} />)}
|
||||
{hover !== null && <g className="hov"><line x1={x(hover)} x2={x(hover)} y1={T} y2={H - B} />{lines.map(l => (l.values[hover] === null ? null : <circle key={l.label} className={l.cls} cx={x(hover)} cy={y(l.values[hover]!, l.axis)} r={3.5} />))}</g>}
|
||||
{plotted[0] && <path className="area" d={`${path(plotted[0])} L${x(n - 1)} ${H - B} L${x(0)} ${H - B} Z`} fill={`url(#lg${gid})`} />}
|
||||
{lines.map((l, k) => <path key={l.label} className={`ln ${l.cls}`} d={path(plotted[k]!)} />)}
|
||||
{hover !== null && <g className="hov"><line x1={x(hover)} x2={x(hover)} y1={T} y2={H - B} />{lines.map((l, k) => (plotted[k]![hover] === null ? null : <circle key={l.label} className={l.cls} cx={x(hover)} cy={y(plotted[k]![hover]!)} r={3.5} />))}</g>}
|
||||
<text className="ax" x={L} y={H - 6}>{date(dates[0])}</text>
|
||||
<text className="ax" x={W - R} y={H - 6} textAnchor="end">{date(dates[n - 1])}</text>
|
||||
</svg>
|
||||
<div className="lchart-legend" aria-live="polite">
|
||||
<span className="lg idx">{indexLabel}</span>
|
||||
{hover !== null && <b className="num">{date(dates[hover])}</b>}
|
||||
{lines.map(l => <span key={l.label} className="lg"><span className={`sw ${l.cls}`} />{l.label}{hover !== null && <b className="num">{fmt(l, l.values[hover] ?? null)}</b>}</span>)}
|
||||
{events.length > 0 && <span className="lg"><span className="sw ev" />{eventsLabel}</span>}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
import { describe, expect, test } from 'bun:test';
|
||||
import type { PricesCurrent } from '../src/api';
|
||||
import { csv, mdTable, pricesCsv, reviewsCsv } from '../src/lib/exports';
|
||||
import { chartSeries, diffSummary, fixHint, priceMatrix, priceStats, regionRows } from '../src/lib/views';
|
||||
import { chartSeries, diffSummary, fixHint, indexSeries, priceMatrix, priceStats, regionRows } from '../src/lib/views';
|
||||
import { indexAxis } from '../src/ui/LineChart';
|
||||
import { parsePriceCsv } from '../../../cli/lib/prices';
|
||||
|
||||
const P: PricesCurrent = {
|
||||
|
|
@ -56,6 +57,17 @@ describe('views', () => {
|
|||
expect(s.conversion).toEqual([0.05, null]);
|
||||
expect(s.events).toEqual([{ date: '2026-01-02', subject: 'x', commit: 'abc' }]);
|
||||
});
|
||||
test('chart index: every line on one axis, 100 = its own average', () => {
|
||||
// impressions ~4000 and downloads ~150 a day: on a count axis downloads lie flat; indexed both use the height
|
||||
const imp = [3800, 4200, 4000, 4000], dl = [120, 150, 180, 150];
|
||||
expect(indexSeries(imp)).toEqual([95, 105, 100, 100]);
|
||||
expect(indexSeries(dl)).toEqual([80, 100, 120, 100]);
|
||||
expect(indexSeries([null, 0.04, 0.06])).toEqual([null, 80, 120]);
|
||||
expect(indexSeries([0, 0, null])).toEqual([null, null, null]);
|
||||
expect(indexAxis([[80, 120], [95, 105]])).toEqual({ max: 150, ticks: [0, 50, 100, 150] });
|
||||
expect(indexAxis([[40, 230]])).toEqual({ max: 300, ticks: [0, 100, 200, 300] });
|
||||
expect(indexAxis([[900]]).max).toBeGreaterThanOrEqual(900);
|
||||
});
|
||||
test('errors that say how to fix them', () => {
|
||||
expect(fixHint('PLAY_SERVICE_ACCOUNT is not set (env ...)')).toBe('hint.keys');
|
||||
expect(fixHint('no snapshots in /x/.storebound/analytics (storebound analytics snapshot)')).toBe('hint.snapshot');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue