when writing Measurements to a CSV, format them in a machine-readable manner
i haven't tested the ones which contains commas -- hopefully the CSV encoder deals with these :-)
This commit is contained in:
@@ -73,7 +73,7 @@ impl Measurement {
|
||||
&self.name
|
||||
}
|
||||
|
||||
pub fn str_value(&self) -> String {
|
||||
pub fn pretty_print(&self) -> String {
|
||||
use MeasurementValue::*;
|
||||
match self.value {
|
||||
Field(v) => format!("{}{}", v, self.unit),
|
||||
@@ -87,6 +87,18 @@ impl Measurement {
|
||||
}
|
||||
}
|
||||
|
||||
/// format the Measurement in a way that could be parseable later.
|
||||
/// one major use case for this is in dumping the type to a CSV.
|
||||
pub fn machine_readable(&self) -> String {
|
||||
use MeasurementValue::*;
|
||||
match self.value {
|
||||
Field(v) => format!("{},{},{}", v.x(), v.y(), v.z()),
|
||||
Float(f) => f.to_string(),
|
||||
Int(u) => u.to_string(),
|
||||
Dim(v) => format!("{},{},{}", v.x(), v.y(), v.z()),
|
||||
}
|
||||
}
|
||||
|
||||
/// retrieve the float value of this measurement -- if it's of float type.
|
||||
/// useful for tests
|
||||
pub fn get_float(&self) -> Option<f32> {
|
||||
|
Reference in New Issue
Block a user