refactor: comment out unused timeserie queries in stats router
This commit is contained in:
parent
068f4b0c01
commit
9782cde917
1 changed files with 68 additions and 74 deletions
|
|
@ -1,81 +1,78 @@
|
||||||
import { sql } from "kysely";
|
|
||||||
import type { StackedTimeserie } from "~/components/timeserieBarChartStacked";
|
|
||||||
import TipologiaPosizioneEnum from "~/schemas/public/TipologiaPosizioneEnum";
|
|
||||||
import { adminProcedure, createTRPCRouter } from "~/server/api/trpc";
|
import { adminProcedure, createTRPCRouter } from "~/server/api/trpc";
|
||||||
import { db } from "~/server/db";
|
import { db } from "~/server/db";
|
||||||
|
|
||||||
export const statsRouter = createTRPCRouter({
|
export const statsRouter = createTRPCRouter({
|
||||||
adminDashStats: adminProcedure.query(async () => {
|
adminDashStats: adminProcedure.query(async () => {
|
||||||
const userTimeserie = (
|
// const userTimeserie = (
|
||||||
await db
|
// await db
|
||||||
.selectFrom("users")
|
// .selectFrom("users")
|
||||||
.select((eb) => [
|
// .select((eb) => [
|
||||||
sql<Date>`date_trunc('day', created_at)`.as("date"),
|
// sql<Date>`date_trunc('day', created_at)`.as("date"),
|
||||||
eb.fn.count<number>("id").as("value"),
|
// eb.fn.count<number>("id").as("value"),
|
||||||
])
|
// ])
|
||||||
.where("isAdmin", "=", false)
|
// .where("isAdmin", "=", false)
|
||||||
.groupBy("date")
|
// .groupBy("date")
|
||||||
.orderBy("date")
|
// .orderBy("date")
|
||||||
.execute()
|
// .execute()
|
||||||
).map((item) => ({
|
// ).map((item) => ({
|
||||||
date: item.date,
|
// date: item.date,
|
||||||
value: parseInt(String(item.value)),
|
// value: parseInt(String(item.value)),
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
const serviziTimeserie = {
|
// const serviziTimeserie = {
|
||||||
data: Object.values(
|
// data: Object.values(
|
||||||
(
|
// (
|
||||||
await db
|
// await db
|
||||||
.selectFrom("servizio")
|
// .selectFrom("servizio")
|
||||||
.select((eb) => [
|
// .select((eb) => [
|
||||||
sql<Date>`date_trunc('day', created_at)`.as("date"),
|
// sql<Date>`date_trunc('day', created_at)`.as("date"),
|
||||||
eb.fn.count<number>("servizio_id").as("value"),
|
// eb.fn.count<number>("servizio_id").as("value"),
|
||||||
"tipologia",
|
// "tipologia",
|
||||||
])
|
// ])
|
||||||
.groupBy(["date", "tipologia"])
|
// .groupBy(["date", "tipologia"])
|
||||||
.orderBy("date")
|
// .orderBy("date")
|
||||||
.execute()
|
// .execute()
|
||||||
).reduce(
|
// ).reduce(
|
||||||
(acc, item) => {
|
// (acc, item) => {
|
||||||
const dateStr = item.date.toISOString().slice(0, 10);
|
// const dateStr = item.date.toISOString().slice(0, 10);
|
||||||
if (!acc[dateStr]) {
|
// if (!acc[dateStr]) {
|
||||||
acc[dateStr] = {
|
// acc[dateStr] = {
|
||||||
date: item.date,
|
// date: item.date,
|
||||||
valueA: 0,
|
// valueA: 0,
|
||||||
valueB: 0,
|
// valueB: 0,
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
if (item.tipologia === TipologiaPosizioneEnum.Transitorio) {
|
// if (item.tipologia === TipologiaPosizioneEnum.Transitorio) {
|
||||||
acc[dateStr].valueA = parseInt(String(item.value));
|
// acc[dateStr].valueA = parseInt(String(item.value));
|
||||||
} else if (item.tipologia === TipologiaPosizioneEnum.Stabile) {
|
// } else if (item.tipologia === TipologiaPosizioneEnum.Stabile) {
|
||||||
acc[dateStr].valueB = parseInt(String(item.value));
|
// acc[dateStr].valueB = parseInt(String(item.value));
|
||||||
}
|
// }
|
||||||
return acc;
|
// return acc;
|
||||||
},
|
// },
|
||||||
{} as Record<string, StackedTimeserie>,
|
// {} as Record<string, StackedTimeserie>,
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
valueALabel: "Transitorio",
|
// valueALabel: "Transitorio",
|
||||||
valueBLabel: "Stabile",
|
// valueBLabel: "Stabile",
|
||||||
};
|
// };
|
||||||
|
|
||||||
const contattiTimeserie = (
|
// const contattiTimeserie = (
|
||||||
await db
|
// await db
|
||||||
.selectFrom("servizio_annunci")
|
// .selectFrom("servizio_annunci")
|
||||||
.select((eb) => [
|
// .select((eb) => [
|
||||||
sql<Date>`date_trunc('day', created_at)`.as("date"),
|
// sql<Date>`date_trunc('day', created_at)`.as("date"),
|
||||||
eb.fn
|
// eb.fn
|
||||||
.count<number>(eb.fn("concat", ["servizio_id", "annunci_id"]))
|
// .count<number>(eb.fn("concat", ["servizio_id", "annunci_id"]))
|
||||||
.as("value"),
|
// .as("value"),
|
||||||
])
|
// ])
|
||||||
.where("open_contatti_at", "is not", null)
|
// .where("open_contatti_at", "is not", null)
|
||||||
.groupBy("date")
|
// .groupBy("date")
|
||||||
.orderBy("date")
|
// .orderBy("date")
|
||||||
.execute()
|
// .execute()
|
||||||
).map((item) => ({
|
// ).map((item) => ({
|
||||||
date: item.date,
|
// date: item.date,
|
||||||
value: parseInt(String(item.value)),
|
// value: parseInt(String(item.value)),
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
const userCount =
|
const userCount =
|
||||||
(
|
(
|
||||||
|
|
@ -86,10 +83,7 @@ export const statsRouter = createTRPCRouter({
|
||||||
)?.count || 0;
|
)?.count || 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
contattiTimeserie,
|
|
||||||
serviziTimeserie,
|
|
||||||
userCount,
|
userCount,
|
||||||
userTimeserie,
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue