feat: add monitor summary function
This commit is contained in:
parent
f1513fe3f7
commit
bbb8d88116
@ -67,3 +67,31 @@ export function getMonitorRecentData(
|
||||
})
|
||||
.then((arr) => arr.reverse());
|
||||
}
|
||||
|
||||
export function getMonitorSummaryWithDay(
|
||||
monitorId: string,
|
||||
beforeDay: number = 30
|
||||
) {
|
||||
interface MonitorSummaryItem {
|
||||
day: string;
|
||||
total_count: number;
|
||||
up_count: number;
|
||||
up_rate: number;
|
||||
}
|
||||
|
||||
return prisma.$queryRaw<MonitorSummaryItem[]>`
|
||||
SELECT
|
||||
DATE("createdAt") AS day,
|
||||
COUNT(1) AS total_count,
|
||||
SUM(CASE WHEN "value" >= 0 THEN 1 ELSE 0 END) AS up_count,
|
||||
(SUM(CASE WHEN "value" >= 0 THEN 1 ELSE 0 END) * 100.0 / COUNT(1)) AS up_rate
|
||||
FROM
|
||||
"MonitorData"
|
||||
WHERE
|
||||
"monitorId" = ${monitorId} AND
|
||||
"createdAt" >= CURRENT_DATE - INTERVAL '${beforeDay} days'
|
||||
GROUP BY
|
||||
DATE("createdAt")
|
||||
ORDER BY
|
||||
day;`;
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ export async function getWebsitePageviewMetrics(
|
||||
}
|
||||
|
||||
return prisma.$queryRaw`
|
||||
select ${Prisma.sql([`"${column}"`])} x, count(*) y
|
||||
select ${Prisma.sql([`"${column}"`])} x, count(*) y
|
||||
from "WebsiteEvent"
|
||||
${joinSession}
|
||||
where "WebsiteEvent"."websiteId" = ${websiteId}
|
||||
|
Loading…
Reference in New Issue
Block a user