|
2 | 2 | use super::models::*;
|
3 | 3 | use serde_json::Value;
|
4 | 4 |
|
| 5 | +/// contest parser |
| 6 | +pub fn contest(v: Value) -> Option<Contest> { |
| 7 | + let o = v.as_object()?; |
| 8 | + let contest = o.get("contest")?.as_object()?; |
| 9 | + let questions: Vec<ContestQuestionStub> = o |
| 10 | + .get("questions")?.as_array()? |
| 11 | + .into_iter().map(|q| { |
| 12 | + let stub: Result<ContestQuestionStub, _> = serde_json::from_value(q.clone()); |
| 13 | + stub.unwrap() |
| 14 | + }).collect(); |
| 15 | + Some(Contest { |
| 16 | + id: contest.get("id")?.as_i64()? as i32, |
| 17 | + duration: contest.get("duration")?.as_i64()? as i32, |
| 18 | + start_time: contest.get("start_time")?.as_i64()?, |
| 19 | + title: contest.get("title")?.as_str()?.to_string(), |
| 20 | + title_slug: contest.get("title_slug")?.as_str()?.to_owned(), |
| 21 | + description: "".to_owned(), // TODO: display description. contest.get("description")?.as_str()?.to_owned(), |
| 22 | + is_virtual: contest.get("is_virtual")?.as_bool()?, |
| 23 | + contains_premium: o.get("containsPremium")?.as_bool()?, |
| 24 | + registered: o.get("registered")?.as_bool()?, |
| 25 | + questions |
| 26 | + }) |
| 27 | +} |
| 28 | + |
5 | 29 | /// problem parser
|
6 | 30 | pub fn problem(problems: &mut Vec<Problem>, v: Value) -> Option<()> {
|
7 | 31 | let pairs = v.get("stat_status_pairs")?.as_array()?;
|
|
0 commit comments