Skip to content

Commit 06052f5

Browse files
committed
✨ feat: add visualization for the number of contest entrants in the last ten contests
1 parent 769ecf2 commit 06052f5

File tree

5 files changed

+129
-2
lines changed

5 files changed

+129
-2
lines changed

api/routers/contests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime
1+
from datetime import datetime, timedelta
22
from typing import List, Optional
33

44
from fastapi import APIRouter, Request
@@ -31,6 +31,8 @@ async def contests_user_num_last_ten(
3131
"""
3232
records = (
3333
await Contest.find(
34+
# In any situation, there must have been more than 10 contests in the last 60 days
35+
Contest.startTime > datetime.utcnow() - timedelta(days=60),
3436
Contest.user_num_us >= 0,
3537
Contest.user_num_cn >= 0,
3638
projection_model=ResultOfContestsUserNum,

client/src/components/Footer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const Footer = () => {
77
<div>
88
<span className="footer-title">LCCN Predictor</span>
99
<a
10-
href="https://twitter.com/intent/tweet?text=lccn.lbao.site%20Leetcode%20weekly%20and%20biweekly%20contest%20rating%20predictor%20@l__bao"
10+
href="https://twitter.com/intent/tweet?text=lccn.lbao.site%20Leetcode%20weekly%20and%20biweekly%20contest%20rating%20predictor"
1111
target="_blank"
1212
rel="noreferrer noopener"
1313
>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import ReactEcharts from "echarts-for-react";
2+
3+
const ContestsUserNumStackedArea = ({ contests }) => {
4+
contests.sort((a, b) => new Date(a.startTime) - new Date(b.startTime));
5+
console.log(contests);
6+
const titles = contests.map((contest) =>
7+
contest.title.replace(/eekly Contest /g, "")
8+
);
9+
const usNums = contests.map((contest) => contest.user_num_us);
10+
const cnNums = contests.map((contest) => contest.user_num_cn);
11+
const option = {
12+
title: {
13+
text: "Number of Contest Entrants",
14+
x: "center",
15+
},
16+
color: ["#ee6666", "#5470c6"],
17+
tooltip: {
18+
trigger: "axis",
19+
axisPointer: {
20+
type: "cross",
21+
label: {
22+
backgroundColor: "#6a7985",
23+
},
24+
},
25+
},
26+
legend: {
27+
data: ["US", "CN"],
28+
left: "80%",
29+
},
30+
toolbox: {
31+
feature: {
32+
saveAsImage: {},
33+
},
34+
},
35+
grid: {
36+
left: "3%",
37+
right: "4%",
38+
bottom: "3%",
39+
containLabel: true,
40+
},
41+
xAxis: [
42+
{
43+
type: "category",
44+
boundaryGap: false,
45+
name: "Contest",
46+
// axisLabel: {
47+
// rotate: 75,
48+
// },
49+
data: titles,
50+
},
51+
],
52+
yAxis: [
53+
{
54+
type: "value",
55+
name: "User Count",
56+
},
57+
],
58+
series: [
59+
{
60+
name: "CN",
61+
type: "line",
62+
stack: "Total",
63+
label: {
64+
show: true,
65+
position: "top",
66+
},
67+
areaStyle: {},
68+
emphasis: {
69+
focus: "series",
70+
},
71+
data: cnNums,
72+
},
73+
{
74+
name: "US",
75+
type: "line",
76+
stack: "Total",
77+
label: {
78+
show: true,
79+
position: "top",
80+
},
81+
areaStyle: {},
82+
emphasis: {
83+
focus: "series",
84+
},
85+
data: usNums,
86+
},
87+
],
88+
};
89+
90+
return (
91+
<ReactEcharts
92+
option={option}
93+
// theme="dark"
94+
// lazyUpdate={true}
95+
// opts={{renderer: "svg"}}
96+
// style={{
97+
// height: "25em",
98+
// }}
99+
/>
100+
);
101+
};
102+
103+
export default ContestsUserNumStackedArea;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import ContestsUserNumStackedArea from "../../components/charts/ContestsUserNumStackedArea.jsx";
2+
import useSWR from "swr";
3+
import { baseUrl } from "../../data/constants.js";
4+
5+
const ContestsUserNum = () => {
6+
const { data: contests } = useSWR(
7+
`${baseUrl}/contests/user-num-last-ten`,
8+
(url) => fetch(url).then((r) => r.json()),
9+
{ revalidateOnFocus: false }
10+
);
11+
return (
12+
contests && (
13+
<div className="container mx-auto text-center w-8/9">
14+
<ContestsUserNumStackedArea contests={contests} />
15+
</div>
16+
)
17+
);
18+
};
19+
20+
export default ContestsUserNum;

client/src/pages/Predicted/PredictedContests.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Link } from "react-router-dom";
44
import useSWR from "swr";
55
import Pagination from "../../components/Pagination";
66
import { baseUrl } from "../../data/constants";
7+
import ContestsUserNum from "../Contests/ContestsUserNum";
78

89
const ContestsTable = ({ contests }) => {
910
return (
@@ -123,6 +124,7 @@ const PredictedContest = () => {
123124

124125
return (
125126
<>
127+
<ContestsUserNum />
126128
{contests ? <ContestsTable contests={contests} /> : undefined}
127129
<Pagination
128130
totalCount={totalCount}

0 commit comments

Comments
 (0)