use std::fs::File; use std::path::Path; use rand::Rng; use crate::cli::cli::OutputFormat; use crate::system::model::DLASystem; use crate::system::{Position, Storage}; use crate::system::spawner::Spawner; use crate::system::sticker::Sticker; use crate::system::walker::Walker; pub fn write, W: Walker

, Sp: Spawner

, St: Sticker>( sys: &DLASystem, format: OutputFormat, output: &Path, ) { match format { OutputFormat::FullDataJson => write_json_full_data(sys, output), OutputFormat::Positions => write_csv_positions(sys, output), } } fn write_csv_positions, W: Walker

, Sp: Spawner

, St: Sticker>(sys: &DLASystem, csv_path: &Path) { let mut wtr = csv::Writer::from_path(csv_path) .expect("Failed to open file"); // CSVs can only store the raw positions let positions: Vec<&P> = sys.history .iter() .map(|line| &line.position) .collect(); wtr.serialize(positions) .unwrap(); wtr.flush() .unwrap(); } fn write_json_full_data, W: Walker

, Sp: Spawner

, St: Sticker>(sys: &DLASystem, output_path: &Path) { let file = File::create(output_path).expect("Failed to open file"); let vec: Vec

= sys.history .iter() .map(|l| l.position.clone()) .collect(); serde_json::to_writer(file, &vec) .expect("Failed to write json"); }