// Take the collection of samples the user gave us, and convert them into the underlying format. private void StoreTwo() { List <OtherItemDataCsvItem> rawSamples = new List <OtherItemDataCsvItem>(); double currentSamplingInterval = SamplingInterval; double lastOffset = -SamplingInterval; for (int sampleNumber = 0; sampleNumber < _twoValuedSamples.Count; sampleNumber++) { ExerciseSampleTwoValue sample = _twoValuedSamples[sampleNumber]; // Is this sample coming when it's expected? // if not, we need to put in an escape... if (lastOffset + currentSamplingInterval != sample.OffsetInSeconds) { currentSamplingInterval = sample.OffsetInSeconds - lastOffset; OtherItemDataCsvEscape escape = new OtherItemDataCsvEscape("i", currentSamplingInterval.ToString()); rawSamples.Add(escape); } rawSamples.Add(new OtherItemDataCsvDouble(sample.Value1)); rawSamples.Add(new OtherItemDataCsvDouble(sample.Value2)); lastOffset = sample.OffsetInSeconds; } SetOtherData(rawSamples); }
// Get all the samples as doubles, and create the collection that we want to return to the user. // We set the time offset from the initial sampling interval and any escapes that are present to // reset it. We also go from a single-valued list to the two-valued list. private void CreateTwoValuedSamples() { ProcessCompressedAndEncodedData(); _twoValuedSamples = new Collection <ExerciseSampleTwoValue>(); Collection <OtherItemDataCsvItem> rawSamples = GetAsDouble(); double currentSampleInterval = _samplingInterval; double offsetInSeconds = -currentSampleInterval; for (int sampleIndex = 0; sampleIndex < rawSamples.Count; sampleIndex++) { OtherItemDataCsvItem item = rawSamples[sampleIndex]; OtherItemDataCsvDouble itemDouble = item as OtherItemDataCsvDouble; if (itemDouble != null) { OtherItemDataCsvDouble itemSecond = rawSamples[sampleIndex + 1] as OtherItemDataCsvDouble; offsetInSeconds += currentSampleInterval; ExerciseSampleTwoValue sample = new ExerciseSampleTwoValue(offsetInSeconds, itemDouble.Value, itemSecond.Value); _twoValuedSamples.Add(sample); sampleIndex++; // skip an extra item } OtherItemDataCsvEscape itemEscape = item as OtherItemDataCsvEscape; if (itemEscape != null) { if (itemEscape.Name == "i") { currentSampleInterval = double.Parse(itemEscape.Value); } } } }