public static Type ToAccessDataType(this DeviceDataType dataType)
        {
            Type type = null;

            Switch.On(dataType)
            .Case(DeviceDataType.Int16, () => { type = typeof(Int16); })
            .Case(DeviceDataType.Int32, () => { type = typeof(Int32); })
            .Case(DeviceDataType.Int64, () => { type = typeof(Int64); })
            .Case(DeviceDataType.UInt16, () => { type = typeof(UInt16); })
            .Case(DeviceDataType.UInt32, () => { type = typeof(UInt32); })
            .Case(DeviceDataType.UInt64, () => { type = typeof(UInt64); })
            .Case(DeviceDataType.Boolean, () => { type = typeof(Boolean); })
            .Case(DeviceDataType.Byte, () => { type = typeof(Byte); })
            .Case(DeviceDataType.SByte, () => { type = typeof(SByte); })
            .Case(DeviceDataType.Decimal, () => { type = typeof(Decimal); })
            .Case(DeviceDataType.Double, () => { type = typeof(Double); })
            .Case(DeviceDataType.HSBCD, () => { type = typeof(HSBCD); })
            .Case(DeviceDataType.SBCD10, () => { type = typeof(SBCD10); })
            .Case(DeviceDataType.BooleanList, () => { type = typeof(BooleanList); })
            .Case(DeviceDataType.String, () => { type = typeof(String); })
            .Case(DeviceDataType.BitArray, () => { type = typeof(BitArray); })
            .Case(DeviceDataType.Int16Array, () => { type = typeof(Int16[]); })
            .Case(DeviceDataType.UInt16Array, () => { type = typeof(UInt16[]); })
            .Case(DeviceDataType.Int32Array, () => { type = typeof(Int32[]); })
            .Case(DeviceDataType.UInt32Array, () => { type = typeof(UInt32[]); })
            .Default(() => { type = typeof(UnknownDateType); });
            return(type);
        }
Beispiel #2
0
        public static IFAS500 Parsing(DeviceDataType type)
        {
            IFAS500 result;

            switch (type)
            {
            case DeviceDataType.OnTime_StsChg:
                result = new FAS500OnTimeData();
                break;

            case DeviceDataType.Manual_StsChg:
                result = new FAS500ManualData();
                break;

            case DeviceDataType.UpdateFirmware:
                result = new FAS500UpdateFirmwareData();
                break;

            case DeviceDataType.Auto_StsChg:
                result = new FAS500AutoData();
                break;

            default:
                result = null;
                break;
            }
            return(result);
        }
 public static string ToString(DeviceDataType value)
 {
     if (value == DeviceDataType.Quantity)
     {
         return("Quantity");
     }
     else if (value == DeviceDataType.Range)
     {
         return("Range");
     }
     else if (value == DeviceDataType.Coding)
     {
         return("Coding");
     }
     else if (value == DeviceDataType.Array)
     {
         return("Array");
     }
     else if (value == DeviceDataType.String)
     {
         return("string");
     }
     else
     {
         throw new ArgumentException("Unrecognized DeviceDataType value: " + value.ToString());
     }
 }
            public static bool TryParse(string value, out DeviceDataType result)
            {
                result = default(DeviceDataType);

                if (value == "Quantity")
                {
                    result = DeviceDataType.Quantity;
                }
                else if (value == "Range")
                {
                    result = DeviceDataType.Range;
                }
                else if (value == "Coding")
                {
                    result = DeviceDataType.Coding;
                }
                else if (value == "Array")
                {
                    result = DeviceDataType.Array;
                }
                else if (value == "string")
                {
                    result = DeviceDataType.String;
                }
                else
                {
                    return(false);
                }

                return(true);
            }
