pub fn stats_response(stats: Arc<ServerStats>, resources: Arc<HashMap<String, String>>) -> Result<Response, Response> {
    let results = stats.request_results.lock().unwrap();

    let request_successes: Vec<bool> = results.iter().map(|result| result.is_successful()).collect();

    let mut path_counts: HashMap<String, PathCount> = HashMap::new();
    &results.iter().for_each(|result| {
        let resource = (&result.requested_resource).to_string();
        path_counts.entry(resource.to_string()).or_insert(PathCount{path: resource.to_string(), num_requested: 0}).increase_num();
    });

    let result_view = ResultView{request_successes, path_counts};

    let html = build_html(resources, results, result_view);

    let mut response = Response::default_ok();
    &response.add_content_type("_.html".to_string());
    response.body = html.as_bytes().to_vec();

    Ok(response)
}
/// Endpoint returns the accumulated stats about the server via html file
Endpoint returns the accumulated stats about the server via html file
Endpoint returns the accumulated stats about the server via html file
pub fn stats_response(stats: Arc<ServerStats>, resources: Arc<HashMap<String, String>>) -> Result<Response, Response> {
    let results = stats.request_results.lock().unwrap();
    let request_successes: Vec<bool> = results.iter().map(|result| result.is_successful()).collect();
    let mut path_counts: HashMap<String, PathCount> = HashMap::new();
    &results.iter().for_each(|result| {
        let resource = (&result.requested_resource).to_string();
        path_counts.entry(resource.to_string()).or_insert(PathCount{path: resource.to_string(), num_requested: 0}).increase_num();
    });
    let result_view = ResultView{request_successes, path_counts};
    let html = build_html(resources, results, result_view);
    let mut response = Response::default_ok();
    &response.add_content_type("_.html".to_string());
    response.body = html.as_bytes().to_vec();
    Ok(response)
}
pub fn stats_response ( stats : Arc < ServerStats > , resources : Arc < HashMap < String , String > > ) -> Result < Response , Response > { let results = stats . request_results . lock ( ) . unwrap ( ) ; let request_successes : Vec < bool > = results . iter ( ) . map ( | result | result . is_successful ( ) ) . collect ( ) ; let mut path_counts : HashMap < String , PathCount > = HashMap :: new ( ) ; & results . iter ( ) . for_each ( | result | { let resource = ( & result . requested_resource ) . to_string ( ) ; path_counts . entry ( resource . to_string ( ) ) . or_insert ( PathCount { path : resource . to_string ( ) , num_requested : 0 } ) . increase_num ( ) ; } ) ; let result_view = ResultView { request_successes , path_counts } ; let html = build_html ( resources , results , result_view ) ; let mut response = Response :: default_ok ( ) ; & response . add_content_type ( " " . to_string ( ) ) ; response . body = html . as_bytes ( ) . to_vec ( ) ; Ok ( response ) }
Endpoint returns the accumulated stats about the server via html file
Endpoint returns the accumulated stats about the server via html file
stats
Arc<ServerStats>
resources
Arc<HashMap<String, String>>
stats
Arc<ServerStats>
resources
Arc<HashMap<String, String>>