forked from kenkoooo/AtCoderProblems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDifficultyCircle.tsx
More file actions
121 lines (117 loc) · 3.19 KB
/
DifficultyCircle.tsx
File metadata and controls
121 lines (117 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import React, { useState } from "react";
import { Badge, Tooltip } from "reactstrap";
import { getRatingColor } from "../utils";
import ProblemModel, {
isProblemModelWithDifficultyModel,
isProblemModelWithTimeModel,
ProblemModelWithDifficultyModel,
} from "../interfaces/ProblemModel";
import {
predictSolveProbability,
predictSolveTime,
formatPredictedSolveProbability,
formatPredictedSolveTime,
} from "../utils/ProblemModelUtil";
import { RatingInfo } from "../utils/RatingInfo";
import { TopcoderLikeCircle } from "./TopcoderLikeCircle";
interface Props {
id: string;
problemModel?: ProblemModel | null;
userRatingInfo?: RatingInfo | null;
}
function getColor(difficulty: number) {
if (difficulty < 3200) {
return getRatingColor(difficulty);
} else if (difficulty < 3600) {
return "Bronze";
} else if (difficulty < 4000) {
return "Silver";
} else {
return "Gold";
}
}
export const DifficultyCircle: React.FC<Props> = (props) => {
const { id, problemModel, userRatingInfo } = props;
const difficulty = problemModel?.difficulty;
const [tooltipOpen, setTooltipOpen] = useState(false);
const toggleTooltipState = (): void => setTooltipOpen(!tooltipOpen);
const circleId = "DifficultyCircle-" + id;
if (difficulty === undefined) {
return (
<span>
<Badge
className="difficulty-unavailable-circle"
color="info"
id={circleId}
pill
>
?
</Badge>
<Tooltip
placement="top"
target={circleId}
isOpen={tooltipOpen}
toggle={toggleTooltipState}
>
Difficulty is unavailable.
</Tooltip>
</span>
);
}
const color = getColor(difficulty);
const predictProbability: string =
problemModel === undefined
? "-"
: userRatingInfo?.internalRating === undefined ||
userRatingInfo?.internalRating === null
? "-"
: isProblemModelWithDifficultyModel(problemModel) === false
? "-"
: formatPredictedSolveProbability(
predictSolveProbability(
problemModel as ProblemModelWithDifficultyModel,
userRatingInfo.internalRating
)
);
const predictTime =
problemModel === undefined
? "-"
: userRatingInfo?.internalRating === undefined ||
userRatingInfo?.internalRating === null
? "-"
: isProblemModelWithTimeModel(problemModel) === false
? "-"
: formatPredictedSolveTime(
predictSolveTime(problemModel, userRatingInfo.internalRating)
);
const contentDifficulty = `Difficulty: ${difficulty}`;
const contentProbability = `Solve Prob: ${predictProbability}`;
const contentTime = `Solve Time: ${predictTime}`;
const content = (
<>
{contentDifficulty}
<br />
{contentProbability}
<br />
{contentTime}
</>
);
return (
<>
<TopcoderLikeCircle
color={color}
rating={difficulty}
className="difficulty-circle"
id={circleId}
/>
<Tooltip
placement="top"
target={circleId}
isOpen={tooltipOpen}
toggle={toggleTooltipState}
>
{content}
</Tooltip>
</>
);
};