Beispiel #5
0
        public ActionResult Realtime(string macaddress, DeviceDataType type = DeviceDataType.EnergyUsage)
        {
            ViewBag.Title         = "WattchDog - Realtime Device Data";
            TempData["data_type"] = type;

            string table = "";

            switch (type)
            {
            case DeviceDataType.EnergyUsage:
                table = "EnergyUsages";
                break;

            case DeviceDataType.Irms:
                table = "RmsCurrents";
                break;

            case DeviceDataType.PowerFactor:
                table = "PowerFactors";
                break;

            case DeviceDataType.RealPower:
                table = "RealPowers";
                break;

            default:
                table = "RmsVoltages";
                break;
            }

            var repo = new TempRepo();

            var deviceData = new RealtimeDataViewModel();

            var device = repo.GetDevice("mac_address", macaddress).Result;

            if (device.UserId != Session["UID"] as int?)
            {
                return(RedirectToAction("Index"));
            }

            deviceData.Device = (DeviceViewModel)device;

            var data = repo.GetData(table, device.ID, 10).Result.Select(d => (DataViewModel)d);

            data            = data.Reverse();
            deviceData.Type = type;
            deviceData.Data = data;

            return(View(deviceData));
        }
            public static bool TryParse(string value, out DeviceDataType result)
            {
                result = default(DeviceDataType);

                if( value=="Quantity")
                    result = DeviceDataType.Quantity;
                else if( value=="Range")
                    result = DeviceDataType.Range;
                else if( value=="Coding")
                    result = DeviceDataType.Coding;
                else if( value=="Array")
                    result = DeviceDataType.Array;
                else if( value=="string")
                    result = DeviceDataType.String;
                else
                    return false;

                return true;
            }
 public static string ToString(DeviceDataType value)
 {
     if( value==DeviceDataType.Quantity )
         return "Quantity";
     else if( value==DeviceDataType.Range )
         return "Range";
     else if( value==DeviceDataType.Coding )
         return "Coding";
     else if( value==DeviceDataType.Array )
         return "Array";
     else if( value==DeviceDataType.String )
         return "string";
     else
         throw new ArgumentException("Unrecognized DeviceDataType value: " + value.ToString());
 }
Beispiel #8
0
 public ISimTag Build(DeviceDataType dataType)
 {
     return(Container.Resolve <ISimTag>());
 }
Beispiel #9
0
        public ActionResult Monthly(string macaddress, DeviceDataType type = DeviceDataType.EnergyUsage)
        {
            ViewBag.Title         = "WattchDog - Monthly Device Data";
            TempData["data_type"] = type;

            string table = "";

            switch (type)
            {
            case DeviceDataType.EnergyUsage:
                table = "EnergyUsages";
                break;

            case DeviceDataType.Irms:
                table = "RmsCurrents";
                break;

            case DeviceDataType.PowerFactor:
                table = "PowerFactors";
                break;

            case DeviceDataType.RealPower:
                table = "RealPowers";
                break;

            default:
                table = "RmsVoltages";
                break;
            }

            var repo            = new TempRepo();
            var aggregatetdData = new MonthlyDataViewModel();
            var device          = repo.GetDevice("mac_address", macaddress).Result;

            if (device.UserId != Session["UID"] as int?)
            {
                return(RedirectToAction("Index"));
            }

            aggregatetdData.Device = (DeviceViewModel)device;

            var queryTime = TimeZoneInfo.ConvertTime(DateTime.Now,
                                                     TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));

            List <MonthlyDatapointViewModel> outputData;
            var curTime = new DateTime(queryTime.Year, queryTime.Month, 1);
            var refTime = new DateTime(queryTime.Year, queryTime.Month, 1).AddYears(-1);

            var cache = MemoryCache.Default;
            var key   = $"{macaddress.ToUpper()}-{type.ToString()}-{curTime.ToString()}-monthly";

            if (cache.Contains(key))
            {
                outputData = (List <MonthlyDatapointViewModel>)cache[key];
            }
            else
            {
                outputData = new List <MonthlyDatapointViewModel>();
                var data = repo.GetAggregatedData(table, device.ID, queryTime, DateGrouping.Monthly).Result.Reverse().ToList();

                while (refTime < curTime)
                {
                    if (data.ElementAtOrDefault(0)?.GroupedDate == refTime)
                    {
                        outputData.Add(new MonthlyDatapointViewModel()
                        {
                            Month      = data[0].GroupedDate,
                            NumSamples = data[0].NumSamples,
                            Value      = type == DeviceDataType.EnergyUsage ? Math.Round(data[0].AvgValue, 7) : Math.Round(data[0].AvgValue, 2)
                        });
                        data.RemoveAt(0);
                    }
                    else
                    {
                        outputData.Add(new MonthlyDatapointViewModel()
                        {
                            Month      = refTime,
                            NumSamples = 0,
                            Value      = 0
                        });
                    }

                    refTime = refTime.AddMonths(1);
                }

                cache.Add(key, outputData, DateTimeOffset.Now.AddMinutes(5));
            }

            aggregatetdData.Data = outputData;
            aggregatetdData.Type = type;

            return(View(aggregatetdData));
        }