From 4201ddc1822aaeb243842ce0c44abece76f76d62 Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Wed, 8 Apr 2020 03:18:47 -0400 Subject: [PATCH] streamlined csv (fewer cols) --- src/csv.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/csv.rs b/src/csv.rs index bbedaa7..601741c 100644 --- a/src/csv.rs +++ b/src/csv.rs @@ -202,7 +202,12 @@ fn run(start: Instant, logger: &slog::Logger) -> Result { let mut wtr = csv::Writer::from_writer(wtr); - wtr.write_record(&["time","ratio","bmex","gdax","n_bmex","n_gdax","bmex_amt","gdax_amt"]).map_err(|e| format!("writing CSV headers to output file failed: {}", e))?; + wtr.write_record(&[ + "time", + "ratio", + "bmex", + "gdax", + ]).map_err(|e| format!("writing CSV headers to output file failed: {}", e))?; let headers: csv::StringRecord = rdr.headers().map_err(|e| format!("failed to parse CSV headers: {}", e))?.clone(); let mut row = csv::StringRecord::new(); @@ -241,12 +246,12 @@ fn run(start: Instant, logger: &slog::Logger) -> Result { n += 1; - if trade.ticker != t!(btc-usd) { continue } - // verify data is sorted by time assert!(trade.time >= last_time); last_time = trade.time; + if trade.ticker != t!(btc-usd) { continue } + if trade.time >= next_hour { // finalize last hour, and prepare for this hour if n_bmex == 0 || n_gdax == 0 { wtr.write_record(&[ @@ -254,10 +259,6 @@ fn run(start: Instant, logger: &slog::Logger) -> Result { "NaN", "NaN", "NaN", - &format!("{}", n_bmex), - &format!("{}", n_gdax), - &format!("{}", bmex_amt), - &format!("{}", gdax_amt), ]).map_err(|e| format!("writing output row failed: {}", e))?; } else { let bmex_wt_avg = bmex_total / bmex_amt; @@ -268,10 +269,6 @@ fn run(start: Instant, logger: &slog::Logger) -> Result { &format!("{}", ratio), &format!("{}", bmex_wt_avg), &format!("{}", gdax_wt_avg), - &format!("{}", n_bmex), - &format!("{}", n_gdax), - &format!("{}", bmex_amt), - &format!("{}", gdax_amt), ]).map_err(|e| format!("writing output row failed: {}", e))?; } n_written += 1; @@ -295,10 +292,6 @@ fn run(start: Instant, logger: &slog::Logger) -> Result { "NaN", "NaN", "NaN", - "0", - "0", - "0.0", - "0.0", ]).map_err(|e| format!("writing output row failed: {}", e))?; n_written += 1;