Skip to content

Commit c453490

Browse files
committed
Generated by Spark: in te modesl used panel, show the names of the models as well.
in the chart, do not show the lines per model itself, just compliant / exceeding
1 parent 004bb7b commit c453490

2 files changed

Lines changed: 51 additions & 58 deletions

File tree

src/App.tsx

Lines changed: 50 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function App() {
9292
}
9393
}, [processFile]);
9494

95-
// Generate chart data grouped by date with a stacked entry for each model
95+
// Generate chart data grouped by date with total compliant and exceeding requests
9696
const chartData = useCallback(() => {
9797
if (!aggregatedData.length) return [];
9898

@@ -101,12 +101,16 @@ function App() {
101101

102102
aggregatedData.forEach(item => {
103103
if (!groupedByDate[item.date]) {
104-
groupedByDate[item.date] = { date: item.date };
104+
groupedByDate[item.date] = {
105+
date: item.date,
106+
compliant: 0,
107+
exceeding: 0
108+
};
105109
}
106110

107-
// Add compliant and exceeding requests for this model
108-
groupedByDate[item.date][`${item.model}_compliant`] = item.compliantRequests;
109-
groupedByDate[item.date][`${item.model}_exceeding`] = item.exceedingRequests;
111+
// Add to total compliant and exceeding requests
112+
groupedByDate[item.date].compliant += item.compliantRequests;
113+
groupedByDate[item.date].exceeding += item.exceedingRequests;
110114
});
111115

112116
// Convert to array sorted by date
@@ -186,13 +190,16 @@ function App() {
186190
<p className="text-2xl font-bold">
187191
{uniqueModels.length}
188192
</p>
193+
<div className="mt-2 text-xs text-muted-foreground">
194+
{uniqueModels.join(", ")}
195+
</div>
189196
</div>
190197
</Card>
191198
</div>
192199
</div>
193200

194201
<div>
195-
<h2 className="text-2xl font-semibold mb-2">Daily Usage by Model</h2>
202+
<h2 className="text-2xl font-semibold mb-2">Daily Usage Overview</h2>
196203
<Separator className="mb-6" />
197204
<div className="bg-card p-4 rounded-lg border">
198205
<ChartContainer
@@ -216,40 +223,28 @@ function App() {
216223
<ChartTooltip
217224
content={({ active, payload, label }) => {
218225
if (active && payload && payload.length) {
219-
const modelsData: Record<string, { compliant: number, exceeding: number }> = {};
220-
221-
payload.forEach(item => {
222-
const keyParts = String(item.dataKey).split('_');
223-
const model = keyParts[0];
224-
const type = keyParts[1];
225-
226-
if (!modelsData[model]) {
227-
modelsData[model] = { compliant: 0, exceeding: 0 };
228-
}
229-
230-
modelsData[model][type as 'compliant' | 'exceeding'] = Number(item.value || 0);
231-
});
226+
const compliant = payload.find(p => p.dataKey === 'compliant')?.value || 0;
227+
const exceeding = payload.find(p => p.dataKey === 'exceeding')?.value || 0;
228+
const total = Number(compliant) + Number(exceeding);
232229

233230
return (
234231
<div className="border rounded-lg bg-background shadow-lg p-3 text-xs">
235232
<div className="font-medium mb-2">{label}</div>
236233
<div className="space-y-2">
237-
{Object.entries(modelsData).map(([model, stats]) => (
238-
<div key={model} className="grid grid-cols-2 gap-2">
239-
<div className="font-medium">{model}</div>
240-
<div />
241-
<div className="flex items-center gap-1.5">
242-
<div className="w-2 h-2 rounded-full bg-[#10b981]" />
243-
<span>Compliant:</span>
244-
</div>
245-
<div className="text-right">{stats.compliant}</div>
246-
<div className="flex items-center gap-1.5">
247-
<div className="w-2 h-2 rounded-full bg-[#ef4444]" />
248-
<span>Exceeding:</span>
249-
</div>
250-
<div className="text-right">{stats.exceeding}</div>
234+
<div className="grid grid-cols-2 gap-2">
235+
<div className="flex items-center gap-1.5">
236+
<div className="w-2 h-2 rounded-full bg-[#10b981]" />
237+
<span>Compliant:</span>
238+
</div>
239+
<div className="text-right">{compliant}</div>
240+
<div className="flex items-center gap-1.5">
241+
<div className="w-2 h-2 rounded-full bg-[#ef4444]" />
242+
<span>Exceeding:</span>
251243
</div>
252-
))}
244+
<div className="text-right">{exceeding}</div>
245+
<div className="font-medium">Total:</div>
246+
<div className="text-right font-medium">{total}</div>
247+
</div>
253248
</div>
254249
</div>
255250
);
@@ -259,29 +254,27 @@ function App() {
259254
/>
260255
<Legend />
261256

262-
{/* Create lines for each model */}
263-
{uniqueModels.flatMap(model => [
264-
<Line
265-
key={`${model}_compliant`}
266-
type="monotone"
267-
dataKey={`${model}_compliant`}
268-
name={`${model} (Compliant)`}
269-
stroke="#10b981"
270-
strokeWidth={2}
271-
activeDot={{ r: 6 }}
272-
stackId="1"
273-
/>,
274-
<Line
275-
key={`${model}_exceeding`}
276-
type="monotone"
277-
dataKey={`${model}_exceeding`}
278-
name={`${model} (Exceeding)`}
279-
stroke="#ef4444"
280-
strokeWidth={2}
281-
activeDot={{ r: 6 }}
282-
stackId="1"
283-
/>
284-
])}
257+
{/* Show only two lines: compliant and exceeding */}
258+
<Line
259+
key="compliant"
260+
type="monotone"
261+
dataKey="compliant"
262+
name="Compliant Requests"
263+
stroke="#10b981"
264+
strokeWidth={2}
265+
activeDot={{ r: 6 }}
266+
stackId="1"
267+
/>
268+
<Line
269+
key="exceeding"
270+
type="monotone"
271+
dataKey="exceeding"
272+
name="Exceeding Requests"
273+
stroke="#ef4444"
274+
strokeWidth={2}
275+
activeDot={{ r: 6 }}
276+
stackId="1"
277+
/>
285278
</LineChart>
286279
</ChartContainer>
287280
</div>

src/prd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
- Success: Properly parses CSV format with correct data types and handles validation with clear feedback
2626

2727
2. **Stacked Line Graph**
28-
- What: Visualize request data by model per day with color-coded status indicators
28+
- What: Visualize daily request data with color-coded status indicators showing compliant vs exceeding requests
2929
- Why: Makes usage patterns and quota status immediately apparent
3030
- Success: Clearly shows trends over time and distinguishes between quota-compliant and exceeding requests
3131

0 commit comments

Comments
 (0)