fn build_html(resources: Arc<HashMap<String, String>>, results: MutexGuard<Vec<RequestResult>>, result_view: ResultView) -> String {
    let mut html = resources.get("/stats.html").unwrap().to_string();

    html = html.replace("{{num_total}}", &result_view.num_total().to_string());
    html = html.replace("{{num_successful}}", &result_view.num_successful().to_string());
    html = html.replace("{{num_unsuccessful}}", &result_view.num_unsuccessful().to_string());

    let table_entry = resources.get("/stats_table_entry.html").unwrap().to_string();
    let mut table_entries = String::new();

    results.iter().for_each(|result| {
        let mut entry = table_entry.to_string();
        entry = entry.replace("{{Time}}", &result.time.to_string());
        entry = entry.replace("{{Path}}", &result.requested_resource);
        entry = entry.replace("{{Code}}", &result.response_code.to_string());
        entry = entry.replace("{{Duration}}", &result.duration.to_string());
        table_entries = format!("{}\n{}", table_entries, entry);
    });

    html = html.replace("{{result_entries}}", &table_entries);

    html
}
/// Builds the html file to display the stats dynamically
Builds the html file to display the stats dynamically
Builds the html file to display the stats dynamically
fn build_html(resources: Arc<HashMap<String, String>>, results: MutexGuard<Vec<RequestResult>>, result_view: ResultView) -> String {
    let mut html = resources.get("/stats.html").unwrap().to_string();
    html = html.replace("{{num_total}}", &result_view.num_total().to_string());
    html = html.replace("{{num_successful}}", &result_view.num_successful().to_string());
    html = html.replace("{{num_unsuccessful}}", &result_view.num_unsuccessful().to_string());
    let table_entry = resources.get("/stats_table_entry.html").unwrap().to_string();
    let mut table_entries = String::new();
    results.iter().for_each(|result| {
        let mut entry = table_entry.to_string();
        entry = entry.replace("{{Time}}", &result.time.to_string());
        entry = entry.replace("{{Path}}", &result.requested_resource);
        entry = entry.replace("{{Code}}", &result.response_code.to_string());
        entry = entry.replace("{{Duration}}", &result.duration.to_string());
        table_entries = format!("{}\n{}", table_entries, entry);
    });
    html = html.replace("{{result_entries}}", &table_entries);
    html
}
fn build_html ( resources : Arc < HashMap < String , String > > , results : MutexGuard < Vec < RequestResult > > , result_view : ResultView ) -> String { let mut html = resources . get ( " " ) . unwrap ( ) . to_string ( ) ; html = html . replace ( " " , & result_view . num_total ( ) . to_string ( ) ) ; html = html . replace ( " " , & result_view . num_successful ( ) . to_string ( ) ) ; html = html . replace ( " " , & result_view . num_unsuccessful ( ) . to_string ( ) ) ; let table_entry = resources . get ( " " ) . unwrap ( ) . to_string ( ) ; let mut table_entries = String :: new ( ) ; results . iter ( ) . for_each ( | result | { let mut entry = table_entry . to_string ( ) ; entry = entry . replace ( " " , & result . time . to_string ( ) ) ; entry = entry . replace ( " " , & result . requested_resource ) ; entry = entry . replace ( " " , & result . response_code . to_string ( ) ) ; entry = entry . replace ( " " , & result . duration . to_string ( ) ) ; table_entries = format ! ( " \n " table_entries entry ) ; } ) ; html = html . replace ( " " , & table_entries ) ; html }
Builds the html file to display the stats dynamically
Builds the html file to display the stats dynamically
resources
Arc<HashMap<String, String>>
results
MutexGuard<Vec<RequestResult>>
result_view
ResultView
resources
Arc<HashMap<String, String>>
results
MutexGuard<Vec<RequestResult>>
result_view
ResultView