@@ -52,6 +52,36 @@ pub fn problem(problems: &mut Vec<Problem>, v: Value) -> Option<()> {
52
52
Some ( ( ) )
53
53
}
54
54
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
+
55
85
/// desc parser
56
86
pub fn desc ( q : & mut Question , v : Value ) -> Option < bool > {
57
87
/* None - parsing failed
0 commit comments