Skip to content

Commit

Permalink
Add missing table info (#2)
Browse files Browse the repository at this point in the history
* Add missing info

* Fmt and clippy suggestions
  • Loading branch information
margual56 committed Oct 30, 2023
1 parent a8a815d commit 4786938
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tcpreno"
authors = ["margual56@gmail.com"]
version = "1.1.0"
version = "1.1.1"
license = "GPL-2.0"
edition = "2021"

Expand Down
85 changes: 82 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -251,6 +258,78 @@ 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,
));
});
});
});
});
});
}
}
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ pub fn algorithm(
(window_sizes, thresholds)
}

pub fn to_csv(window_sizes: Vec<u16>, thresholds: Vec<u16>, losses: Vec<usize>) -> 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() {
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
Expand Down

0 comments on commit 4786938

Please sign in to comment.