From: Ben Pfaff Date: Sat, 3 Jan 2026 19:33:35 +0000 (-0800) Subject: cleanup X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0ed2b5cca2dc85e223a3a0ed9bc8b2f7becdbc7;p=pspp cleanup --- diff --git a/rust/pspp/src/cli/show_spv.rs b/rust/pspp/src/cli/show_spv.rs index 8f8b0bfa3a..a62c18e7a6 100644 --- a/rust/pspp/src/cli/show_spv.rs +++ b/rust/pspp/src/cli/show_spv.rs @@ -24,7 +24,7 @@ use pspp::{ }, spv::{ SpvArchive, - legacy_bin::LegacyBin, + legacy_bin::{DataValue, LegacyBin}, read::{ReadSeek, legacy_xml::Visualization, structure::OutlineItem}, }, }; @@ -203,9 +203,15 @@ impl ShowSpv { data.values().flat_map(|map| map.iter()).enumerate() { for (value_index, data_value) in values.iter().enumerate() { - let value = Value::new_datum(&data_value.value).with_value_label( - (variable_name == "cellFormat") - .then(|| data_value.as_format(&formats).to_string()), + let value = Value::new_datum(data_value).with_value_label( + (variable_name == "cellFormat").then(|| { + DataValue { + value: data_value.clone(), + index: None, + } + .as_format(&formats) + .to_string() + }), ); pivot_table.insert([value_index, variable_index], value); } diff --git a/rust/pspp/src/spv/read/legacy_bin.rs b/rust/pspp/src/spv/read/legacy_bin.rs index acd43b751b..ed690c2499 100644 --- a/rust/pspp/src/spv/read/legacy_bin.rs +++ b/rust/pspp/src/spv/read/legacy_bin.rs @@ -78,11 +78,11 @@ pub struct LegacyBin { impl LegacyBin { /// Decodes legacy binary data into a map from a series name to a map of - /// variables, which in turn contains a vector of [DataValue]s. + /// variables, which in turn contains a vector of [Datum]s. pub fn decode( &self, warn: &mut dyn FnMut(LegacyBinWarning), - ) -> IndexMap>> { + ) -> IndexMap>>> { let mut sources = IndexMap::new(); for (metadata, data) in self.metadata.iter().zip(&self.data) { let mut variables = IndexMap::new(); @@ -92,10 +92,7 @@ impl LegacyBin { variable .values .iter() - .map(|value| DataValue { - index: None, - value: Datum::Number((*value != f64::MIN).then_some(*value)), - }) + .map(|value| Datum::Number((*value != f64::MIN).then_some(*value))) .collect::>(), ); } @@ -136,7 +133,7 @@ impl LegacyBin { }); continue; }; - value.value = Datum::String(label.label.clone()); + *value = Datum::String(label.label.clone()); } } } diff --git a/rust/pspp/src/spv/read/legacy_xml.rs b/rust/pspp/src/spv/read/legacy_xml.rs index 707d39fa08..93202ca2c5 100644 --- a/rust/pspp/src/spv/read/legacy_xml.rs +++ b/rust/pspp/src/spv/read/legacy_xml.rs @@ -111,7 +111,6 @@ impl Map { if let Datum::Number(Some(number)) = value.value && let Some(to) = self.0.get(&OrderedFloat(number)) { - value.index = Some(number); value.value = to.clone(); } } @@ -209,7 +208,7 @@ impl Visualization { } pub fn decode_series( &self, - data: IndexMap>>, + data: IndexMap>>>, warn: &mut dyn FnMut(LegacyXmlWarning), ) -> BTreeMap<&str, Series> { let mut source_variables = Vec::new(); @@ -626,7 +625,7 @@ impl Visualization { pub fn decode( &self, - binary_data: IndexMap>>, + binary_data: IndexMap>>>, look: Look, warn: &mut dyn FnMut(LegacyXmlWarning), ) -> Result { @@ -831,7 +830,7 @@ impl SourceVariable { } fn decode<'a>( &'a self, - data: &IndexMap>>, + data: &IndexMap>>>, series: &mut BTreeMap<&'a str, Series>, ) -> bool { let label_series = if let Some(label_variable) = &self.label_variable { @@ -847,7 +846,13 @@ impl SourceVariable { let mut data = if let Some(source) = data.get(&self.source) && let Some(values) = source.get(&self.variable) { - values.clone() + values + .iter() + .map(|value| DataValue { + index: value.as_number().flatten(), + value: value.clone(), + }) + .collect() } else { Vec::new() }; @@ -942,6 +947,11 @@ impl DerivedVariable { }); vec![] }; + for datum in &mut values { + if let Datum::Number(Some(number)) = &datum.value { + datum.index = Some(*number); + } + } Map::from_vmes(&self.value_map).apply(&mut values); if let Some(format) = &self.format { Map::from_format(format).apply(&mut values);