File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
atcoder-problems-frontend/src
pages/UserPage/ProgressChartBlock Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ import { useLocalStorage } from "../../../utils/LocalStorage";
27
27
import {
28
28
countUniqueAcByDate ,
29
29
countTeeByDate ,
30
- countTeeInTheOldDays ,
30
+ countTeeMovingAverage ,
31
31
} from "../../../utils/StreakCounter" ;
32
32
import Submission from "../../../interfaces/Submission" ;
33
33
import { ProblemId } from "../../../interfaces/Status" ;
@@ -147,7 +147,7 @@ export const ProgressChartBlock: React.FC<Props> = (props) => {
147
147
return list ;
148
148
} , [ ] as { dateSecond : number ; count : number } [ ] ) ;
149
149
150
- const teeInTheOldDays = countTeeInTheOldDays ( dailyTeeCount ) ;
150
+ const teeMovingAverage = countTeeMovingAverage ( dailyTeeCount ) ;
151
151
152
152
const dateColorCountMap = Array . from ( submissionsByProblem . values ( ) )
153
153
. map ( ( submissionsOfProblem ) => {
@@ -281,9 +281,9 @@ export const ProgressChartBlock: React.FC<Props> = (props) => {
281
281
< TeeChart climbingData = { teeClimbing } />
282
282
283
283
< Row className = "my-2 border-bottom" >
284
- < h1 > TEE In The Old Days </ h1 >
284
+ < h1 > TEE Moving Average (30 days) </ h1 >
285
285
</ Row >
286
- < TeeChart climbingData = { teeInTheOldDays } />
286
+ < TeeChart climbingData = { teeMovingAverage } />
287
287
288
288
< Row className = "my-2 border-bottom" >
289
289
< h1 > Heatmap</ h1 >
Original file line number Diff line number Diff line change @@ -112,18 +112,24 @@ export const countTeeByDate = (
112
112
. sort ( ( a , b ) => a . dateLabel . localeCompare ( b . dateLabel ) ) ;
113
113
} ;
114
114
115
- export const countTeeInTheOldDays = (
115
+ export const countTeeMovingAverage = (
116
116
dailyTeeCount : {
117
117
dateLabel : string ;
118
118
count : number ;
119
119
} [ ]
120
120
) => {
121
121
const DURATION = 30 ;
122
+ if ( ! Array . isArray ( dailyTeeCount ) || dailyTeeCount . length === 0 ) {
123
+ return [ ] ;
124
+ }
122
125
123
126
const minDateLabel = dailyTeeCount [ 0 ] . dateLabel ;
124
127
const maxDateLabel = dailyTeeCount [ dailyTeeCount . length - 1 ] . dateLabel ;
125
128
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 ;
127
133
128
134
const differentiatedTees = Array . from ( Array ( dateDelta ) ) . map ( ( __ , i ) => {
129
135
const nextDate = new Date ( minDateLabel ) ;
@@ -147,7 +153,7 @@ export const countTeeInTheOldDays = (
147
153
if ( ! total ) {
148
154
return null ;
149
155
}
150
- return { dateSecond, count : total } ;
156
+ return { dateSecond, count : total / DURATION } ;
151
157
} )
152
- . filter ( ( data ) => ! ! data ) as { dateSecond : number ; count : number } [ ] ;
158
+ . filter ( ( data ) : data is { dateSecond : number ; count : number } => ! ! data ) ;
153
159
} ;
You can’t perform that action at this time.
0 commit comments