1- import { Col , Row } from "reactstrap" ;
2- import React from "react" ;
1+ import { Col , Row , Button , ButtonGroup } from "reactstrap" ;
2+ import React , { useState } from "react" ;
33import {
44 useContestToProblems ,
55 useUserSubmission ,
6+ useContestMap ,
67} from "../../../api/APIClient" ;
78import Problem from "../../../interfaces/Problem" ;
89import Submission from "../../../interfaces/Submission" ;
@@ -12,6 +13,7 @@ import {
1213 isAccepted ,
1314 isValidResult ,
1415} from "../../../utils" ;
16+ import { isRatedContest } from "../../../utils/ContestClassifier" ;
1517import { SmallPieChart } from "./SmallPieChart" ;
1618
1719enum SubmissionStatus {
@@ -143,18 +145,26 @@ export const PieChartBlock = (props: Props) => {
143145 ) ;
144146 const contestToProblems =
145147 useContestToProblems ( ) ?? new Map < ContestId , Problem [ ] > ( ) ;
148+ const [ onlyRated , setOnlyRated ] = useState ( true ) ;
149+ const contestMap = useContestMap ( ) ;
146150
147151 const abcSolved = solvedCountForPieChart (
148- Array . from ( contestToProblems ) . filter ( ( [ contestId ] ) =>
149- contestId . startsWith ( "abc" )
150- ) ,
152+ Array . from ( contestToProblems )
153+ . filter ( ( [ contestId ] ) => contestId . startsWith ( "abc" ) )
154+ . filter (
155+ ( [ contestId ] ) =>
156+ isRatedContest ( contestMap . get ( contestId ) , 2 ) || ! onlyRated
157+ ) ,
151158 submissionsMap ,
152159 props . userId
153160 ) ;
154161 const arcSolved = solvedCountForPieChart (
155- Array . from ( contestToProblems ) . filter ( ( [ contestId ] ) =>
156- contestId . startsWith ( "arc" )
157- ) ,
162+ Array . from ( contestToProblems )
163+ . filter ( ( [ contestId ] ) => contestId . startsWith ( "arc" ) )
164+ . filter (
165+ ( [ contestId ] ) =>
166+ isRatedContest ( contestMap . get ( contestId ) , 2 ) || ! onlyRated
167+ ) ,
158168 submissionsMap ,
159169 props . userId
160170 ) ;
@@ -167,23 +177,50 @@ export const PieChartBlock = (props: Props) => {
167177 ) ;
168178 return (
169179 < >
170- < PieCharts problems = { abcSolved } title = "AtCoder Beginner Contest" />
171- < PieCharts problems = { arcSolved } title = "AtCoder Regular Contest" />
172- < PieCharts problems = { agcSolved } title = "AtCoder Grand Contest" />
180+ < PieCharts
181+ problems = { abcSolved }
182+ title = "AtCoder Beginner Contest"
183+ setOnlyRated = { setOnlyRated }
184+ onlyRated = { onlyRated }
185+ />
186+ < PieCharts
187+ problems = { arcSolved }
188+ title = "AtCoder Regular Contest"
189+ setOnlyRated = { setOnlyRated }
190+ onlyRated = { onlyRated }
191+ />
192+ < PieCharts
193+ problems = { agcSolved }
194+ title = "AtCoder Grand Contest"
195+ setOnlyRated = { setOnlyRated }
196+ onlyRated = { onlyRated }
197+ />
173198 </ >
174199 ) ;
175200} ;
176201
177202interface PieChartsProps {
178203 problems : { total : number ; solved : number ; rejected : number } [ ] ;
179204 title : string ;
205+ setOnlyRated : ( onlyRated : boolean ) => void ;
206+ onlyRated : boolean ;
180207}
181208
182- const PieCharts : React . FC < PieChartsProps > = ( { problems, title } ) => (
209+ const PieCharts : React . FC < PieChartsProps > = ( {
210+ problems,
211+ title,
212+ setOnlyRated,
213+ onlyRated,
214+ } ) => (
183215 < div >
184216 < Row className = "my-2 border-bottom" >
185217 < h1 > { title } </ h1 >
186218 </ Row >
219+ < ButtonGroup className = "mb-2" >
220+ < Button onClick = { ( ) : void => setOnlyRated ( ! onlyRated ) } >
221+ { onlyRated ? "Only Rated Contests" : "All Contests" }
222+ </ Button >
223+ </ ButtonGroup >
187224 < Row className = "my-3" >
188225 { problems . map ( ( { solved, rejected, total } , i ) => {
189226 const key = i <= 6 ? "ABCDEFG" . charAt ( i ) : "H/Ex" ;
0 commit comments