Skip to content

Commit d386937

Browse files
committed
fix: fix by comment. Changed feature: moving total -> moving average / fixed bugs and some styles.
1 parent 9e130d5 commit d386937

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { useLocalStorage } from "../../../utils/LocalStorage";
2727
import {
2828
countUniqueAcByDate,
2929
countTeeByDate,
30-
countTeeInTheOldDays,
30+
countTeeMovingAverage,
3131
} from "../../../utils/StreakCounter";
3232
import Submission from "../../../interfaces/Submission";
3333
import { ProblemId } from "../../../interfaces/Status";
@@ -147,7 +147,7 @@ export const ProgressChartBlock: React.FC<Props> = (props) => {
147147
return list;
148148
}, [] as { dateSecond: number; count: number }[]);
149149

150-
const teeInTheOldDays = countTeeInTheOldDays(dailyTeeCount);
150+
const teeMovingAverage = countTeeMovingAverage(dailyTeeCount);
151151

152152
const dateColorCountMap = Array.from(submissionsByProblem.values())
153153
.map((submissionsOfProblem) => {
@@ -281,9 +281,9 @@ export const ProgressChartBlock: React.FC<Props> = (props) => {
281281
<TeeChart climbingData={teeClimbing} />
282282

283283
<Row className="my-2 border-bottom">
284-
<h1>TEE In The Old Days</h1>
284+
<h1>TEE Moving Average (30 days)</h1>
285285
</Row>
286-
<TeeChart climbingData={teeInTheOldDays} />
286+
<TeeChart climbingData={teeMovingAverage} />
287287

288288
<Row className="my-2 border-bottom">
289289
<h1>Heatmap</h1>

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,24 @@ export const countTeeByDate = (
112112
.sort((a, b) => a.dateLabel.localeCompare(b.dateLabel));
113113
};
114114

115-
export const countTeeInTheOldDays = (
115+
export const countTeeMovingAverage = (
116116
dailyTeeCount: {
117117
dateLabel: string;
118118
count: number;
119119
}[]
120120
) => {
121121
const DURATION = 30;
122+
if (!Array.isArray(dailyTeeCount) || dailyTeeCount.length === 0) {
123+
return [];
124+
}
122125

123126
const minDateLabel = dailyTeeCount[0].dateLabel;
124127
const maxDateLabel = dailyTeeCount[dailyTeeCount.length - 1].dateLabel;
125128
const dateDelta =
126-
(+new Date(maxDateLabel) - +new Date(minDateLabel)) / 1000 / 86400;
129+
1 +
130+
(new Date(maxDateLabel).getTime() - new Date(minDateLabel).getTime()) /
131+
1000 /
132+
86400;
127133

128134
const differentiatedTees = Array.from(Array(dateDelta)).map((__, i) => {
129135
const nextDate = new Date(minDateLabel);
@@ -147,7 +153,7 @@ export const countTeeInTheOldDays = (
147153
if (!total) {
148154
return null;
149155
}
150-
return { dateSecond, count: total };
156+
return { dateSecond, count: total / DURATION };
151157
})
152-
.filter((data) => !!data) as { dateSecond: number; count: number }[];
158+
.filter((data): data is { dateSecond: number; count: number } => !!data);
153159
};

0 commit comments

Comments
 (0)