MCPcopy Create free account
hub / github.com/eigenform/perfect / write_csv

Method write_csv

perfect/src/stats.rs:337–383  ·  view source on GitHub ↗

Write this set of results to a CSV file. FIXME: This code is very slow and bad. Would probably be better if this structure was reorganized. FIXME: For now, this simply takes the *mode* from each set of observations.

(&self, filename: &str)

Source from the content-addressed store, hash-verified

335 /// observations.
336 ///
337 pub fn write_csv(&self, filename: &str) {
338 let mut w = csv::Writer::from_path(filename).unwrap();
339
340 // The first row is a set of labels for each column
341 let mut fields = Vec::new();
342 fields.push("input".to_string());
343 for evt in self.data.keys() {
344 fields.push(evt.as_desc().name().to_string());
345 }
346
347
348 // FIXME: This doesn't validate that all results contain the
349 // same number of observations
350 let first = self.data.iter().next().unwrap();
351 let mut num_samples = first.1.len();
352 let num_columns = self.data.keys().len();
353
354 let mut rows: Vec<(I, Vec<usize>)> = {
355 vec![(I::default(), Vec::new()); num_samples]
356 };
357
358 // Fill out the dependent variable column.
359 // FIXME: We only look at one event, but there's no guarantee that
360 // these are the same across all recorded events.
361 for idx in 0..num_samples {
362 rows[idx].0 = first.1.inputs[idx];
363 }
364
365 // Fill out the column for each event
366 for (evt, results) in self.data.iter() {
367 for idx in 0..num_samples {
368 rows[idx].1 = self.iter_ith_results(idx)
369 .map(|x| x.get_mode())
370 .collect();
371 }
372 }
373
374 // Write all of the rows
375 w.write_record(fields).unwrap();
376 for row in rows {
377 let mut r = Vec::new();
378 r.push(format!("{}", row.0));
379 r.extend(row.1.iter().map(|x| format!("{}", x)));
380 w.write_record(r).unwrap();
381 }
382
383 }
384}
385
386/// Set of results associated with a particular experiment.

Callers 1

runMethod · 0.80

Calls 9

nameMethod · 0.80
nextMethod · 0.80
iter_ith_resultsMethod · 0.80
get_modeMethod · 0.80
extendMethod · 0.80
pushMethod · 0.45
as_descMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected