Ejemplo n.º 1
0
        private static void TestSensorDataStringValues(SensorDataEntity expected, SensorData actual, SensorType sensorType)
        {
            switch (sensorType)
            {
            case SensorType.BooleanSensor:
                BoolSensorData boolData = JsonSerializer.Deserialize <BoolSensorData>(expected.TypedData);
                Assert.Equal(SensorDataStringValuesFactory.GetSimpleSensorsString(expected.TimeCollected, boolData.Comment, boolData.BoolValue),
                             actual.StringValue);
                Assert.Equal(boolData.BoolValue.ToString(), actual.ShortStringValue);
                break;

            case SensorType.IntSensor:
                IntSensorData intData = JsonSerializer.Deserialize <IntSensorData>(expected.TypedData);
                Assert.Equal(SensorDataStringValuesFactory.GetSimpleSensorsString(expected.TimeCollected, intData.Comment, intData.IntValue),
                             actual.StringValue);
                Assert.Equal(intData.IntValue.ToString(), actual.ShortStringValue);
                break;

            case SensorType.DoubleSensor:
                DoubleSensorData doubleData = JsonSerializer.Deserialize <DoubleSensorData>(expected.TypedData);
                Assert.Equal(SensorDataStringValuesFactory.GetSimpleSensorsString(expected.TimeCollected, doubleData.Comment, doubleData.DoubleValue),
                             actual.StringValue);
                Assert.Equal(doubleData.DoubleValue.ToString(), actual.ShortStringValue);
                break;

            case SensorType.StringSensor:
                StringSensorData stringData = JsonSerializer.Deserialize <StringSensorData>(expected.TypedData);
                Assert.Equal(SensorDataStringValuesFactory.GetSimpleSensorsString(expected.TimeCollected, stringData.Comment, stringData.StringValue),
                             actual.StringValue);
                Assert.Equal(stringData.StringValue, actual.ShortStringValue);
                break;

            case SensorType.IntegerBarSensor:
                IntBarSensorData intBarData = JsonSerializer.Deserialize <IntBarSensorData>(expected.TypedData);
                Assert.Equal(SensorDataStringValuesFactory.GetBarSensorsString(expected.TimeCollected, intBarData.Comment, intBarData.Min, intBarData.Mean, intBarData.Max, intBarData.Count, intBarData.LastValue),
                             actual.StringValue);
                Assert.Equal(SensorDataStringValuesFactory.GetBarSensorsShortString(intBarData.Min, intBarData.Mean, intBarData.Max, intBarData.Count, intBarData.LastValue),
                             actual.ShortStringValue);
                break;

            case SensorType.DoubleBarSensor:
                DoubleBarSensorData doubleBarData = JsonSerializer.Deserialize <DoubleBarSensorData>(expected.TypedData);
                Assert.Equal(SensorDataStringValuesFactory.GetBarSensorsString(expected.TimeCollected, doubleBarData.Comment, doubleBarData.Min, doubleBarData.Mean, doubleBarData.Max, doubleBarData.Count, doubleBarData.LastValue),
                             actual.StringValue);
                Assert.Equal(SensorDataStringValuesFactory.GetBarSensorsShortString(doubleBarData.Min, doubleBarData.Mean, doubleBarData.Max, doubleBarData.Count, doubleBarData.LastValue),
                             actual.ShortStringValue);
                break;

            case SensorType.FileSensorBytes:
                FileSensorBytesData fileSensorBytesData = JsonSerializer.Deserialize <FileSensorBytesData>(expected.TypedData);
                Assert.Equal(SensorDataStringValuesFactory.GetFileSensorsString(expected.TimeCollected, fileSensorBytesData.Comment, fileSensorBytesData.FileName, fileSensorBytesData.Extension, fileSensorBytesData.FileContent.Length),
                             actual.StringValue);
                Assert.Equal(SensorDataStringValuesFactory.GetFileSensorsShortString(fileSensorBytesData.FileName, fileSensorBytesData.Extension, fileSensorBytesData.FileContent.Length),
                             actual.ShortStringValue);
                break;
            }
        }
        protected override Collection <DataPoint> ConvertToDataPoints(List <SensorHistoryItem> historyItems)
        {
            Collection <DataPoint> result = new Collection <DataPoint>();

            historyItems.Reverse();
            foreach (var item in historyItems)
            {
                IntSensorData typedData = JsonSerializer.Deserialize <IntSensorData>(item.SensorValue);
                result.Add(new DataPoint(DateTimeAxis.ToDouble(item.Time), typedData.IntValue));
            }

            return(result);
        }