Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 7, 2024. It is now read-only.

Commit 69cf804

Browse files
committed
add parser for contest questions (it is actually a parser for questions in general. will refactor later)
1 parent b14ca10 commit 69cf804

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎src/cache/parser.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,36 @@ pub fn problem(problems: &mut Vec<Problem>, v: Value) -> Option<()> {
5252
Some(())
5353
}
5454

55+
// TODO: implement test for this
56+
/// graphql problem && question parser
57+
pub fn graphql_problem_and_question(v: Value) -> Option<(Problem,Question)> {
58+
let mut qn = Question::default();
59+
assert_eq!(Some(true), desc(&mut qn, v.clone()));
60+
let percent = &qn.stats.rate;
61+
let percent = percent[..percent.len()-1].parse::<f32>().ok()?;
62+
let v = v.as_object()?.get("data")?
63+
.as_object()?.get("question")?
64+
.as_object()?;
65+
Some((Problem {
66+
category: v.get("categoryTitle")?.as_str()?.to_ascii_lowercase(), // dangerous, since this is not actually the slug. But currently (May 2022) ok
67+
fid: v.get("questionFrontendId")?.as_str()?.parse().ok()?,
68+
id: v.get("questionId")?.as_str()?.parse().ok()?,
69+
level: match v.get("difficulty")?.as_str()?.chars().next()? {
70+
'E' => 1,
71+
'M' => 2,
72+
'H' => 3,
73+
_ => 0,
74+
},
75+
locked: false, // lazy
76+
name: v.get("title")?.as_str()?.to_string(),
77+
percent,
78+
slug: v.get("titleSlug")?.as_str()?.to_string(),
79+
starred: v.get("isFavor")?.as_bool()?,
80+
status: v.get("status")?.as_str().unwrap_or("Null").to_owned(),
81+
desc: serde_json::to_string(&qn).ok()?,
82+
}, qn))
83+
}
84+
5585
/// desc parser
5686
pub fn desc(q: &mut Question, v: Value) -> Option<bool> {
5787
/* None - parsing failed

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /