Skip to content

Commit 3563264

Browse files
round point status's points by 100
1 parent 5737038 commit 3563264

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

atcoder-problems-frontend/src/pages/ListPage/SmallTable.tsx

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,60 @@ export const SmallTable: React.FC<Props> = ({ submissions, setFilterFunc }) => {
5151
useMergedProblemMap().data ?? new Map<ProblemId, MergedProblem>();
5252
const userPointCountMap = getUserPointCounts(mergedProblemMap, submissions);
5353
const totalCount = getTotalCount(mergedProblemMap);
54+
const totalCountBy100 = totalCount.reduce(
55+
(
56+
ret: { point: number; count: number }[],
57+
current: { point: number; count: number }
58+
) => {
59+
const roundedPoint = Math.floor(current.point / 100) * 100;
60+
const prev = ret.find((entry) => entry.point === roundedPoint);
61+
if (prev) {
62+
prev.count += current.count;
63+
} else {
64+
ret.push({ point: roundedPoint, count: current.count });
65+
}
66+
return ret;
67+
},
68+
[]
69+
);
70+
71+
const getUserPointCountInArea = (
72+
countByPoint: Map<number | null | undefined, number>,
73+
pointStart: number,
74+
pointEnd: number
75+
) => {
76+
let ret = 0;
77+
for (let i = 0; i < totalCount.length; i++) {
78+
if (totalCount[i].point < pointStart) {
79+
continue;
80+
}
81+
if (totalCount[i].point >= pointEnd) {
82+
break;
83+
}
84+
ret += countByPoint.get(totalCount[i].point) ?? 0;
85+
}
86+
return ret;
87+
};
88+
5489
return (
5590
<Table striped bordered hover responsive>
5691
<thead>
5792
<tr>
5893
<th>Point</th>
59-
{totalCount.map(({ point }) => (
94+
{totalCountBy100.map(({ point }) => (
6095
<th key={point}>
6196
<a
6297
href={window.location.hash}
6398
onClick={(): void => setFilterFunc(point)}
6499
>
65-
{point}
100+
{`${point}-`}
66101
</a>
67102
</th>
68103
))}
69104
</tr>
70105
<tr>
71106
<th>Total</th>
72-
{totalCount.map(({ point, count }) => (
107+
{totalCountBy100.map(({ point, count }) => (
73108
<th key={point}>{count}</th>
74109
))}
75110
</tr>
@@ -78,16 +113,17 @@ export const SmallTable: React.FC<Props> = ({ submissions, setFilterFunc }) => {
78113
{userPointCountMap.map(({ userId, countByPoint }) => (
79114
<tr key={userId}>
80115
<td>{userId}</td>
81-
{totalCount.map(({ point, count }) => (
116+
{totalCountBy100.map(({ point, count }) => (
82117
<td
83118
key={point}
84119
className={
85-
countByPoint.get(point) === count
120+
getUserPointCountInArea(countByPoint, point, point + 100) ===
121+
count
86122
? TableColor.Success
87123
: TableColor.None
88124
}
89125
>
90-
{countByPoint.get(point) ?? 0}
126+
{getUserPointCountInArea(countByPoint, point, point + 100) ?? 0}
91127
</td>
92128
))}
93129
</tr>

0 commit comments

Comments
 (0)