private void ParseMask(Line line) { var stringMask = line.Raw.Split("=", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).Last(); var result = new MaskValues[SIZE]; for (int pos = 0; pos < stringMask.Length; pos++) { result[SIZE - 1 - pos] = stringMask[pos] == 'X' ? MaskValues.Floating : (stringMask[pos] == '1' ? MaskValues.One : MaskValues.Zero); } this.mask = result; }
/// <summary> /// Test the masking of the data /// </summary> public void TestMask() { MaskValues.ClearMasks(); bool isStart = true; double start = -1; double end = -1; double prevValue = 0; for (int i = 0; i < SeriesCollection[0].Values.Count; i++) { ObservablePoint point = SeriesCollection[0].Values[i] as ObservablePoint; double highValue = GetHighValueAt(point.X); double lowValue = GetLowValueAt(point.X); Debug.WriteLine($"checking for ({point.X},{point.Y}) low: {lowValue} high: {highValue}"); if (point.Y > highValue || point.Y < lowValue) { prevValue = point.Y; if (i == 0) { start = 0; isStart = false; } else { double intersection = 0; ObservablePoint prevPoint = SeriesCollection[0].Values[i - 1] as ObservablePoint; if (point.Y > highValue) { intersection = prevPoint.X + ((highValue - prevPoint.Y) / (point.Y - prevPoint.Y)) * (point.X - prevPoint.X); } else { intersection = prevPoint.X + ((lowValue - prevPoint.Y) / (point.Y - prevPoint.Y)) * (point.X - prevPoint.X); } if (isStart) { start = intersection; isStart = false; } } } else { if (!isStart) { ObservablePoint prevPoint = SeriesCollection[0].Values[i - 1] as ObservablePoint; if (prevValue > highValue) { end = prevPoint.X + ((highValue - prevPoint.Y) / (point.Y - prevPoint.Y)) * (point.X - prevPoint.X); Debug.WriteLine("setting end from high"); } else { end = prevPoint.X + ((lowValue - prevPoint.Y) / (point.Y - prevPoint.Y)) * (point.X - prevPoint.X); Debug.WriteLine("setting end from low"); } Debug.WriteLine($"adding to mask: {start} {end}"); MaskValues.AddToMask(start, end); isStart = true; } } if (i == SeriesCollection[0].Values.Count - 1 && !isStart) { end = point.X; MaskValues.AddToMask(start, end); } } MaskText = MaskValues.GetMaskText(); }