< Summary - pva.SuperV

Information
Class: pva.SuperV.Engine.HistoryRetrieval.HistoryRow
Assembly: pva.SuperV.Engine
File(s): /home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Engine/HistoryRetrieval/HistoryRow.cs
Tag: dotnet-ubuntu_18869653307
Line coverage
80%
Covered lines: 127
Uncovered lines: 30
Coverable lines: 157
Total lines: 219
Line coverage: 80.8%
Branch coverage
52%
Covered branches: 50
Total branches: 96
Branch coverage: 52%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Ts()100%11100%
get_Quality()100%11100%
get_Values()100%11100%
.ctor(...)84.37%323294.28%
ConvertToUshort(...)33.33%6680%
ConvertToUlong(...)33.33%6680%
ConvertToUint(...)33.33%6680%
ConvertToStringt(...)50%4488.88%
ConvertToShort(...)33.33%6680%
ConvertToTimeSpan(...)50%6680%
ConvertToLong(...)33.33%6680%
ConvertToInt(...)33.33%6680%
ConvertToFloat(...)33.33%6680%
ConvertToDouble(...)50%4488.88%
ConvertToDatetime(...)0%2040%
ConvertToBool(...)50%4488.88%
GetValue(...)100%11100%

File(s)

/home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Engine/HistoryRetrieval/HistoryRow.cs

