From b9f55a723c3968693d528f38a3157cd796346a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guti=C3=A9rrez=20Alonso?= Date: Mon, 30 Oct 2023 23:18:01 +0100 Subject: [PATCH 1/2] Add missing info --- src/app.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/lib.rs | 16 +++++++--- 2 files changed, 95 insertions(+), 7 deletions(-) diff --git a/src/app.rs b/src/app.rs index ae2e184..752c1b0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,4 +1,4 @@ -use crate::algorithm; +use crate::{algorithm, to_csv}; use eframe::egui; use egui_extras::{Column, TableBuilder}; use egui_plot::{Legend, Line, LineStyle, VLine}; @@ -169,8 +169,15 @@ impl eframe::App for App { ui.horizontal(|ui| { ui.label("Algorithm:"); - ui.radio_value(&mut self.algorithm, Algorithm::Reno, "Reno"); - ui.radio_value(&mut self.algorithm, Algorithm::Tahoe, "Tahoe"); + if ui + .radio_value(&mut self.algorithm, Algorithm::Reno, "Reno") + .clicked() + || ui + .radio_value(&mut self.algorithm, Algorithm::Tahoe, "Tahoe") + .clicked() + { + self.update_data(); + } }); ui.collapsing("Edit cycles where there are losses", |ui| { @@ -251,6 +258,79 @@ impl eframe::App for App { .style(LineStyle::dashed_dense()), ); }); + + ui.separator(); + + ui.horizontal_centered(|ui| { + ui.vertical_centered_justified(|ui| { + TableBuilder::new(ui) + .striped(true) + .auto_shrink([true, true]) + .column(Column::auto()) + .column(Column::auto()) + .column(Column::auto()) + .column(Column::auto()) + .header(30.0, |mut header| { + header.col(|ui| { + ui.heading("Cycle"); + }); + header.col(|ui| { + ui.heading("Window size"); + }); + header.col(|ui| { + ui.heading("Threshold"); + }); + header.col(|ui| { + ui.heading("Has loss?"); + }); + }) + .body(|mut body| { + for (i, (window, threshold)) in self + .window_size_data + .iter() + .zip(self.threshold_data.iter()) + .enumerate() + { + body.row(30.0, |mut row| { + row.col(|ui| { + ui.label(i.to_string()); + }); + + row.col(|ui| { + ui.label(window[1].to_string()); + }); + + row.col(|ui| { + ui.label(threshold[1].to_string()); + }); + + row.col(|ui| { + ui.label(if self.losses.contains(&(i as u16)) { + "Yes" + } else { + "" + }); + }); + }); + } + }); + }); + + ui.separator(); + + ui.vertical_centered_justified(|ui|{ + ui.push_id("CSV scroll", |ui|{ + egui::ScrollArea::vertical().show(ui, |ui| { + + ui.text_edit_multiline(&mut to_csv( + &self.window_size_data, + &self.threshold_data, + &self.losses, + )); + }); + }); + }); + }); }); } } diff --git a/src/lib.rs b/src/lib.rs index bb01e80..a3a6811 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,16 +43,24 @@ pub fn algorithm( (window_sizes, thresholds) } -pub fn to_csv(window_sizes: Vec, thresholds: Vec, losses: Vec) -> String { +pub fn to_csv( + window_sizes: &Vec<[f64; 2]>, + thresholds: &Vec<[f64; 2]>, + losses: &Vec, +) -> String { let mut csv = String::new(); csv.push_str("Cycle;Window size;Threshold;Packet losses\n"); for (i, (window, threshold)) in window_sizes.iter().zip(thresholds.iter()).enumerate() { csv.push_str(&format!( "{};{};{};{}\n", i, - window, - threshold, - if losses.contains(&i) { "Loss" } else { "" } + window[1], + threshold[1], + if losses.contains(&(i as u16)) { + "Loss" + } else { + "" + } )); } csv From e143def91c4956f469cb28209dae4aba2610d48d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guti=C3=A9rrez=20Alonso?= Date: Mon, 30 Oct 2023 23:19:55 +0100 Subject: [PATCH 2/2] Fmt and clippy suggestions --- src/app.rs | 13 ++++++------- src/lib.rs | 6 +----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/app.rs b/src/app.rs index 752c1b0..4419d41 100644 --- a/src/app.rs +++ b/src/app.rs @@ -318,16 +318,15 @@ impl eframe::App for App { ui.separator(); - ui.vertical_centered_justified(|ui|{ - ui.push_id("CSV scroll", |ui|{ - egui::ScrollArea::vertical().show(ui, |ui| { - - ui.text_edit_multiline(&mut to_csv( + ui.vertical_centered_justified(|ui| { + ui.push_id("CSV scroll", |ui| { + egui::ScrollArea::vertical().show(ui, |ui| { + ui.text_edit_multiline(&mut to_csv( &self.window_size_data, &self.threshold_data, &self.losses, - )); - }); + )); + }); }); }); }); diff --git a/src/lib.rs b/src/lib.rs index a3a6811..5437e4d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,11 +43,7 @@ pub fn algorithm( (window_sizes, thresholds) } -pub fn to_csv( - window_sizes: &Vec<[f64; 2]>, - thresholds: &Vec<[f64; 2]>, - losses: &Vec, -) -> String { +pub fn to_csv(window_sizes: &[[f64; 2]], thresholds: &[[f64; 2]], losses: &[u16]) -> String { let mut csv = String::new(); csv.push_str("Cycle;Window size;Threshold;Packet losses\n"); for (i, (window, threshold)) in window_sizes.iter().zip(thresholds.iter()).enumerate() {