Skip to content

Commit

Permalink
Add synthetic dataset download
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoDiFrancesco committed May 3, 2024
1 parent a619415 commit da23d14
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/datasets/keystroke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Keystroke {
let file_name = "keystroke.csv";

if !Path::new(file_name).exists() {
utils::download_csv_file(url, file_name)?
utils::download_csv_file(url, file_name);
}
let file = File::open(file_name)?;
let y_cols = Some(Target::Name("subject".to_string()));
Expand Down
10 changes: 8 additions & 2 deletions src/datasets/synthetic.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
use crate::stream::data_stream::Target;
use crate::stream::iter_csv::IterCsv;
use std::fs::File;
use std::path::Path;

use super::utils;

/// ChatGPT Generated synthetic dataset.
///
/// Add 'synthetic.csv' to project root directory.
pub struct Synthetic;
impl Synthetic {
pub fn load_data() -> IterCsv<f32, File> {
// let file_name = "syntetic_dataset_paper.csv";
let file_name = "syntetic_dataset_int.csv";
let url = "https://marcodifrancesco.com/assets/img/LightRiver/syntetic_dataset.csv";
let file_name = "syntetic_dataset.csv";
if !Path::new(file_name).exists() {
utils::download_csv_file(url, file_name);
}
let file = File::open(file_name).unwrap();
let y_cols = Some(Target::Name("label".to_string()));
IterCsv::<f32, File>::new(file, y_cols).unwrap()
Expand Down
11 changes: 6 additions & 5 deletions src/datasets/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use reqwest::blocking::Client;
use std::fs::File;
use std::io;
use std::path::Path;
use zip::ZipArchive;

Expand Down Expand Up @@ -31,9 +32,9 @@ pub(crate) fn download_zip_file(
Ok(())
}

pub(crate) fn download_csv_file(
url: &str,
file_name: &str,
) -> Result<(), Box<dyn std::error::Error>> {
unimplemented!("For now download the file in the root directory of the project and rename it to 'keystroke.csv'");
pub(crate) fn download_csv_file(url: &str, file_name: &str) {
let resp = reqwest::blocking::get(url).expect("request failed");
let body = resp.text().expect("body invalid");
let mut out = File::create(file_name).expect("failed to create file");
io::copy(&mut body.as_bytes(), &mut out).expect("failed to copy content");
}

0 comments on commit da23d14

Please sign in to comment.