#LineLine coverage
 1using pva.SuperV.Engine.Exceptions;
 2using TDengine.Driver;
 3
 4namespace pva.SuperV.Engine.HistoryRetrieval
 5{
 6    /// <summary>
 7    /// Row of history for a specific timestamp.
 8    /// </summary>
 9    public class HistoryRow
 10    {
 11        /// <summary>
 12        /// Timestamp of history row.
 13        /// </summary>
 6214        public DateTime Ts { get; }
 15
 16        /// <summary>
 17        /// Quality of history row.
 18        /// </summary>
 5819        public QualityLevel Quality { get; }
 20
 21        /// <summary>
 22        /// List of values as objects.
 23        /// </summary>
 18624        public List<object?> Values { get; } = [];
 25
 26        /// <summary>
 27        /// Builds a row from a TDengine row.
 28        /// </summary>
 29        /// <param name="row">TDengine row</param>
 1830        public HistoryRow(IRows row, List<IFieldDefinition> fields, bool keepFieldType)
 1831        {
 1832            Ts = ((DateTime)row.GetValue(row.FieldCount - 2)).ToUniversalTime();
 1833            string qualityValueString = (string)row.GetValue(row.FieldCount - 1);
 1834            Quality = qualityValueString != null
 1835                ? Enum.Parse<QualityLevel>(qualityValueString)
 1836                : QualityLevel.Uncertain;
 22237            for (int i = 0; i < fields.Count; i++)
 9338            {
 9339                if (keepFieldType)
 7840                {
 7841                    IFieldDefinition field = fields[i];
 7842                    Values.Add(field switch
 7843                    {
 644                        FieldDefinition<bool> => ConvertToBool(field.Name, row.GetValue(i)),
 045                        FieldDefinition<DateTime> => ConvertToDatetime(field.Name, row.GetValue(i)),
 646                        FieldDefinition<double> => ConvertToDouble(field.Name, row.GetValue(i)),
 647                        FieldDefinition<float> => ConvertToFloat(field.Name, row.GetValue(i)),
 1848                        FieldDefinition<int> => ConvertToInt(field.Name, row.GetValue(i)),
 649                        FieldDefinition<long> => ConvertToLong(field.Name, row.GetValue(i)),
 650                        FieldDefinition<TimeSpan> => ConvertToTimeSpan(field.Name, row.GetValue(i)),
 651                        FieldDefinition<short> => ConvertToShort(field.Name, row.GetValue(i)),
 652                        FieldDefinition<string> => ConvertToStringt(field.Name, row.GetValue(i)),
 653                        FieldDefinition<uint> => ConvertToUint(field.Name, row.GetValue(i)),
 654                        FieldDefinition<ulong> => ConvertToUlong(field.Name, row.GetValue(i)),
 655                        FieldDefinition<ushort> => ConvertToUshort(field.Name, row.GetValue(i)),
 056                        _ => throw new UnhandledMappingException(nameof(HistoryRow), field?.Type.ToString()),
 7857
 7858                    });
 7859                }
 60                else
 1561                {
 1562                    Values.Add(row.GetValue(i));
 1563                }
 9364            }
 1865        }
 66
 67        private static ushort? ConvertToUshort(string fieldName, object fieldValue)
 668        {
 69
 670            return fieldValue == null
 671                ? null
 672                : fieldValue switch
 673                {
 674                    ushort directValue => directValue,
 075                    double doubleValue => (ushort)Math.Truncate(doubleValue),
 076                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 677                };
 678        }
 79
 80        private static ulong? ConvertToUlong(string fieldName, object fieldValue)
 681        {
 682            return fieldValue == null
 683                ? null
 684                : fieldValue switch
 685                {
 686                    ulong directValue => directValue,
 087                    double doubleValue => (ulong)Math.Truncate(doubleValue),
 088                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 689                };
 690        }
 91
 92        private static uint? ConvertToUint(string fieldName, object fieldValue)
 693        {
 694            return fieldValue == null
 695                ? null
 696                : fieldValue switch
 697                {
 698                    uint directValue => directValue,
 099                    double doubleValue => (uint)Math.Truncate(doubleValue),
 0100                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 6101                };
 6102        }
 103
 104        private static string? ConvertToStringt(string fieldName, object fieldValue)
 6105        {
 6106            return fieldValue == null
 6107                ? null
 6108                : fieldValue switch
 6109                {
 6110                    string directValue => directValue,
 0111                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 6112                };
 6113        }
 114
 115        private static short? ConvertToShort(string fieldName, object fieldValue)
 6116        {
 6117            return fieldValue == null
 6118                ? null
 6119                : fieldValue switch
 6120                {
 6121                    short directValue => directValue,
 0122                    double doubleValue => (short)Math.Truncate(doubleValue),
 0123                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 6124                };
 6125        }
 126
 127        private static TimeSpan? ConvertToTimeSpan(string fieldName, object fieldValue)
 6128        {
 6129            return fieldValue == null
 6130                ? null
 6131                : fieldValue switch
 6132                {
 0133                    TimeSpan directValue => directValue,
 6134                    long longValue => TimeSpan.FromTicks(longValue),
 0135                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 6136                };
 6137        }
 138
 139        private static long? ConvertToLong(string fieldName, object fieldValue)
 6140        {
 6141            return fieldValue == null
 6142                ? null
 6143                : fieldValue switch
 6144                {
 6145                    long directValue => directValue,
 0146                    double doubleValue => (long)Math.Truncate(doubleValue),
 0147                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 6148                };
 6149        }
 150
 151        private static int? ConvertToInt(string fieldName, object fieldValue)
 18152        {
 18153            return fieldValue == null
 18154                ? null
 18155                : fieldValue switch
 18156                {
 18157                    int directValue => directValue,
 0158                    double doubleValue => (int)Math.Truncate(doubleValue),
 0159                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 18160                };
 18161        }
 162
 163        private static float? ConvertToFloat(string fieldName, object fieldValue)
 6164        {
 6165            return fieldValue == null
 6166                ? null
 6167                : fieldValue switch
 6168                {
 6169                    float directValue => directValue,
 0170                    double doubleValue => (float)doubleValue,
 0171                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 6172                };
 6173        }
 174
 175        private static double? ConvertToDouble(string fieldName, object fieldValue)
 6176        {
 6177            return fieldValue == null
 6178                ? null
 6179                : fieldValue switch
 6180                {
 6181                    double directValue => directValue,
 0182                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 6183                };
 6184        }
 185
 186        private static DateTime? ConvertToDatetime(string fieldName, object fieldValue)
 0187        {
 0188            return fieldValue == null
 0189                ? null
 0190                : fieldValue switch
 0191                {
 0192                    DateTime directValue => directValue,
 0193                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 0194                };
 0195        }
 196
 197        private static bool? ConvertToBool(string fieldName, object fieldValue)
 6198        {
 6199            return fieldValue == null
 6200                ? null
 6201                : fieldValue switch
 6202                {
 6203                    bool directValue => directValue,
 0204                    _ => throw new UnhandledFieldTypeException(fieldName, fieldValue.GetType())
 6205                };
 6206        }
 207
 208        /// <summary>
 209        /// Gets field value at a specific index as the specified type.
 210        /// </summary>
 211        /// <typeparam name="T"></typeparam>
 212        /// <param name="colIndex">Index of value.</param>
 213        /// <returns></returns>
 214        public T? GetValue<T>(int colIndex)
 8215        {
 8216            return (T?)Values[colIndex];
 8217        }
 218    }
 219}