Skip to content

Commit

Permalink
round point status's points by 100
Browse files Browse the repository at this point in the history
  • Loading branch information
CoCo-Japan-pan committed Sep 3, 2024
1 parent 5737038 commit 684c72e
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions atcoder-problems-frontend/src/pages/ListPage/SmallTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,60 @@ export const SmallTable: React.FC<Props> = ({ submissions, setFilterFunc }) => {
useMergedProblemMap().data ?? new Map<ProblemId, MergedProblem>();
const userPointCountMap = getUserPointCounts(mergedProblemMap, submissions);
const totalCount = getTotalCount(mergedProblemMap);
const totalCountBy100 = totalCount.reduce(
(
ret: { point: number; count: number }[],
current: { point: number; count: number }
) => {
const roundedPoint = Math.floor(current.point / 100) * 100;
const prev = ret.find((entry) => entry.point === roundedPoint);
if (prev) {
prev.count += current.count;
} else {
ret.push({ point: roundedPoint, count: current.count });
}
return ret;
},
[]
);

const getUserPointCountInArea = (
countByPoint: Map<number | null | undefined, number>,
pointStart: number,
pointEnd: number
) => {
let ret = 0;
for (let i = 0; i < totalCount.length; i++) {
if (totalCount[i].point < pointStart) {
continue;
}
if (totalCount[i].point >= pointEnd) {
break;
}
ret += countByPoint.get(totalCount[i].point) ?? 0;
}
return ret;
};

return (
<Table striped bordered hover responsive>
<thead>
<tr>
<th>Point</th>
{totalCount.map(({ point }) => (
{totalCountBy100.map(({ point }) => (
<th key={point}>
<a
href={window.location.hash}
onClick={(): void => setFilterFunc(point)}
>
{point}
{`${point}-`}
</a>
</th>
))}
</tr>
<tr>
<th>Total</th>
{totalCount.map(({ point, count }) => (
{totalCountBy100.map(({ point, count }) => (
<th key={point}>{count}</th>
))}
</tr>
Expand All @@ -78,16 +113,17 @@ export const SmallTable: React.FC<Props> = ({ submissions, setFilterFunc }) => {
{userPointCountMap.map(({ userId, countByPoint }) => (
<tr key={userId}>
<td>{userId}</td>
{totalCount.map(({ point, count }) => (
{totalCountBy100.map(({ point, count }) => (
<td
key={point}
className={
countByPoint.get(point) === count
getUserPointCountInArea(countByPoint, point, point + 100) ===
count
? TableColor.Success
: TableColor.None
}
>
{countByPoint.get(point) ?? 0}
{getUserPointCountInArea(countByPoint, point, point + 100) ?? 0}
</td>
))}
</tr>
Expand Down

0 comments on commit 684c72e

Please sign in to comment.