From 951f72af2a94448759590ec4c8d0ff9405a07788 Mon Sep 17 00:00:00 2001 From: cleantted Date: Fri, 20 Oct 2023 15:38:08 +0900 Subject: [PATCH 1/2] Extract only rated problems from whole problems --- .../src/pages/UserPage/DifficultyPieChart/index.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/atcoder-problems-frontend/src/pages/UserPage/DifficultyPieChart/index.tsx b/atcoder-problems-frontend/src/pages/UserPage/DifficultyPieChart/index.tsx index 122820b2..c5ab1ffc 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,6 +37,7 @@ 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) ?? []; @@ -43,7 +45,13 @@ export const DifficultyPieChart: React.FC = (props) => { (submission) => isRatedContest(contestMap.get(submission.contest_id), 2) || !onlyRated ); - Array.from(problemModels?.values() ?? []).forEach((model) => { + 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; From 8d2f76f77743827ca8b11ebed26c65145befdbf7 Mon Sep 17 00:00:00 2001 From: cleantted Date: Fri, 20 Oct 2023 15:50:57 +0900 Subject: [PATCH 2/2] Undefined-check contestMap --- .../src/pages/UserPage/DifficultyPieChart/index.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/atcoder-problems-frontend/src/pages/UserPage/DifficultyPieChart/index.tsx b/atcoder-problems-frontend/src/pages/UserPage/DifficultyPieChart/index.tsx index c5ab1ffc..84278bdc 100644 --- a/atcoder-problems-frontend/src/pages/UserPage/DifficultyPieChart/index.tsx +++ b/atcoder-problems-frontend/src/pages/UserPage/DifficultyPieChart/index.tsx @@ -41,10 +41,15 @@ export const DifficultyPieChart: React.FC = (props) => { 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 - ); + 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);