Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

feat(insights): open on 24h, always compare same prompts, drop the trend's AC markers and Send biggest gap (#1100)

Cihan0d81dd8c6e3a
diff --git a/web/messages/en.json b/web/messages/en.json
index fbe96cb4a..99100a094 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -1714,8 +1714,6 @@
"checkedAt": "Checked: {date}"
},
"compare": {
- "label": "Compare",
- "samePrompts": "Same prompts",
"hint": "Changes compare only prompts tracked in both periods",
"newExcluded": "{count, plural, one {# new prompt excluded} other {# new prompts excluded}}",
"newIncluded": "{count, plural, one {includes # new prompt} other {includes # new prompts}}"
@@ -1849,8 +1847,6 @@
"pinLimit": "Up to 5 competitors",
"pinFailed": "Couldn't save the pinned competitors.",
"promptsAdded": "{count, plural, one {# prompt} other {# prompts}} added · {date}",
- "actionsSent": "{actions} sent · {date}",
- "moreActions": "{actions} +{count}",
"goal": "Goal {value}",
"goalLegend": "Action Center goal"
},
@@ -1864,15 +1860,7 @@
"lowSample": "Low sample",
"openTopic": "Open {topic}",
"showAll": "Show all {count}",
- "showLess": "Show less",
- "sendGap": "Send biggest gap to Actions",
- "sendGapTitle": "Open a Compete action for {topic}, where {competitor} leads you by {gap} pts",
- "noGap": "No topic where a competitor leads you",
- "sent": "AC-{no} sent to the Action Center",
- "alreadySent": "Already in the Action Center as AC-{no}",
- "sendFailed": "Couldn't send to the Action Center.",
- "openAction": "Open",
- "gapChanged": "The gap changed since the page loaded. Refresh to see the latest."
+ "showLess": "Show less"
},
"breakdown": {
"noData": "No data",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/insights/_formula-dialog.tsx b/web/src/app/[locale]/(dashboard)/dashboard/insights/_formula-dialog.tsx
index 2ecc5f483..a707f5d8a 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/insights/_formula-dialog.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/insights/_formula-dialog.tsx
@@ -153,13 +153,12 @@ export function FormulaDialog() {
<Formula>Coverage = prompts you appeared in ÷ prompts answered × 100</Formula>
</Section>
- <Section title="Changes and “Same prompts”">
+ <Section title="Changes">
<p>
Each card&apos;s change compares the selected period with the period of the same
- length just before it. With &quot;Compare: Same prompts&quot; on, it compares only
- the prompts answered in both periods, so adding prompts doesn&apos;t inflate it; the
- numbers themselves still cover every prompt. With &quot;All time&quot; there is no
- earlier period, so no change is shown.
+ length just before it, over the prompts answered in both periods only, so adding
+ prompts doesn&apos;t inflate it; the numbers themselves still cover every prompt.
+ With &quot;All time&quot; there is no earlier period, so no change is shown.
</p>
</Section>
</div>
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/insights/_topic-heatmap.tsx b/web/src/app/[locale]/(dashboard)/dashboard/insights/_topic-heatmap.tsx
index 972c18e58..e385206af 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/insights/_topic-heatmap.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/insights/_topic-heatmap.tsx
@@ -2,15 +2,11 @@
import { useState } from 'react';
import { useLocale, useTranslations } from 'next-intl';
-import { ArrowRight } from 'lucide-react';
-import { toast } from 'sonner';
-import { Link, useRouter } from '@/i18n/navigation';
-import { Button } from '@/components/ui/button';
-import { sendTopicGapToActionCenter, type TopicGapWindow } from '@/lib/actions/topic';
+import { Link } from '@/i18n/navigation';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { cn } from '@/lib/utils';
import { numberFormat } from '@/lib/number-format';
-import { biggestGap, heatShade, topicHeatmap, type TopicCompetitors } from '@/lib/insights-topics';
+import { heatShade, topicHeatmap, type TopicCompetitors } from '@/lib/insights-topics';
import { TONE_TEXT } from './kpi-format';
/** Rows shown before "Show all". */
@@ -38,22 +34,17 @@ const SHADES = [
export function TopicHeatmap({
topics,
columns,
- window,
className,
}: {
topics: TopicCompetitors[];
/** You first, then the competitors on the trend: `'you'` or a competitor id. */
columns: { key: string; name: string }[];
- /** The window and filters the map was loaded with, for "Send biggest gap". */
- window: TopicGapWindow;
className?: string;
}) {
const t = useTranslations('insights.topicMap');
const f = numberFormat(useLocale());
/** A gap with one decimal, so the column lines up: "−29.0", "−20.3". */
const gapText = (gap: number) => `−${f.number(Math.abs(gap), 1)}`;
- const router = useRouter();
- const [sending, setSending] = useState(false);
// Expanded for this data only: another brand or range starts folded.
const [expandedFor, setExpandedFor] = useState<TopicCompetitors[] | null>(null);
const expanded = expandedFor === topics;
@@ -66,69 +57,10 @@ export function TopicHeatmap({
// The tones spread over the scores of every row, so folding doesn't shift them.
const named = rows.flatMap((r) => r.scores).filter((v) => v > 0);
const [low, high] = [Math.min(...named), Math.max(...named)];
- const target = biggestGap(rows);
- const targetCompetitor = target && columns.find((c) => c.key === target.leader)?.name;
-
- const sendBiggestGap = async () => {
- if (!target) return;
- setSending(true);
- try {
- const result = await sendTopicGapToActionCenter(target.topicId, target.leader, window);
- if ('error' in result) {
- // The page's numbers can be older than the server's: a newer run may
- // have closed the gap since it loaded.
- if (result.code === 'stale') toast.error(t('gapChanged'));
- else toast.error(t('sendFailed'), { description: result.error });
- return;
- }
- toast.success(
- result.created
- ? t('sent', { no: result.actionNo })
- : t('alreadySent', { no: result.actionNo }),
- {
- action: {
- label: t('openAction'),
- onClick: () =>
- router.push(`/dashboard/action-center/actions?action=${result.actionId}`),
- },
- },
- );
- } catch {
- toast.error(t('sendFailed'));
- } finally {
- setSending(false);
- }
- };
-
return (
<Card className={className}>
<CardHeader className="pb-2">
- <div className="flex flex-wrap items-center justify-between gap-2">
- <CardTitle className="text-sm font-medium">{t('title')}</CardTitle>
- {/* The hint sits on a wrapper: a disabled button shows no tooltip. */}
- <span
- title={
- target
- ? t('sendGapTitle', {
- topic: target.name,
- competitor: targetCompetitor ?? '',
- gap: f.number(Math.abs(target.gap!), 1),
- })
- : t('noGap')
- }
- >
- <Button
- variant="outline"
- size="sm"
- className="h-7 gap-1.5 text-xs"
- disabled={!target || sending}
- onClick={sendBiggestGap}
- >
- <ArrowRight className="h-3.5 w-3.5" aria-hidden />
- {t('sendGap')}
- </Button>
- </span>
- </div>
+ <CardTitle className="text-sm font-medium">{t('title')}</CardTitle>
</CardHeader>
<CardContent className="overflow-x-auto">
{/* Fixed layout: every brand column gets the same width, as in the mockup. */}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/insights/_trend-card.tsx b/web/src/app/[locale]/(dashboard)/dashboard/insights/_trend-card.tsx
index 61b277415..440640840 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/insights/_trend-card.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/insights/_trend-card.tsx
@@ -36,18 +36,11 @@ const VisibilityRateTrendChart = dynamic(
{ ssr: false, loading: () => <Skeleton className="h-[320px] w-full" /> },
);
-/** Action numbers as the Action Center writes them: "AC-61", "AC-3, AC-4", "AC-3, AC-4, AC-5 +2". */
-const actionIds = (nos: number[]) =>
- nos
- .slice(0, 3)
- .map((n) => `AC-${n}`)
- .join(', ');
-
/**
* The visibility trend card (VIS-007), as in the v2 mockup: the score over
* the range, your line and the pinned competitors (chips to highlight them,
* "Pin" to choose up to five, saved on the brand), the Action Center goal,
- * and markers for the days prompts were added and actions sent.
+ * and markers for the days prompts were added.
*/
export function TrendCard({
brandId,
@@ -109,23 +102,12 @@ export function TrendCard({
};
const describe = (m: TrendMarker) =>
- m.kind === 'prompts'
- ? t('promptsAdded', { count: m.count, date: dayLabel(m.day, locale) })
- : t('actionsSent', {
- actions:
- m.actionNos.length > 3
- ? t('moreActions', {
- actions: actionIds(m.actionNos),
- count: f.number(m.actionNos.length - 3),
- })
- : actionIds(m.actionNos),
- date: dayLabel(m.day, locale),
- });
+ t('promptsAdded', { count: m.count, date: dayLabel(m.day, locale) });
// Every marker is listed below the chart; only those with a point are drawn on it.
const placed = markers
? trendMarkers(markers, data.points).map((m) => ({
...m,
- glyph: m.kind === 'prompts' ? '+' : 'A',
+ glyph: '+',
title: describe(m),
}))
: [];
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/insights/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/insights/page.tsx
index 87332e6e5..e25c0e57a 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/insights/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/insights/page.tsx
@@ -95,26 +95,23 @@ interface InsightsFilters {
region: string;
model: string;
topic: string;
- /** "Compare: Same prompts" (VIS-002): changes compare only prompts answered in both periods. */
- samePrompts: boolean;
}
const DEFAULT_FILTERS: InsightsFilters = {
- // 30 days, as in the v2 mockup (VIS-007); 24h stays one click away.
- datePreset: '30d',
+ // The last 24 hours: what the latest run found. Longer ranges are one
+ // click away.
+ datePreset: '24h',
dateFrom: '',
dateTo: '',
region: '',
model: '',
topic: '',
- samePrompts: true,
};
/**
* The filters as kept in the URL (#917): ?range=, plus ?from=/&to= for a
- * custom range, ?region=, ?model=, ?topic=, and ?compare=all when "Same
- * prompts" is off. Defaults are left out, and an unknown range falls back to
- * the default.
+ * custom range, ?region=, ?model= and ?topic=. Defaults are left out, and an
+ * unknown range falls back to the default.
*/
function filtersFromUrl(): InsightsFilters {
const datePreset = readUrlChoice<DatePreset>(
@@ -129,7 +126,6 @@ function filtersFromUrl(): InsightsFilters {
region: readUrlParam('region'),
model: readUrlParam('model'),
topic: readUrlParam('topic'),
- samePrompts: readUrlParam('compare') !== 'all',
};
}
@@ -143,7 +139,8 @@ function writeFiltersToUrl(f: InsightsFilters) {
region: f.region,
model: f.model,
topic: f.topic,
- compare: f.samePrompts ? null : 'all',
+ // Dropped from links made while "Same prompts" could be turned off.
+ compare: null,
},
{ range: DEFAULT_FILTERS.datePreset },
);
@@ -326,7 +323,6 @@ function FilterBar({
availableTopics: Topic[];
}) {
const t = useTranslations('common');
- const tInsights = useTranslations('insights');
const set = (patch: Partial<InsightsFilters>) => onChange({ ...filters, ...patch });
return (
@@ -437,35 +433,6 @@ function FilterBar({
</SelectContent>
</Select>
</div>
- {/* Compare: Same prompts (VIS-002) */}
- <div>
- <label className="mb-1.5 block text-xs font-medium text-muted-foreground">
- {tInsights('compare.label')}
- </label>
- <button
- type="button"
- role="switch"
- aria-checked={filters.samePrompts}
- title={tInsights('compare.hint')}
- onClick={() => set({ samePrompts: !filters.samePrompts })}
- className="inline-flex h-8 items-center gap-2 rounded-md border bg-background px-2.5 text-xs transition-colors hover:bg-muted/50"
- >
- <span
- className={cn(
- 'relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors',
- filters.samePrompts ? 'bg-primary' : 'bg-muted-foreground/30',
- )}
- >
- <span
- className={cn(
- 'block h-3 w-3 rounded-full bg-background shadow transition-transform',
- filters.samePrompts ? 'translate-x-3.5' : 'translate-x-0.5',
- )}
- />
- </span>
- {tInsights('compare.samePrompts')}
- </button>
- </div>
</div>
);
}
@@ -789,7 +756,9 @@ export default function InsightsPage() {
// rollups (00066). Absent for 24h, whose anchored window above is
// timestamp-shaped and stays on the raw path.
days,
- samePrompts: f.samePrompts,
+ // Changes compare only the prompts answered in both periods
+ // (VIS-002), so adding prompts doesn't inflate them.
+ samePrompts: true,
};
const hasFilters = Boolean(f.datePreset !== 'all' || f.model || f.region || f.topic);
@@ -1376,12 +1345,6 @@ export default function InsightsPage() {
topicCompetitors.length > 0 && (
<TopicHeatmap
topics={topicCompetitors}
- window={{
- dayFrom: loadedFilters?.days?.dayFrom,
- dayTo: loadedFilters?.days?.dayTo,
- model: loadedFilters?.model,
- region: loadedFilters?.region,
- }}
columns={trendLines(rateTrend.entities, rateTrend.points, rateTrend.pinned).map(
(line) => ({ key: line.key, name: line.name }),
)}
diff --git a/web/src/lib/actions/topic.ts b/web/src/lib/actions/topic.ts
index a9bb6dd3c..579ea44d5 100644
--- a/web/src/lib/actions/topic.ts
+++ b/web/src/lib/actions/topic.ts
@@ -408,64 +408,6 @@ export async function deleteTopic(topicId: string): Promise<void> {
if (error) throw new Error(error.message);
}
-/** The window and filters a heat map's gap was shown for (VIS-010). */
-export interface TopicGapWindow {
- dayFrom?: string;
- dayTo?: string;
- /** The page's AI Model filter: model slugs, comma-separated. */
- model?: string;
- region?: string;
-}
-
-/**
- * "Send biggest gap to Actions" (VIS-010): a Compete action to close the
- * topic's gap with the competitor leading it. The server measures the gap
- * again over the same window; the same topic and competitor sent again
- * return the open action.
- */
-export async function sendTopicGapToActionCenter(
- topicId: string,
- competitorId: string,
- window: TopicGapWindow,
-): Promise<
- | { actionId: string; actionNo: number; created: boolean }
- // 'stale': the server measured no gap over that window any more (409).
- | { error: string; code?: 'stale' }
-> {
- const supabase = await createClient();
- const {
- data: { session },
- } = await supabase.auth.getSession();
- if (!session) return { error: 'Not authenticated' };
-
- const models = window.model
- ?.split(',')
- .map((m) => m.trim())
- .filter(Boolean);
- const res = await fetch(`${API_BASE_URL}/api/topics/${topicId}/gap-action`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${session.access_token}`,
- },
- body: JSON.stringify({
- competitorId,
- dayFrom: window.dayFrom,
- dayTo: window.dayTo,
- models: models?.length ? models : undefined,
- region: window.region || undefined,
- }),
- });
-
- // Returned, not thrown: a thrown error's message is masked in production.
- if (!res.ok) {
- const body = await res.json().catch(() => ({}));
- const error = body.details || body.error || `Server error: ${res.status}`;
- return res.status === 409 ? { error, code: 'stale' } : { error };
- }
- return res.json();
-}
-
/**
* "Send action" on an Insights Opportunities topic (VIS-011): a Growth
* action to capture the demand of the topic's suggested prompts. The server
diff --git a/web/src/lib/insights-topics.test.ts b/web/src/lib/insights-topics.test.ts
index 30e30313f..b1c06681d 100644
--- a/web/src/lib/insights-topics.test.ts
+++ b/web/src/lib/insights-topics.test.ts
@@ -1,7 +1,6 @@
import { describe, expect, it } from 'vitest';
import { computeAiVisibilityScore } from './visibility-score';
import {
- biggestGap,
heatShade,
parseTopicCompetitors,
topicHeatmap,
@@ -78,30 +77,6 @@ describe('topicHeatmap', () => {
});
});
-describe('biggestGap', () => {
- it('picks the topic you trail by the most, against its leader', () => {
- const rows = topicHeatmap(
- [
- topic('lead', 100, 80, { a: 50 }),
- topic('small-gap', 100, 40, { a: 50, b: 45 }),
- topic('big-gap', 100, 10, { a: 30, b: 70 }),
- topic('few', 10, 0, { a: 9 }),
- ],
- ['you', 'a', 'b'],
- );
-
- expect(biggestGap(rows)).toMatchObject({ topicId: 'big-gap', leader: 'b' });
- });
-
- it('sends nothing when you lead everywhere or the samples are too small', () => {
- const rows = topicHeatmap(
- [topic('lead', 100, 80, { a: 50 }), topic('few', 10, 0, { a: 9 })],
- ['you', 'a'],
- );
- expect(biggestGap(rows)).toBeNull();
- });
-});
-
describe('heatShade', () => {
it('spreads the tones over the scores in view', () => {
// A table of 50s to 80s still reads in steps.
diff --git a/web/src/lib/insights-topics.ts b/web/src/lib/insights-topics.ts
index 34a609a71..4449ccf23 100644
--- a/web/src/lib/insights-topics.ts
+++ b/web/src/lib/insights-topics.ts
@@ -119,17 +119,6 @@ export function topicHeatmap(topics: TopicCompetitors[], columns: string[]): Hea
);
}
-/**
- * The row "Send biggest gap to Actions" sends: the topic you trail by the
- * most, against the competitor leading it. Topics you lead or with too few
- * answers are never sent. Null when no competitor leads you anywhere.
- */
-export function biggestGap(rows: HeatmapRow[]): HeatmapRow | null {
- return rows
- .filter((r) => r.status === 'behind' && r.leader !== 'you')
- .reduce<HeatmapRow | null>((worst, r) => (!worst || r.gap! < worst.gap! ? r : worst), null);
-}
-
/**
* A cell's shade, light to dark, by where its score sits between the lowest
* and highest non-zero score in view. The map compares, so its tones spread
diff --git a/web/src/lib/insights-trend.test.ts b/web/src/lib/insights-trend.test.ts
index a6dd53c1f..bf14de4fb 100644
--- a/web/src/lib/insights-trend.test.ts
+++ b/web/src/lib/insights-trend.test.ts
@@ -49,8 +49,10 @@ describe('trendMarkers', () => {
it('puts each marker on the point of its day, or the next one with a point', () => {
const markers = trendMarkers(
{
- promptsAdded: [{ day: '2026-09-29', count: 509 }],
- actionsSent: [{ day: '2026-10-03', actionNos: [61] }],
+ promptsAdded: [
+ { day: '2026-09-29', count: 509 },
+ { day: '2026-10-03', count: 12 },
+ ],
goal: null,
},
points,
@@ -58,11 +60,11 @@ describe('trendMarkers', () => {
expect(markers).toEqual([
{ kind: 'prompts', day: '2026-09-29', date: '09-29', count: 509 },
- { kind: 'actions', day: '2026-10-03', date: '10-04', actionNos: [61] },
+ { kind: 'prompts', day: '2026-10-03', date: '10-04', count: 12 },
]);
});
- it('keeps the three biggest prompt days and the three latest action days', () => {
+ it('keeps the three biggest prompt days', () => {
const markers = trendMarkers(
{
promptsAdded: [
@@ -71,49 +73,30 @@ describe('trendMarkers', () => {
{ day: '2026-10-01', count: 2 },
{ day: '2026-10-02', count: 40 },
],
- actionsSent: ['2026-09-28', '2026-09-29', '2026-10-01', '2026-10-02'].map((day, i) => ({
- day,
- actionNos: [i + 1],
- })),
goal: null,
},
points,
);
- expect(markers.filter((m) => m.kind === 'prompts').map((m) => m.day)).toEqual([
- '2026-09-29',
- '2026-09-30',
- '2026-10-02',
- ]);
- expect(markers.filter((m) => m.kind === 'actions').map((m) => m.day)).toEqual([
- '2026-09-29',
- '2026-10-01',
- '2026-10-02',
- ]);
+ expect(markers.map((m) => m.day)).toEqual(['2026-09-29', '2026-09-30', '2026-10-02']);
});
it('lists a day after the last point without placing it on the chart', () => {
expect(
- trendMarkers(
- { promptsAdded: [{ day: '2026-10-05', count: 3 }], actionsSent: [], goal: null },
- points,
- ),
+ trendMarkers({ promptsAdded: [{ day: '2026-10-05', count: 3 }], goal: null }, points),
).toEqual([{ kind: 'prompts', day: '2026-10-05', date: null, count: 3 }]);
});
});
describe('parseTrendMarkers', () => {
- it('reads the RPC payload', () => {
+ it('reads the RPC payload, leaving the actions sent out', () => {
expect(
parseTrendMarkers({
prompts_added: [{ day: '2026-10-12', count: '7' }],
actions_sent: [{ day: '2026-10-13', action_nos: ['3', 4] }],
}),
- ).toEqual({
- promptsAdded: [{ day: '2026-10-12', count: 7 }],
- actionsSent: [{ day: '2026-10-13', actionNos: [3, 4] }],
- });
- expect(parseTrendMarkers(null)).toEqual({ promptsAdded: [], actionsSent: [] });
+ ).toEqual({ promptsAdded: [{ day: '2026-10-12', count: 7 }] });
+ expect(parseTrendMarkers(null)).toEqual({ promptsAdded: [] });
});
});
diff --git a/web/src/lib/insights-trend.ts b/web/src/lib/insights-trend.ts
index 59c6fb433..db6ae3be9 100644
--- a/web/src/lib/insights-trend.ts
+++ b/web/src/lib/insights-trend.ts
@@ -1,17 +1,16 @@
/**
* The Insights visibility trend (VIS-007), as in the v2 mockup: your line
* and the competitors you pin (they stay the same whatever the range),
- * markers for the days prompts were added and Action Center actions were
- * sent, and the Action Center goal. Kept apart from the chart so the rules
- * are tested on their own.
+ * markers for the days prompts were added, and the Action Center goal. Kept
+ * apart from the chart so the rules are tested on their own.
*/
/** At most this many competitors can be pinned (also a check on brands, 00136). */
export const MAX_PINNED_COMPETITORS = 5;
/** Without pins, the chart shows this many: the strongest at the end of the range. */
const AUTO_COMPETITORS = 4;
-/** Markers of each kind shown at once, so the chart stays readable. */
-const MARKERS_PER_KIND = 3;
+/** Prompt-day markers shown at once, so the chart stays readable. */
+const MAX_MARKERS = 3;
export const OWN_BRAND_COLOR = '#22c55e';
/** Competitor colors in line order: pin order, or rank without pins. */
@@ -64,12 +63,11 @@ export function trendLines<E extends Entity>(
export interface TrendMarkerData {
promptsAdded: { day: string; count: number }[];
- actionsSent: { day: string; actionNos: number[] }[];
/** The active "AI visibility" Action Center KPI's target; null without one. */
goal: number | null;
}
-/** The insights_trend_markers payload (00136). */
+/** The insights_trend_markers payload (00136); its actions_sent isn't shown. */
export function parseTrendMarkers(raw: unknown): Omit<TrendMarkerData, 'goal'> {
const r = (raw ?? {}) as Record<string, unknown>;
const rows = (v: unknown) => (Array.isArray(v) ? (v as Record<string, unknown>[]) : []);
@@ -78,44 +76,25 @@ export function parseTrendMarkers(raw: unknown): Omit<TrendMarkerData, 'goal'> {
day: String(d.day),
count: Number(d.count ?? 0),
})),
- actionsSent: rows(r.actions_sent).map((d) => ({
- day: String(d.day),
- actionNos: Array.isArray(d.action_nos) ? d.action_nos.map(Number) : [],
- })),
};
}
-export type TrendMarker =
- | { kind: 'prompts'; day: string; date: string | null; count: number }
- | { kind: 'actions'; day: string; date: string | null; actionNos: number[] };
+export type TrendMarker = { kind: 'prompts'; day: string; date: string | null; count: number };
/**
* The markers, each on the chart point of its day (or the next day with a
- * point): the days the most prompts were added and the latest days actions
- * were sent, three of each at most, in day order. A day after the last point
+ * point): the days the most prompts were added, three at most, in day order. A day after the last point
* (the latest run hasn't landed yet) gets no `date`: it is listed under the
* chart but not drawn on a day it didn't happen.
*/
export function trendMarkers(data: TrendMarkerData, points: Point[]): TrendMarker[] {
const dateOf = (day: string) => points.find((p) => p.day >= day)?.date ?? null;
- const prompts = [...data.promptsAdded]
+ return [...data.promptsAdded]
.sort((a, b) => b.count - a.count || b.day.localeCompare(a.day))
- .slice(0, MARKERS_PER_KIND)
- .map((d) => ({ kind: 'prompts' as const, day: d.day, date: dateOf(d.day), count: d.count }));
- const actions = [...data.actionsSent]
- .sort((a, b) => b.day.localeCompare(a.day))
- .slice(0, MARKERS_PER_KIND)
- .map((d) => ({
- kind: 'actions' as const,
- day: d.day,
- date: dateOf(d.day),
- actionNos: d.actionNos,
- }));
-
- return [...prompts, ...actions].sort(
- (a, b) => a.day.localeCompare(b.day) || a.kind.localeCompare(b.kind),
- );
+ .slice(0, MAX_MARKERS)
+ .map((d) => ({ kind: 'prompts' as const, day: d.day, date: dateOf(d.day), count: d.count }))
+ .sort((a, b) => a.day.localeCompare(b.day));
}
/**