Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes #3

Merged
merged 5 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 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 = ["[email protected]"]
version = "1.1.2"
version = "1.2.0"
license = "GPL-2.0"
edition = "2021"

Expand Down
8 changes: 4 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct App {

impl Default for App {
fn default() -> Self {
let (data_window, data_threshold) = algorithm(1, 8, 25, vec![10, 14, 20], true);
let (data_window, data_threshold) = algorithm(1, 8, 25, &[10, 14, 20], true);

let window_data_zipped: Vec<[f64; 2]> = (0..data_window.len())
.zip(data_window.iter())
Expand Down Expand Up @@ -69,7 +69,7 @@ impl App {
algo: Algorithm,
) -> Self {
let (data_window, data_threshold) =
algorithm(window, threshold, cycles, losses.clone(), algo.is_reno());
algorithm(window, threshold, cycles, &losses, algo.is_reno());

let window_data_zipped: Vec<[f64; 2]> = (0..data_window.len())
.zip(data_window.iter())
Expand All @@ -96,7 +96,7 @@ impl App {
self.window,
self.threshold,
self.cycles,
self.losses.clone(),
&self.losses,
self.algorithm.is_reno(),
);

Expand Down Expand Up @@ -244,7 +244,7 @@ impl eframe::App for App {
});

egui::CentralPanel::default().show(ctx, |ui| {
egui_plot::Plot::new("example_plot")
egui_plot::Plot::new("TCP Reno/Tahoe")
.height(ui.available_height() / 2.0)
.show_axes(true)
.legend(Legend::default())
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn algorithm(
initial_window_size: u16,
initial_threshold: u16,
cycles: usize,
losses: Vec<u16>,
losses: &[u16],
is_reno: bool,
) -> (Vec<u16>, Vec<u16>) {
let mut window_size = initial_window_size;
Expand Down
88 changes: 80 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use clap::{command, Parser};
use eframe::egui;
use tcpreno::App;

#[cfg(not(target_arch = "wasm32"))]
#[derive(Parser, Debug)]
#[command(author, version, about)]
struct Cli {
#[clap(
long,
short,
help = "Number of cycles to calculate",
default_value_t = 20
)]
#[clap(long, help = "Number of cycles to calculate", default_value_t = 20)]
cycles: usize,

#[clap(long, short, help = "The initial threshold", default_value_t = 8)]
Expand All @@ -33,19 +30,39 @@ struct Cli {
help = "Algorithm to use: 'Tahoe' or 'Reno'"
)]
algorithm: String,

#[clap(
long,
short,
default_value_t = false,
help = "Avoid the GUI: output the results to stdout and as an image"
)]
cli: bool,
}

#[cfg(not(target_arch = "wasm32"))]
fn main() -> Result<(), eframe::Error> {
let args = Cli::parse();

if args.cli {
do_cli(args);
Ok(())
} else {
do_gui(args)
}
}

#[cfg(not(target_arch = "wasm32"))]
fn do_gui(args: Cli) -> Result<(), eframe::Error> {
use eframe::egui;

let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(1500.0, 700.0)),
..Default::default()
};

eframe::run_native(
"My egui App",
"TCP Reno/Tahoe",
options,
Box::new(move |cc| {
//Increase the font size
Expand All @@ -69,6 +86,61 @@ fn main() -> Result<(), eframe::Error> {
)
}

#[cfg(not(target_arch = "wasm32"))]
fn do_cli(args: Cli) {
use plotly::{
common::{DashType, Line, Title},
layout::Axis,
Layout, Plot, Scatter,
};
use tcpreno::{algorithm, to_csv};

let is_reno = args.algorithm.to_ascii_lowercase().trim().eq("reno");

let window_size = 1;
let threshold = args.threshold;

let (window_sizes, thresholds): (Vec<u16>, Vec<u16>) =
algorithm(window_size, threshold, args.cycles, &args.losses, is_reno);

// Generar scatter plots de cada uno de los vectores
let window_size_trace =
Scatter::new((0..window_sizes.len()).collect(), window_sizes.clone()).name("Window size");
let threshold_trace = Scatter::new((0..thresholds.len()).collect(), thresholds.clone())
.line(Line::new().dash(DashType::DashDot))
.name("Threshold");

// Crear un plot
let layout = Layout::new()
.title(Title::new(&format!(
"{} Window Size and Threshold",
args.algorithm
)))
.x_axis(Axis::new().title(Title::new("Cycle")))
.y_axis(Axis::new().title(Title::new("Window Size / Threshold")));

let mut plot = Plot::new();
plot.add_trace(window_size_trace);
plot.add_trace(threshold_trace);
plot.set_layout(layout);

// Y mostrarlo
plot.show();

// Y además generar el csv
let ws: Vec<[f64; 2]> = window_sizes
.iter()
.map(|v| [0.0f64, *v as f64])
.collect::<Vec<[f64; 2]>>();

let ts: Vec<[f64; 2]> = thresholds
.iter()
.map(|v| [0.0f64, *v as f64])
.collect::<Vec<[f64; 2]>>();

println!("{}", to_csv(&ws, &ts, &args.losses));
}

#[cfg(target_arch = "wasm32")]
fn main() {
let web_options = eframe::WebOptions::default();
Expand Down
Loading