#cms #training #competitive-programming #api-bindings #cmsocial #olinfo

cms_tools

A rust crate for interacting with the CMSocial competitive programming platform

1 unstable release

0.1.0 Nov 9, 2019

#19 in #cms

24 downloads per month

MIT license

35KB
737 lines

cms_tools

A rust crate for interacting with the CMSocial competitive programming platform

License

Licensed under


lib.rs:

Examples:

  • Print list of people with highest number of fastest solutions
//make a client
let client = Client::new(String::from("Gemmady"));
let task_list = client.get_task_list(0, 1024, "", None, None).unwrap();
let mut hm = std::collections::HashMap::<String, u32>::new();
for i in task_list.tasks {
    let best = client.get_stats(&i.name).unwrap().best;
    if best.len() > 0 {
        let t = hm.entry(best[0].username.clone()).or_insert(0);
        *t += 1;
    }
}
let mut v: Vec<(u32, String)> = hm.iter().map(|x| (*x.1, x.0.clone())).collect();
v.sort();
for i in v.iter().rev() {
    println!("{} {}", i.1, i.0);
}
  • Resubmit all fastest solutions
let username = String::from("user");
let password = "password";
let mut client = Client::new(username.clone());
client.login(password).unwrap();
let user = client.get_user(&username).unwrap();
for sc in user.scores.unwrap() {
    if sc.score == 100.0 {
        println!("{} has score 100", sc.title);
        let sub_list = client.get_submission_list(&sc.name).unwrap();
        let best_sub = sub_list.get_fastest_high(&client).unwrap();
        let files = &best_sub.files;
        if files.len() == 1 { // if it is not an output-only
            let mut submitted: bool = false;
            print!("Resubmitting {}", sc.name.clone());
            while !submitted { // because cmsocial has a limit to submission rate
                print!(".");
                if client
                    .submit_normal(
                        &sc.name,
                        &client.get_file(&files[0]).unwrap(),
                        files[0].name.split(".").collect::<Vec<&str>>().last().unwrap(),
                    )
                    .is_ok()
                {
                    submitted = true;
                }
            }
            println!("");
        }
    }
}

Not implemented yet:

Dependencies

~22MB
~453K SLoC