fn process_reports(
    mut reports: Vec<DMARCAggregateReport>,
) -> std::io::Result<HashMap<i64, WeeklyRecord>> {
    trace!("Processing {:?} reports", reports.len());
    let mut report_hash: HashMap<i64, WeeklyRecord> = HashMap::new();

    // First build a hash with the week-start timestamp as the key and a WeeklyRecord as the value
    for dmarc_report in reports.drain(0..) {
        trace!(
            "Processing report with start time {:?}",
            dmarc_report.report_metadata.date_range.begin
        );
        let mut realtime =
            NaiveDateTime::from_timestamp(dmarc_report.report_metadata.date_range.begin, 0);
        realtime = realtime
            - Duration::seconds(
                ((realtime.weekday().num_days_from_monday() + 1) * 24 * 60 * 60).into(),
            );
        let starttime =
            NaiveDate::from_ymd(realtime.year(), realtime.month(), realtime.day()).and_hms(0, 0, 0);
        let start_timestamp = starttime.timestamp();

        if report_hash.contains_key(&start_timestamp) {
            trace!("report has already has key {}", &start_timestamp);
            if let Some(record) = report_hash.get_mut(&start_timestamp) {
                record.dmarc_reports.push(dmarc_report);
            }
        } else {
            trace!("first entry for key {}", &start_timestamp);
            let mut dmark_reports: Vec<DMARCAggregateReport> = Vec::new();
            dmark_reports.push(dmarc_report);
            let data_records: HashMap<String, PrintableData> = HashMap::new();
            let start_date = NaiveDateTime::from_timestamp(start_timestamp, 0).date();
            let end_date =
                NaiveDateTime::from_timestamp(start_timestamp + (6 * 24 * 60 * 60), 0).date();
            let readable_date = format!(
                "{} - {}",
                start_date.format("%a %e %B").to_string(),
                end_date.format("%a %e %B").to_string()
            );
            let record = WeeklyRecord {
                readable_date: readable_date,
                printable_data: data_records,
                dmarc_reports: dmark_reports,
            };
            report_hash.insert(start_timestamp, record);
        }
    }

    // Then walk through the hash processing each WeeklyRecord into a PrintableData
    for weekly_record in report_hash.values_mut() {
        for dmarc_report in weekly_record.dmarc_reports.iter() {
            if !weekly_record
                .printable_data
                .contains_key(&dmarc_report.report_metadata.org_name)
            {
                weekly_record.printable_data.insert(
                    String::from(&dmarc_report.report_metadata.org_name),
                    PrintableData { good: 0, bad: 0 },
                );
            }
            if let Some(printable_data) = weekly_record
                .printable_data
                .get_mut(&dmarc_report.report_metadata.org_name)
            {
                for record in dmarc_report.records.iter() {
                    if record.row.policy_evaluated.disposition == "none" {
                        printable_data.good += record.row.count;
                    } else {
                        printable_data.bad += record.row.count;
                    }
                }
            }
        }
    }

    Ok(report_hash)
}
/**
 * walk through the DMARCAggregateReport instances building up a reportable form of good and bad messages
 * in weekly time buckets for each domain found
 */
