migration

This commit is contained in:
Théo LAGACHE
2025-05-16 15:54:17 +02:00
parent 01019fe1a3
commit 6f2523e524
285 changed files with 15492 additions and 46090 deletions
@@ -1,54 +1,37 @@
"use client"
import {ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent} from "@/components/ui/chart";
import {CartesianGrid, Line, LineChart, XAxis, YAxis} from "recharts";
import {humanReadableDate} from "@/utils/date-formatting";
const data = [
{date: "2024-12-01", count: 1},
{date: "2024-12-02", count: 2},
{date: "2024-12-03", count: 4},
{date: "2024-12-04", count: 8},
{date: "2024-12-05", count: 9},
{date: "2024-12-06", count: 9},
{date: "2024-12-07", count: 10},
{date: "2024-12-08", count: 13},
{date: "2024-12-09", count: 15},
{date: "2024-12-10", count: 18},
]
"use client";
import { ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent } from "@/components/ui/chart";
import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts";
import { humanReadableDate } from "@/utils/date-formatting";
type Data = {
createdAt: Date;
}
};
export type evolutionLineChartProps = {
data: Data[]
}
data: Data[];
};
export function EvolutionLineChart(props: evolutionLineChartProps) {
const {data} = props
console.log("aaa data", data)
const { data } = props;
// Process data to calculate cumulative count
const cumulativeData = data.reduce((acc, backup) => {
const date = backup.createdAt.toISOString().split("T")[0]; // Format as YYYY-MM-DD
const cumulativeData = data.reduce(
(acc, backup) => {
const date = backup.createdAt.toISOString().split("T")[0]; // Format as YYYY-MM-DD
// Increment count for the current date or initialize it
if (acc.length && acc[acc.length - 1].date === date) {
acc[acc.length - 1].count += 1;
} else {
const lastCount = acc.length ? acc[acc.length - 1].count : 0;
acc.push({date, count: lastCount + 1});
}
return acc;
}, [] as { date: string; count: number }[]);
// Increment count for the current date or initialize it
if (acc.length && acc[acc.length - 1].date === date) {
acc[acc.length - 1].count += 1;
} else {
const lastCount = acc.length ? acc[acc.length - 1].count : 0;
acc.push({ date, count: lastCount + 1 });
}
return acc;
},
[] as { date: string; count: number }[]
);
const chartConfig = {
date: {
@@ -59,8 +42,7 @@ export function EvolutionLineChart(props: evolutionLineChartProps) {
label: "Number of backups",
color: "#60a5fa",
},
} satisfies ChartConfig
} satisfies ChartConfig;
return (
<ChartContainer config={chartConfig}>
@@ -72,27 +54,18 @@ export function EvolutionLineChart(props: evolutionLineChartProps) {
right: 12,
}}
>
<CartesianGrid vertical={false}/>
<CartesianGrid vertical={false} />
<XAxis
dataKey="date"
tickLine={false}
axisLine={false}
tickMargin={8}
tickFormatter={(value) => humanReadableDate(Date(value)).split(' ')[0]}
/>
<YAxis/>
<ChartTooltip
cursor={false}
content={<ChartTooltipContent hideLabel/>}
/>
<Line
dataKey="count"
type="linear"
stroke="var(--color-desktop)"
strokeWidth={2}
dot={false}
tickFormatter={(value) => humanReadableDate(new Date(value)).split(" ")[0]}
/>
<YAxis />
<ChartTooltip cursor={false} content={<ChartTooltipContent hideLabel />} />
<Line dataKey="count" type="linear" stroke="var(--color-desktop)" strokeWidth={2} dot={false} />
</LineChart>
</ChartContainer>
)
}
);
}
@@ -1,22 +1,21 @@
"use client"
"use client";
import {ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent} from "@/components/ui/chart";
import {CartesianGrid, Line, LineChart, XAxis, YAxis} from "recharts";
import { ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent } from "@/components/ui/chart";
import { EStatusSchema } from "@/db/schema/types";
import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts";
type Data = {
createdAt: Date;
status: "success" | "failed";
_count: { id: number };
}
status: EStatusSchema;
_count: number;
};
export type percentageLineChartProps = {
data: Data[]
}
data: Data[];
};
export function PercentageLineChart(props: percentageLineChartProps) {
const {data} = props
const { data } = props;
const chartConfig = {
date: {
@@ -27,21 +26,24 @@ export function PercentageLineChart(props: percentageLineChartProps) {
label: "Success Rate",
color: "#60a5fa",
},
} satisfies ChartConfig
} satisfies ChartConfig;
const dailyStats = data.reduce((acc, backup) => {
const date = backup.createdAt.toISOString().split("T")[0]; // Format YYYY-MM-DD
const status = backup.status;
const dailyStats = data.reduce(
(acc, backup) => {
const date = backup.createdAt.toISOString().split("T")[0]; // Format YYYY-MM-DD
const status = backup.status;
if (!acc[date]) {
acc[date] = {success: 0, failed: 0, total: 0};
}
if (!acc[date]) {
acc[date] = { success: 0, failed: 0, total: 0 };
}
acc[date][status === "success" ? "success" : "failed"] += backup._count.id;
acc[date].total += backup._count.id;
acc[date][status === "success" ? "success" : "failed"] += backup._count.id;
acc[date].total += backup._count.id;
return acc;
}, {} as Record<string, { success: number; failed: number; total: number }>);
return acc;
},
{} as Record<string, { success: number; failed: number; total: number }>
);
// Format data for the chart
const formattedData = Object.entries(dailyStats).map(([date, stats]) => ({
@@ -51,35 +53,26 @@ export function PercentageLineChart(props: percentageLineChartProps) {
return (
<ChartContainer config={chartConfig}>
<LineChart
accessibilityLayer
data={formattedData}
>
<CartesianGrid strokeDasharray="3 3"/>
<XAxis dataKey="date"/>
<YAxis domain={[0, 100]} tickFormatter={(tick) => `${tick}%`}/>
<LineChart accessibilityLayer data={formattedData}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="date" />
<YAxis domain={[0, 100]} tickFormatter={(tick) => `${tick}%`} />
<ChartTooltip
content={<ChartTooltipContent/>}
content={<ChartTooltipContent />}
cursor={false}
defaultIndex={1}
formatter={(value, name) => (
<div className="flex min-w-[130px] items-center text-xs text-muted-foreground">
{chartConfig[name as keyof typeof chartConfig]?.label ||
name}
<div
className="ml-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums text-foreground">
{chartConfig[name as keyof typeof chartConfig]?.label || name}
<div className="ml-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums text-foreground">
{value}
<span className="font-normal text-muted-foreground">
%
</span>
<span className="font-normal text-muted-foreground">%</span>
</div>
</div>
)}
/>
<Line type="step" dataKey="successRate" stroke="#8884d8" strokeWidth={2}/>
<Line type="step" dataKey="successRate" stroke="#8884d8" strokeWidth={2} />
</LineChart>
</ChartContainer>
)
);
}