add time range param for apis stats
This commit is contained in:
@@ -119,11 +119,11 @@ async function InteractiveBarChartSection() {
|
||||
|
||||
// 请求统计图表组件
|
||||
async function RequestStatsSection() {
|
||||
const screenshot_stats = await getScrapeStatsByType("screenshot");
|
||||
const meta_stats = await getScrapeStatsByType("meta-info");
|
||||
const md_stats = await getScrapeStatsByType("markdown");
|
||||
const text_stats = await getScrapeStatsByType("text");
|
||||
const qr_stats = await getScrapeStatsByType("qrcode");
|
||||
const screenshot_stats = await getScrapeStatsByType("screenshot", "90d");
|
||||
const meta_stats = await getScrapeStatsByType("meta-info", "90d");
|
||||
const md_stats = await getScrapeStatsByType("markdown", "90d");
|
||||
const text_stats = await getScrapeStatsByType("text", "90d");
|
||||
const qr_stats = await getScrapeStatsByType("qrcode", "90d");
|
||||
|
||||
const hasStats =
|
||||
screenshot_stats.length > 0 ||
|
||||
@@ -155,8 +155,8 @@ async function RadialShapeChartSection() {
|
||||
|
||||
// 二维码/截图折线图组件
|
||||
async function QrScreenshotChartSection() {
|
||||
const screenshot_stats = await getScrapeStatsByType("screenshot");
|
||||
const qr_stats = await getScrapeStatsByType("qrcode");
|
||||
const screenshot_stats = await getScrapeStatsByType("screenshot", "90d");
|
||||
const qr_stats = await getScrapeStatsByType("qrcode", "90d");
|
||||
|
||||
return (
|
||||
<LineChartMultiple
|
||||
@@ -169,8 +169,8 @@ async function QrScreenshotChartSection() {
|
||||
|
||||
// 截图/元信息折线图组件
|
||||
async function ScreenshotMetaChartSection() {
|
||||
const screenshot_stats = await getScrapeStatsByType("screenshot");
|
||||
const meta_stats = await getScrapeStatsByType("meta-info");
|
||||
const screenshot_stats = await getScrapeStatsByType("screenshot", "90d");
|
||||
const meta_stats = await getScrapeStatsByType("meta-info", "90d");
|
||||
|
||||
return (
|
||||
<LineChartMultiple
|
||||
@@ -183,8 +183,8 @@ async function ScreenshotMetaChartSection() {
|
||||
|
||||
// Markdown/文本折线图组件
|
||||
async function MarkdownTextChartSection() {
|
||||
const md_stats = await getScrapeStatsByType("markdown");
|
||||
const text_stats = await getScrapeStatsByType("text");
|
||||
const md_stats = await getScrapeStatsByType("markdown", "90d");
|
||||
const text_stats = await getScrapeStatsByType("text", "90d");
|
||||
|
||||
return (
|
||||
<LineChartMultiple
|
||||
|
||||
@@ -5,7 +5,7 @@ import Link from "next/link";
|
||||
import { ScrapeMeta } from "@prisma/client";
|
||||
import { Area, AreaChart, CartesianGrid, XAxis } from "recharts";
|
||||
|
||||
import { isLink, removeUrlSuffix, timeAgo } from "@/lib/utils";
|
||||
import { isLink, nFormatter, removeUrlSuffix, timeAgo } from "@/lib/utils";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
@@ -109,7 +109,7 @@ export function DailyPVUVChart({ data }: { data: ScrapeMeta[] }) {
|
||||
<Card>
|
||||
<CardHeader className="flex flex-col items-stretch space-y-0 border-b p-0 sm:flex-row">
|
||||
<div className="flex flex-1 flex-col justify-center gap-1 px-6 py-2 sm:py-3">
|
||||
<CardTitle>Total Requests of APIs</CardTitle>
|
||||
<CardTitle>Total Requests of APIs in Last 3 Month</CardTitle>
|
||||
<CardDescription>
|
||||
Last request from <strong>{latestFrom}</strong> api about{" "}
|
||||
{latestDate}.
|
||||
@@ -129,7 +129,7 @@ export function DailyPVUVChart({ data }: { data: ScrapeMeta[] }) {
|
||||
{chartConfig[chart].label}
|
||||
</span>
|
||||
<span className="text-lg font-bold leading-none">
|
||||
<CountUp count={dataTotal[key]} />
|
||||
{nFormatter(dataTotal[key])}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Bar, BarChart, CartesianGrid, XAxis } from "recharts";
|
||||
import useSWR from "swr";
|
||||
|
||||
import { DATE_DIMENSION_ENUMS } from "@/lib/enums";
|
||||
import { cn, fetcher } from "@/lib/utils";
|
||||
import { cn, fetcher, nFormatter } from "@/lib/utils";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
@@ -148,7 +148,7 @@ export function InteractiveBarChart() {
|
||||
{chartConfig[chart].label}
|
||||
</span>
|
||||
<span className="text-lg font-bold leading-none sm:text-3xl">
|
||||
<CountUp count={data.total[key]} />
|
||||
{nFormatter(data.total[key])}
|
||||
</span>
|
||||
<span
|
||||
className={cn(
|
||||
|
||||
@@ -9,7 +9,8 @@ export default function CountUpFn({ count }: { count: number }) {
|
||||
<CountUp
|
||||
end={count}
|
||||
duration={2}
|
||||
formattingFn={(value) => nFormatter(value, 2)}
|
||||
redraw={false}
|
||||
formattingFn={(value) => nFormatter(value)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
+10
-1
@@ -2,6 +2,8 @@ import { ScrapeMeta } from "@prisma/client";
|
||||
|
||||
import { prisma } from "@/lib/db";
|
||||
|
||||
import { getStartDate } from "../utils";
|
||||
|
||||
export async function createScrapeMeta(
|
||||
data: Omit<ScrapeMeta, "id" | "createdAt" | "updatedAt">,
|
||||
) {
|
||||
@@ -50,10 +52,17 @@ export async function getApiKeyCallCount() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getScrapeStatsByType(type: string) {
|
||||
export async function getScrapeStatsByType(
|
||||
type: string,
|
||||
dateRange: string = "",
|
||||
) {
|
||||
const startDate = getStartDate(dateRange);
|
||||
return await prisma.scrapeMeta.findMany({
|
||||
where: {
|
||||
type,
|
||||
...(startDate && {
|
||||
createdAt: { gte: startDate },
|
||||
}),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -226,7 +226,6 @@ export async function getUserUrlMetaInfo(
|
||||
dateRange: string = "",
|
||||
) {
|
||||
const startDate = getStartDate(dateRange);
|
||||
|
||||
return await prisma.urlMeta.findMany({
|
||||
where: {
|
||||
urlId,
|
||||
|
||||
+1
-1
@@ -150,7 +150,7 @@ export async function fetcher<JSON = any>(
|
||||
export const isValidEmail = (email: string) =>
|
||||
/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
||||
|
||||
export function nFormatter(num: number, digits?: number) {
|
||||
export function nFormatter(num: number, digits: number = 2) {
|
||||
if (!num) return "0";
|
||||
const lookup = [
|
||||
{ value: 1, symbol: "" },
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user