| | | 1 | | using pva.SuperV.Engine; |
| | | 2 | | using pva.SuperV.Engine.Exceptions; |
| | | 3 | | using pva.SuperV.Engine.HistoryRetrieval; |
| | | 4 | | using pva.SuperV.Model.Instances; |
| | | 5 | | |
| | | 6 | | namespace pva.SuperV.Model.HistoryRetrieval |
| | | 7 | | { |
| | | 8 | | public static class HistoryRowMapper |
| | | 9 | | { |
| | | 10 | | public static List<HistoryRowModel> ToDto(List<HistoryRow> rows, List<IFieldDefinition> fields) |
| | 3 | 11 | | { |
| | 3 | 12 | | return [.. rows.Select(row |
| | 7 | 13 | | => new HistoryRowModel(row.Ts.ToUniversalTime(), row.Quality, BuildRowValues(row, fields, false) |
| | 7 | 14 | | ))]; |
| | 3 | 15 | | } |
| | | 16 | | |
| | | 17 | | public static List<HistoryStatisticsRowModel> ToDto(List<HistoryStatisticRow> rows, List<IFieldDefinition> field |
| | 2 | 18 | | { |
| | 2 | 19 | | return [.. rows.Select(row |
| | 4 | 20 | | => new HistoryStatisticsRowModel(row.Ts.ToUniversalTime(), row.StartTime, row.EndTime, row.Duration, row |
| | 4 | 21 | | ))]; |
| | 2 | 22 | | } |
| | | 23 | | |
| | | 24 | | public static List<HistoryRawRowModel> ToRawDto(List<HistoryRow> rows) |
| | 3 | 25 | | { |
| | 3 | 26 | | return [.. rows.Select(row |
| | 7 | 27 | | => new HistoryRawRowModel(row.Ts.ToUniversalTime(), row.Quality, |
| | 37 | 28 | | [.. row.Values.Select(value => value)] |
| | 7 | 29 | | ))]; |
| | 3 | 30 | | } |
| | | 31 | | |
| | | 32 | | public static List<HistoryStatisticsRawRowModel> ToRawDto(List<HistoryStatisticRow> rows) |
| | 2 | 33 | | { |
| | 2 | 34 | | return [.. rows.Select(row |
| | 4 | 35 | | => new HistoryStatisticsRawRowModel(row.Ts.ToUniversalTime(), row.StartTime, row.EndTime, row.Duration, |
| | 4 | 36 | | [.. row.Values.Select(value => value)] |
| | 4 | 37 | | ))]; |
| | 2 | 38 | | } |
| | | 39 | | |
| | | 40 | | private static List<FieldValueModel> BuildRowValues(HistoryRow row, List<IFieldDefinition> fields, bool useRowVa |
| | 6 | 41 | | { |
| | 6 | 42 | | List<FieldValueModel> rowValues = []; |
| | 100 | 43 | | for (int index = 0; index < fields.Count; index++) |
| | 44 | 44 | | { |
| | 44 | 45 | | object? rowValue = row.Values[index]; |
| | 44 | 46 | | IFieldDefinition field = fields[index]; |
| | 44 | 47 | | if (useRowValuesDatatype) |
| | 7 | 48 | | { |
| | 7 | 49 | | rowValues.Add( |
| | 7 | 50 | | rowValue switch |
| | 7 | 51 | | { |
| | 0 | 52 | | bool typedRowValue => new BoolFieldValueModel(typedRowValue, FieldValueMapper.FormatValue(fi |
| | 0 | 53 | | DateTime typedRowValue => new DateTimeFieldValueModel(typedRowValue, FieldValueMapper.Format |
| | 5 | 54 | | double typedRowValue => new DoubleFieldValueModel(typedRowValue, FieldValueMapper.FormatValu |
| | 0 | 55 | | float typedRowValue => new FloatFieldValueModel(typedRowValue, FieldValueMapper.FormatValue( |
| | 1 | 56 | | int typedRowValue => new IntFieldValueModel(typedRowValue, FieldValueMapper.FormatValue(fiel |
| | 1 | 57 | | long typedRowValue => new LongFieldValueModel(typedRowValue, FieldValueMapper.FormatValue(fi |
| | 0 | 58 | | short typedRowValue => new ShortFieldValueModel(typedRowValue, FieldValueMapper.FormatValue( |
| | 0 | 59 | | string typedRowValue => new StringFieldValueModel(typedRowValue, row.Quality, row.Ts), |
| | 0 | 60 | | TimeSpan typedRowValue => new TimeSpanFieldValueModel(typedRowValue, FieldValueMapper.Format |
| | 0 | 61 | | uint typedRowValue => new UintFieldValueModel(typedRowValue, FieldValueMapper.FormatValue(fi |
| | 0 | 62 | | ulong typedRowValue => new UlongFieldValueModel(typedRowValue, FieldValueMapper.FormatValue( |
| | 0 | 63 | | ushort typedRowValue => new UshortFieldValueModel(typedRowValue, FieldValueMapper.FormatValu |
| | 0 | 64 | | _ => throw new UnhandledMappingException(nameof(FieldValueMapper), field.Type.ToString()) |
| | 7 | 65 | | }); |
| | 7 | 66 | | } |
| | | 67 | | else |
| | 37 | 68 | | { |
| | | 69 | | #pragma warning disable CS8605 // Unboxing a possibly null value. |
| | 37 | 70 | | rowValues.Add( |
| | 37 | 71 | | field switch |
| | 37 | 72 | | { |
| | 3 | 73 | | FieldDefinition<bool> derivedField => new BoolFieldValueModel((bool)rowValue, FieldValueMapp |
| | 0 | 74 | | FieldDefinition<DateTime> derivedField => new DateTimeFieldValueModel((DateTime)rowValue, Fi |
| | 3 | 75 | | FieldDefinition<double> derivedField => new DoubleFieldValueModel((double)rowValue, FieldVal |
| | 3 | 76 | | FieldDefinition<float> derivedField => new FloatFieldValueModel((float)rowValue, FieldValueM |
| | 7 | 77 | | FieldDefinition<int> derivedField => new IntFieldValueModel((int)rowValue, FieldValueMapper. |
| | 3 | 78 | | FieldDefinition<long> derivedField => new LongFieldValueModel((long)rowValue, FieldValueMapp |
| | 3 | 79 | | FieldDefinition<short> derivedField => new ShortFieldValueModel((short)rowValue, FieldValueM |
| | 3 | 80 | | FieldDefinition<string> => new StringFieldValueModel((string?)rowValue, row.Quality, row.Ts) |
| | 3 | 81 | | FieldDefinition<TimeSpan> derivedField => new TimeSpanFieldValueModel((TimeSpan)rowValue, Fi |
| | 3 | 82 | | FieldDefinition<uint> derivedField => new UintFieldValueModel((uint)rowValue, FieldValueMapp |
| | 3 | 83 | | FieldDefinition<ulong> derivedField => new UlongFieldValueModel((ulong)rowValue, FieldValueM |
| | 3 | 84 | | FieldDefinition<ushort> derivedField => new UshortFieldValueModel((ushort)rowValue, FieldVal |
| | 0 | 85 | | _ => throw new UnhandledMappingException(nameof(FieldValueMapper), field.Type.ToString()) |
| | 37 | 86 | | }); |
| | | 87 | | #pragma warning restore CS8605 // Unboxing a possibly null value. |
| | 37 | 88 | | } |
| | 44 | 89 | | } |
| | 6 | 90 | | return rowValues; |
| | 6 | 91 | | } |
| | | 92 | | } |
| | | 93 | | } |