fn generate_json_report(processed_data: HashMap<i64, WeeklyRecord>) -> String {
    info!("Generating json report");
    let mut report = String::from(format!(
        "{{\"report-time\":\"{}\",\"report\":[",
        Local::now().format("%+").to_string()
    ));

    let mut sorted_keys = Vec::new();
    for key in processed_data.keys() {
        sorted_keys.push(key);
    }
    sorted_keys.sort();

    let mut first_date_record = true;
    for key in sorted_keys.iter() {
        if let Some(record) = processed_data.get(&key) {
            let mut sorted_domains = Vec::new();
            for key in record.printable_data.keys() {
                sorted_domains.push(key);
            }
            sorted_domains.sort();
            if first_date_record {
                first_date_record = false;
            } else {
                report += &String::from(",")
            }
            report += &String::from(format!(
                "{{\"date-range\":\"{}\",\"domains\":[",
                record.readable_date
            ));
            let mut first_domain_record = true;
            for domain in sorted_domains.iter() {
                if let Some(printable_data) = record.printable_data.get(*domain) {
                    if first_domain_record {
                        first_domain_record = false;
                    } else {
                        report += &String::from(",")
                    }
                    report += &String::from(format!(
                        "{{\"domain\":\"{}\",\"good\":{},\"bad\":{}}}",
                        domain, printable_data.good, printable_data.bad
                    ));
                }
            }
            report += &String::from("]}");
        }
    }

    report += &String::from("]}");

    report
}
/**
 * Generate a JSON object of the report
 */
Generate a JSON object of the report
Generate a JSON object of the report
fn generate_json_report(processed_data: HashMap<i64, WeeklyRecord>) -> String {
    info!("Generating json report");
    let mut report = String::from(format!(
        "{{\"report-time\":\"{}\",\"report\":[",
        Local::now().format("%+").to_string()
    ));
    let mut sorted_keys = Vec::new();
    for key in processed_data.keys() {
        sorted_keys.push(key);
    }
    sorted_keys.sort();
    let mut first_date_record = true;
    for key in sorted_keys.iter() {
        if let Some(record) = processed_data.get(&key) {
            let mut sorted_domains = Vec::new();
            for key in record.printable_data.keys() {
                sorted_domains.push(key);
            }
            sorted_domains.sort();
            if first_date_record {
                first_date_record = false;
            } else {
                report += &String::from(",")
            }
            report += &String::from(format!(
                "{{\"date-range\":\"{}\",\"domains\":[",
                record.readable_date
            ));
            let mut first_domain_record = true;
            for domain in sorted_domains.iter() {
                if let Some(printable_data) = record.printable_data.get(*domain) {
                    if first_domain_record {
                        first_domain_record = false;
                    } else {
                        report += &String::from(",")
                    }
                    report += &String::from(format!(
                        "{{\"domain\":\"{}\",\"good\":{},\"bad\":{}}}",
                        domain, printable_data.good, printable_data.bad
                    ));
                }
            }
            report += &String::from("]}");
        }
    }
    report += &String::from("]}");
    report
}
fn generate_json_report ( processed_data : HashMap < i64 , WeeklyRecord > ) -> String { info ! ( " " ) ; let mut report = String :: from ( format ! ( " \" \" \" \" \" \" " Local now ( ) format ( " " ) to_string ( ) ) ) ; let mut sorted_keys = Vec :: new ( ) ; for key in processed_data . keys ( ) { sorted_keys . push ( key ) ; } sorted_keys . sort ( ) ; let mut first_date_record = true ; for key in sorted_keys . iter ( ) { if let Some ( record ) = processed_data . get ( & key ) { let mut sorted_domains = Vec :: new ( ) ; for key in record . printable_data . keys ( ) { sorted_domains . push ( key ) ; } sorted_domains . sort ( ) ; if first_date_record { first_date_record = false ; } else { report += & String :: from ( " " ) } report += & String :: from ( format ! ( " \" \" \" \" \" \" " record readable_date ) ) ; let mut first_domain_record = true ; for domain in sorted_domains . iter ( ) { if let Some ( printable_data ) = record . printable_data . get ( * domain ) { if first_domain_record { first_domain_record = false ; } else { report += & String :: from ( " " ) } report += & String :: from ( format ! ( " \" \" \" \" \" \" \" \" " domain printable_data good printable_data bad ) ) ; } } report += & String :: from ( " " ) ; } } report += & String :: from ( " " ) ; report }
Generate a JSON object of the report
Generate a JSON object of the report
processed_data
HashMap<i64, WeeklyRecord>