fn report(activities: &[Activity], categories: &CategoryLookup) -> String {
    let mut by_category = HashMap::new();
    let mut individual: HashMap<String, Vec<u32>> = HashMap::new();
    let total = common::weighted_total(activities, categories);

    for activity in activities {
        let cat = &activity.category;

        if by_category.contains_key(cat) {
            let parts = individual.get_mut(cat).unwrap();
            parts.push(activity.reps);
            let sum = by_category.get(cat).unwrap() + activity.reps;
            by_category.insert(cat.to_string(), sum);
        } else {
            let mut parts = Vec::new();
            parts.push(activity.reps);
            individual.insert(cat.to_string(), parts);

            by_category.insert(cat.to_string(), activity.reps);
        };
    }

    let mut result = String::new();

    result.push_str("Stats for today:\n");
    for category in by_category.keys().sorted() {
        let reps = by_category.get(category).unwrap();

        let details = if individual.get(category).unwrap().len() > 1 {
            format!(
                " ({})",
                individual.get(category).unwrap().iter().join(" + ")
            )
        } else {
            "".to_string()
        };

        result.push_str(&format!("  {:<15}: {} reps{}\n", category, reps, details));
    }

    if by_category.len() > 1 {
        result.push_str(&format!("  Weighted total : {}", total));
    }

    result
}
/// Generate the report for today as string
Generate the report for today as string
Generate the report for today as string
fn report(activities: &[Activity], categories: &CategoryLookup) -> String {
    let mut by_category = HashMap::new();
    let mut individual: HashMap<String, Vec<u32>> = HashMap::new();
    let total = common::weighted_total(activities, categories);
    for activity in activities {
        let cat = &activity.category;
        if by_category.contains_key(cat) {
            let parts = individual.get_mut(cat).unwrap();
            parts.push(activity.reps);
            let sum = by_category.get(cat).unwrap() + activity.reps;
            by_category.insert(cat.to_string(), sum);
        } else {
            let mut parts = Vec::new();
            parts.push(activity.reps);
            individual.insert(cat.to_string(), parts);
            by_category.insert(cat.to_string(), activity.reps);
        };
    }
    let mut result = String::new();
    result.push_str("Stats for today:\n");
    for category in by_category.keys().sorted() {
        let reps = by_category.get(category).unwrap();
        let details = if individual.get(category).unwrap().len() > 1 {
            format!(
                " ({})",
                individual.get(category).unwrap().iter().join(" + ")
            )
        } else {
            "".to_string()
        };
        result.push_str(&format!("  {:<15}: {} reps{}\n", category, reps, details));
    }
    if by_category.len() > 1 {
        result.push_str(&format!("  Weighted total : {}", total));
    }
    result
}
fn report ( activities : & [ Activity ] , categories : & CategoryLookup ) -> String { let mut by_category = HashMap :: new ( ) ; let mut individual : HashMap < String , Vec < u32 > > = HashMap :: new ( ) ; let total = common :: weighted_total ( activities , categories ) ; for activity in activities { let cat = & activity . category ; if by_category . contains_key ( cat ) { let parts = individual . get_mut ( cat ) . unwrap ( ) ; parts . push ( activity . reps ) ; let sum = by_category . get ( cat ) . unwrap ( ) + activity . reps ; by_category . insert ( cat . to_string ( ) , sum ) ; } else { let mut parts = Vec :: new ( ) ; parts . push ( activity . reps ) ; individual . insert ( cat . to_string ( ) , parts ) ; by_category . insert ( cat . to_string ( ) , activity . reps ) ; } ; } let mut result = String :: new ( ) ; result . push_str ( " \n " ) ; for category in by_category . keys ( ) . sorted ( ) { let reps = by_category . get ( category ) . unwrap ( ) ; let details = if individual . get ( category ) . unwrap ( ) . len ( ) > 1 { format ! ( " " individual get ( category ) unwrap ( ) iter ( ) join ( " " ) ) } else { " " . to_string ( ) } ; result . push_str ( & format ! ( " \n " category reps details ) ) ; } if by_category . len ( ) > 1 { result . push_str ( & format ! ( " " total ) ) ; } result }
Generate the report for today as string
Generate the report for today as string
activities
&[Activity]
categories
&CategoryLookup