Skip to content

Commit 9e130d5

Browse files
committed
add: Add TEE In Those Days Chart to UserPage.
1 parent 486da04 commit 9e130d5

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

atcoder-problems-frontend/src/pages/UserPage/ProgressChartBlock/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { useLocalStorage } from "../../../utils/LocalStorage";
2727
import {
2828
countUniqueAcByDate,
2929
countTeeByDate,
30+
countTeeInTheOldDays,
3031
} from "../../../utils/StreakCounter";
3132
import Submission from "../../../interfaces/Submission";
3233
import { ProblemId } from "../../../interfaces/Status";
@@ -146,6 +147,8 @@ export const ProgressChartBlock: React.FC<Props> = (props) => {
146147
return list;
147148
}, [] as { dateSecond: number; count: number }[]);
148149

150+
const teeInTheOldDays = countTeeInTheOldDays(dailyTeeCount);
151+
149152
const dateColorCountMap = Array.from(submissionsByProblem.values())
150153
.map((submissionsOfProblem) => {
151154
const accepted = submissionsOfProblem
@@ -277,6 +280,11 @@ export const ProgressChartBlock: React.FC<Props> = (props) => {
277280
</Row>
278281
<TeeChart climbingData={teeClimbing} />
279282

283+
<Row className="my-2 border-bottom">
284+
<h1>TEE In The Old Days</h1>
285+
</Row>
286+
<TeeChart climbingData={teeInTheOldDays} />
287+
280288
<Row className="my-2 border-bottom">
281289
<h1>Heatmap</h1>
282290
</Row>

atcoder-problems-frontend/src/utils/StreakCounter.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,43 @@ export const countTeeByDate = (
111111
.map(([dateLabel, count]) => ({ dateLabel, count }))
112112
.sort((a, b) => a.dateLabel.localeCompare(b.dateLabel));
113113
};
114+
115+
export const countTeeInTheOldDays = (
116+
dailyTeeCount: {
117+
dateLabel: string;
118+
count: number;
119+
}[]
120+
) => {
121+
const DURATION = 30;
122+
123+
const minDateLabel = dailyTeeCount[0].dateLabel;
124+
const maxDateLabel = dailyTeeCount[dailyTeeCount.length - 1].dateLabel;
125+
const dateDelta =
126+
(+new Date(maxDateLabel) - +new Date(minDateLabel)) / 1000 / 86400;
127+
128+
const differentiatedTees = Array.from(Array(dateDelta)).map((__, i) => {
129+
const nextDate = new Date(minDateLabel);
130+
nextDate.setDate(nextDate.getDate() + i);
131+
const nextDateLabel = nextDate.toISOString().substring(0, 10);
132+
const found = dailyTeeCount.find((tee) => tee.dateLabel === nextDateLabel);
133+
if (found) {
134+
return found;
135+
} else {
136+
return { dateLabel: nextDateLabel, count: 0 };
137+
}
138+
});
139+
140+
return differentiatedTees
141+
.map(({ dateLabel }, i) => {
142+
const dateSecond = parseDateLabel(dateLabel).unix();
143+
const begin = Math.max(i - (DURATION - 1), 0);
144+
const total = differentiatedTees
145+
.slice(begin, i + 1)
146+
.reduce((tot, data) => data.count + tot, 0);
147+
if (!total) {
148+
return null;
149+
}
150+
return { dateSecond, count: total };
151+
})
152+
.filter((data) => !!data) as { dateSecond: number; count: number }[];
153+
};

0 commit comments

Comments
 (0)