Skip to content

Commit 2537a6d

Browse files
SaraVieiracdxker
authored andcommitted
fix: fill empty dates in rag usage chart
1 parent c350a5a commit 2537a6d

4 files changed

Lines changed: 64 additions & 30 deletions

File tree

frontends/analytics/src/components/SingleQueryInfo.tsx

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,23 @@ export const SingleQuery = (props: SingleQueryProps) => {
5454
)}
5555
</div>
5656
<div class="h-2" />
57-
<div class="flex-start flex justify-center gap-2">
58-
<DataSquare label="Search Type" value={props.data.search_type} />
59-
<DataSquare
60-
label="Dataset"
61-
value={datasetName() || props.data.dataset_id}
62-
/>
63-
<DataSquare label="Results" value={props.data.results.length} />
64-
<DataSquare label="Latency" value={`${props.data.latency}ms`} />
65-
<DataSquare
66-
label="Top Score"
67-
value={props.data.top_score.toPrecision(4)}
68-
/>
57+
<div>
58+
<h3 class="text-base font-semibold leading-6 text-gray-900">
59+
Last 30 days
60+
</h3>
61+
<dl class="m-auto mt-5 grid max-w-4xl grid-cols-1 divide-y divide-gray-200 overflow-hidden rounded-lg bg-white shadow md:grid-cols-5 md:divide-x md:divide-y-0">
62+
<DataSquare label="Search Type" value={props.data.search_type} />
63+
<DataSquare
64+
label="Dataset"
65+
value={datasetName() || props.data.dataset_id}
66+
/>
67+
<DataSquare label="Results" value={props.data.results.length} />
68+
<DataSquare label="Latency" value={`${props.data.latency}ms`} />
69+
<DataSquare
70+
label="Top Score"
71+
value={props.data.top_score.toPrecision(4)}
72+
/>
73+
</dl>
6974
</div>
7075
<div class="h-4" />
7176
<div class="text-bold mb-2 h-2 w-full border-t-2 border-t-neutral-300/80 text-neutral-800 outline-neutral-500" />
@@ -101,9 +106,13 @@ export const DataSquare = (props: {
101106
value: number | string;
102107
}) => {
103108
return (
104-
<div class="rounded-md border border-neutral-200 bg-white p-3 text-center shadow-md">
105-
<div>{props.label}</div>
106-
<div class="font-medium">{props.value}</div>
109+
<div class="px-4 py-5 sm:p-6">
110+
<dt class="text-base font-normal text-gray-900">{props.label}</dt>
111+
<dd class="mt-1 flex items-baseline justify-start md:block lg:flex">
112+
<div class="flex items-baseline text-xl font-semibold text-fuchsia-600">
113+
{props.value}
114+
</div>
115+
</dd>
107116
</div>
108117
);
109118
};

frontends/analytics/src/components/charts/Card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const Card = (props: CardProps) => {
1616
style={{
1717
"grid-column": `span ${props.width}`,
1818
}}
19-
class={`shadow-sm rounded-md border border-neutral-100 bg-white p-4 ${classStuff.class}`}
19+
class={`rounded-md border border-neutral-100 bg-white p-4 shadow-sm ${classStuff.class}`}
2020
>
2121
<div class="mb-4 flex items-center justify-between">
2222
<div>

frontends/analytics/src/components/charts/RAGUsageGraph.tsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface RAGUsageProps {
2222
import "chartjs-adapter-date-fns";
2323
import { Card } from "./Card";
2424
import { parseCustomDateString } from "../../utils/formatDate";
25+
import { eachDayOfInterval, isSameDay, subDays } from "date-fns";
2526

2627
export const RAGUsageGraph = (props: RAGUsageProps) => {
2728
const dataset = useContext(DatasetContext);
@@ -92,6 +93,9 @@ export const RAGUsageGraph = (props: RAGUsageProps) => {
9293
},
9394
},
9495
type: "time",
96+
time: {
97+
unit: "day",
98+
},
9599
title: {
96100
text: "Timestamp",
97101
display: true,
@@ -130,12 +134,32 @@ export const RAGUsageGraph = (props: RAGUsageProps) => {
130134
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
131135
chartInstance.options.scales["x"].time.unit = undefined;
132136
}
137+
const info = eachDayOfInterval({
138+
start: props.params.filter.date_range?.gte || subDays(new Date(), 7),
139+
end: props.params.filter.date_range?.lte || new Date(),
140+
}).map((d) => {
141+
return data.reduce(
142+
(acc, curr) => {
143+
const parsedDate = new Date(parseCustomDateString(curr.time_stamp));
144+
if (isSameDay(parsedDate, d)) {
145+
acc = {
146+
time_stamp: parsedDate,
147+
requests: curr.requests,
148+
};
149+
}
150+
151+
return acc;
152+
},
153+
{
154+
time_stamp: d,
155+
requests: 0,
156+
},
157+
);
158+
});
133159

134160
// Update the chart data;
135-
chartInstance.data.labels = data.map(
136-
(point) => new Date(parseCustomDateString(point.time_stamp)),
137-
);
138-
chartInstance.data.datasets[0].data = data.map((point) => point.requests);
161+
chartInstance.data.labels = info.map((point) => point.time_stamp);
162+
chartInstance.data.datasets[0].data = info.map((point) => point.requests);
139163
chartInstance.update();
140164
});
141165

frontends/analytics/src/pages/tablePages/SearchTablePage.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,22 @@ export const SearchTablePage = () => {
108108

109109
return (
110110
<div>
111-
112111
<div class="my-4 rounded-md bg-white">
113112
<Show
114113
fallback={<div class="py-8 text-center">Loading...</div>}
115114
when={searchTableQuery.data}
116115
>
117-
<Card>
118-
<FilterBar noPadding filters={filters} setFilters={setFilters} />
119-
<TanStackTable
120-
pages={pages}
121-
perPage={10}
122-
table={table}
123-
onRowClick={(row: SearchQueryEvent) => navigate(`/query/${row.id}`)}
124-
/>
125-
</Card>
116+
<Card>
117+
<FilterBar noPadding filters={filters} setFilters={setFilters} />
118+
<TanStackTable
119+
pages={pages}
120+
perPage={10}
121+
table={table}
122+
onRowClick={(row: SearchQueryEvent) =>
123+
navigate(`/query/${row.id}`)
124+
}
125+
/>
126+
</Card>
126127
</Show>
127128
</div>
128129
</div>

0 commit comments

Comments
 (0)