walk through the DMARCAggregateReport instances building up a reportable form of good and bad messages
in weekly time buckets for each domain found
walk through the DMARCAggregateReport instances building up a reportable form of good and bad messages in weekly time buckets for each domain found
fn process_reports(
    mut reports: Vec<DMARCAggregateReport>,
) -> std::io::Result<HashMap<i64, WeeklyRecord>> {
    trace!("Processing {:?} reports", reports.len());
    let mut report_hash: HashMap<i64, WeeklyRecord> = HashMap::new();
    // First build a hash with the week-start timestamp as the key and a WeeklyRecord as the value
    for dmarc_report in reports.drain(0..) {
        trace!(
            "Processing report with start time {:?}",
            dmarc_report.report_metadata.date_range.begin
        );
        let mut realtime =
            NaiveDateTime::from_timestamp(dmarc_report.report_metadata.date_range.begin, 0);
        realtime = realtime
            - Duration::seconds(
                ((realtime.weekday().num_days_from_monday() + 1) * 24 * 60 * 60).into(),
            );
        let starttime =
            NaiveDate::from_ymd(realtime.year(), realtime.month(), realtime.day()).and_hms(0, 0, 0);
        let start_timestamp = starttime.timestamp();
        if report_hash.contains_key(&start_timestamp) {
            trace!("report has already has key {}", &start_timestamp);
            if let Some(record) = report_hash.get_mut(&start_timestamp) {
                record.dmarc_reports.push(dmarc_report);
            }
        } else {
            trace!("first entry for key {}", &start_timestamp);
            let mut dmark_reports: Vec<DMARCAggregateReport> = Vec::new();
            dmark_reports.push(dmarc_report);
            let data_records: HashMap<String, PrintableData> = HashMap::new();
            let start_date = NaiveDateTime::from_timestamp(start_timestamp, 0).date();
            let end_date =
                NaiveDateTime::from_timestamp(start_timestamp + (6 * 24 * 60 * 60), 0).date();
            let readable_date = format!(
                "{} - {}",
                start_date.format("%a %e %B").to_string(),
                end_date.format("%a %e %B").to_string()
            );
            let record = WeeklyRecord {
                readable_date: readable_date,
                printable_data: data_records,
                dmarc_reports: dmark_reports,
            };
            report_hash.insert(start_timestamp, record);
        }
    }
    // Then walk through the hash processing each WeeklyRecord into a PrintableData
    for weekly_record in report_hash.values_mut() {
        for dmarc_report in weekly_record.dmarc_reports.iter() {
            if !weekly_record
                .printable_data
                .contains_key(&dmarc_report.report_metadata.org_name)
            {
                weekly_record.printable_data.insert(
                    String::from(&dmarc_report.report_metadata.org_name),
                    PrintableData { good: 0, bad: 0 },
                );
            }
            if let Some(printable_data) = weekly_record
                .printable_data
                .get_mut(&dmarc_report.report_metadata.org_name)
            {
                for record in dmarc_report.records.iter() {
                    if record.row.policy_evaluated.disposition == "none" {
                        printable_data.good += record.row.count;
                    } else {
                        printable_data.bad += record.row.count;
                    }
                }
            }
        }
    }
    Ok(report_hash)
}
fn process_reports ( mut reports : Vec < DMARCAggregateReport > , ) -> std :: io :: Result < HashMap < i64 , WeeklyRecord > > { trace ! ( " " reports len ( ) ) ; let mut report_hash : HashMap < i64 , WeeklyRecord > = HashMap :: new ( ) ; // First build a hash with the week-start timestamp as the key and a WeeklyRecord as the value for dmarc_report in reports . drain ( 0 .. ) { trace ! ( " " dmarc_report report_metadata date_range begin ) ; let mut realtime = NaiveDateTime :: from_timestamp ( dmarc_report . report_metadata . date_range . begin , 0 ) ; realtime = realtime - Duration :: seconds ( ( ( realtime . weekday ( ) . num_days_from_monday ( ) + 1 ) * 24 * 60 * 60 ) . into ( ) , ) ; let starttime = NaiveDate :: from_ymd ( realtime . year ( ) , realtime . month ( ) , realtime . day ( ) ) . and_hms ( 0 , 0 , 0 ) ; let start_timestamp = starttime . timestamp ( ) ; if report_hash . contains_key ( & start_timestamp ) { trace ! ( " " start_timestamp ) ; if let Some ( record ) = report_hash . get_mut ( & start_timestamp ) { record . dmarc_reports . push ( dmarc_report ) ; } } else { trace ! ( " " start_timestamp ) ; let mut dmark_reports : Vec < DMARCAggregateReport > = Vec :: new ( ) ; dmark_reports . push ( dmarc_report ) ; let data_records : HashMap < String , PrintableData > = HashMap :: new ( ) ; let start_date = NaiveDateTime :: from_timestamp ( start_timestamp , 0 ) . date ( ) ; let end_date = NaiveDateTime :: from_timestamp ( start_timestamp + ( 6 * 24 * 60 * 60 ) , 0 ) . date ( ) ; let readable_date = format ! ( " " start_date format ( " " ) to_string ( ) end_date format ( " " ) to_string ( ) ) ; let record = WeeklyRecord { readable_date : readable_date , printable_data : data_records , dmarc_reports : dmark_reports , } ; report_hash . insert ( start_timestamp , record ) ; } } // Then walk through the hash processing each WeeklyRecord into a PrintableData for weekly_record in report_hash . values_mut ( ) { for dmarc_report in weekly_record . dmarc_reports . iter ( ) { if ! weekly_record . printable_data . contains_key ( & dmarc_report . report_metadata . org_name ) { weekly_record . printable_data . insert ( String :: from ( & dmarc_report . report_metadata . org_name ) , PrintableData { good : 0 , bad : 0 } , ) ; } if let Some ( printable_data ) = weekly_record . printable_data . get_mut ( & dmarc_report . report_metadata . org_name ) { for record in dmarc_report . records . iter ( ) { if record . row . policy_evaluated . disposition == " " { printable_data . good += record . row . count ; } else { printable_data . bad += record . row . count ; } } } } } Ok ( report_hash ) }
walk through the DMARCAggregateReport instances building up a reportable form of good and bad messages
 in weekly time buckets for each domain found
walk through the DMARCAggregateReport instances building up a reportable form of good and bad messages in weekly time buckets for each domain found
reports
Vec<DMARCAggregateReport>