pub fn build_monitor(
    runs: &[Run],
    problems: &[(ProblemId, ProblemConfig)],
    parties: &[PartyId],
    _config: &Config,
) -> Monitor {
    let mut party_info = BTreeMap::new();
    let mut runs_by_party_and_problem = BTreeMap::new();
    for (i, run) in runs.iter().enumerate() {
        let k = (run.party, run.problem);
        runs_by_party_and_problem
            .entry(k)
            .or_insert_with(Vec::new)
            .push(i);
    }
    let mut cell_by_party_and_problem = BTreeMap::new();

    let mut stats = StatsRow {
        problems: BTreeMap::new(),
    };
    for problem in problems {
        stats.problems.insert(
            problem.0,
            ProblemStats {
                total_runs: 0,
                accepted_runs: 0,
                max_score: 0,
            },
        );
    }

    for &party in parties {
        for problem in problems {
            let empty_run_ids = Vec::new();
            let run_ids = match runs_by_party_and_problem.get(&(party, problem.0)) {
                Some(ids) => ids,
                None => &empty_run_ids,
            };
            let runs = run_ids.iter().map(|&run_id| &runs[run_id]);
            let problem_stats = stats.problems.get_mut(&problem.0).unwrap();

            let cell = build_cell(runs, &problem.1, problem_stats);

            cell_by_party_and_problem.insert((party, problem.0), cell);
        }
    }
    for &party in parties {
        let stats = PartyStats { color: 0, score: 0 };
        let mut row = PartyRow {
            stats,
            problems: BTreeMap::new(),
        };
        for problem in problems {
            row.problems.insert(
                problem.0,
                cell_by_party_and_problem
                    .remove(&(party, problem.0))
                    .unwrap(),
            );
        }
        party_info.insert(party, row);
    }
    let mut mon = Monitor {
        parties: party_info,
        stats,
    };
    build_party_stats(&mut mon, parties);
    mon
}
/// Builds a `Monitor`, given list of all runs
/// # Panics
/// Panics if provided arguments are invalid
// Probably, later some means to build this incrementally will be implemented
Builds a `Monitor`, given list of all runs
Builds a ` Monitor ` given list of all runs
pub fn build_monitor(
    runs: &[Run],
    problems: &[(ProblemId, ProblemConfig)],
    parties: &[PartyId],
    _config: &Config,
) -> Monitor {
    let mut party_info = BTreeMap::new();
    let mut runs_by_party_and_problem = BTreeMap::new();
    for (i, run) in runs.iter().enumerate() {
        let k = (run.party, run.problem);
        runs_by_party_and_problem
            .entry(k)
            .or_insert_with(Vec::new)
            .push(i);
    }
    let mut cell_by_party_and_problem = BTreeMap::new();
    let mut stats = StatsRow {
        problems: BTreeMap::new(),
    };
    for problem in problems {
        stats.problems.insert(
            problem.0,
            ProblemStats {
                total_runs: 0,
                accepted_runs: 0,
                max_score: 0,
            },
        );
    }
    for &party in parties {
        for problem in problems {
            let empty_run_ids = Vec::new();
            let run_ids = match runs_by_party_and_problem.get(&(party, problem.0)) {
                Some(ids) => ids,
                None => &empty_run_ids,
            };
            let runs = run_ids.iter().map(|&run_id| &runs[run_id]);
            let problem_stats = stats.problems.get_mut(&problem.0).unwrap();
            let cell = build_cell(runs, &problem.1, problem_stats);
            cell_by_party_and_problem.insert((party, problem.0), cell);
        }
    }
    for &party in parties {
        let stats = PartyStats { color: 0, score: 0 };
        let mut row = PartyRow {
            stats,
            problems: BTreeMap::new(),
        };
        for problem in problems {
            row.problems.insert(
                problem.0,
                cell_by_party_and_problem
                    .remove(&(party, problem.0))
                    .unwrap(),
            );
        }
        party_info.insert(party, row);
    }
    let mut mon = Monitor {
        parties: party_info,
        stats,
    };
    build_party_stats(&mut mon, parties);
    mon
}
pub fn build_monitor ( runs : & [ Run ] , problems : & [ ( ProblemId , ProblemConfig ) ] , parties : & [ PartyId ] , _config : & Config , ) -> Monitor { let mut party_info = BTreeMap :: new ( ) ; let mut runs_by_party_and_problem = BTreeMap :: new ( ) ; for ( i , run ) in runs . iter ( ) . enumerate ( ) { let k = ( run . party , run . problem ) ; runs_by_party_and_problem . entry ( k ) . or_insert_with ( Vec :: new ) . push ( i ) ; } let mut cell_by_party_and_problem = BTreeMap :: new ( ) ; let mut stats = StatsRow { problems : BTreeMap :: new ( ) , } ; for problem in problems { stats . problems . insert ( problem . 0 , ProblemStats { total_runs : 0 , accepted_runs : 0 , max_score : 0 , } , ) ; } for & party in parties { for problem in problems { let empty_run_ids = Vec :: new ( ) ; let run_ids = match runs_by_party_and_problem . get ( & ( party , problem . 0 ) ) { Some ( ids ) => ids , None => & empty_run_ids , } ; let runs = run_ids . iter ( ) . map ( | & run_id | & runs [ run_id ] ) ; let problem_stats = stats . problems . get_mut ( & problem . 0 ) . unwrap ( ) ; let cell = build_cell ( runs , & problem . 1 , problem_stats ) ; cell_by_party_and_problem . insert ( ( party , problem . 0 ) , cell ) ; } } for & party in parties { let stats = PartyStats { color : 0 , score : 0 } ; let mut row = PartyRow { stats , problems : BTreeMap :: new ( ) , } ; for problem in problems { row . problems . insert ( problem . 0 , cell_by_party_and_problem . remove ( & ( party , problem . 0 ) ) . unwrap ( ) , ) ; } party_info . insert ( party , row ) ; } let mut mon = Monitor { parties : party_info , stats , } ; build_party_stats ( & mut mon , parties ) ; mon }
Builds a `Monitor`, given list of all runs
Builds a ` Monitor ` given list of all runs
runs
&[Run]
problems
&[(ProblemId, ProblemConfig)]
parties
&[PartyId]
_config
&Config
panics
Panics if provided arguments are invalid
Probably, later some means to build this incrementally will be implemented
Panics if provided arguments are invalid Probably later some means to build this incrementally will be implemented