diff --git a/atcoder-problems-frontend/src/pages/UserPage/DifficultyPieChart/index.tsx b/atcoder-problems-frontend/src/pages/UserPage/DifficultyPieChart/index.tsx index 122820b2..84278bdc 100644 --- a/atcoder-problems-frontend/src/pages/UserPage/DifficultyPieChart/index.tsx +++ b/atcoder-problems-frontend/src/pages/UserPage/DifficultyPieChart/index.tsx @@ -1,6 +1,7 @@ import React, { useState } from "react"; import { Row, Col, Button, ButtonGroup } from "reactstrap"; import { + useProblemMap, useProblemModelMap, useUserSubmission, useContestMap, @@ -36,14 +37,26 @@ const getPieChartTitle = (ratingColor: RatingColor): string => { export const DifficultyPieChart: React.FC = (props) => { const [onlyRated, setOnlyRated] = useState(true); const contestMap = useContestMap(); + const problemMap = useProblemMap(); const problemModels = useProblemModelMap(); const colorCount = new Map(); const allSubmissions = useUserSubmission(props.userId) ?? []; - const submissions = allSubmissions.filter( - (submission) => - isRatedContest(contestMap.get(submission.contest_id), 2) || !onlyRated - ); - Array.from(problemModels?.values() ?? []).forEach((model) => { + const submissions = allSubmissions.filter((submission) => { + if (!onlyRated) { + return true; + } + if (contestMap === undefined) { + return false; + } + return isRatedContest(contestMap.get(submission.contest_id), 2); + }); + Array.from(problemModels?.keys() ?? []).forEach((problemId) => { + const problem = problemMap?.get(problemId); + const contest = contestMap?.get(problem?.contest_id); + if (onlyRated && (contest === undefined || !isRatedContest(contest, 2))) { + return; + } + const model = problemModels?.get(problemId); if (model.difficulty !== undefined) { const color = getRatingColor(model.difficulty); const curCount = colorCount.get(color) ?? 0;