diff --git a/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs b/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs index f1d296f..d02515b 100644 --- a/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs +++ b/BackendWorkerService/Services/Implement/ProcEletricMeterService.cs @@ -852,15 +852,15 @@ namespace BackendWorkerService.Services.Implement switch (name) { case "min": - var min = Convert.ToDecimal(real["@val"].ToString()); + var min = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@min_rawdata", min); break; case "max": - var max = Convert.ToDecimal(real["@val"].ToString()); + var max = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@max_rawdata", max); break; case "avg": - var avg = Convert.ToDecimal(real["@val"].ToString()); + var avg = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@avg_rawdata", avg); break; case "sum": @@ -920,15 +920,15 @@ namespace BackendWorkerService.Services.Implement switch (name) { case "min": - var min = Convert.ToDecimal(real["@val"].ToString()); + var min = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@min_rawdata", min); break; case "max": - var max = Convert.ToDecimal(real["@val"].ToString()); + var max = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@max_rawdata", max); break; case "avg": - var avg = Convert.ToDecimal(real["@val"].ToString()); + var avg = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@avg_rawdata", avg); break; case "sum": diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index 30c2377..e02cb24 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -119,7 +119,7 @@ namespace FrontendWebApi.ApiControllers HistoryExport hed = new HistoryExport(); hed.type = devicePoint.Where(x => x.device_building_tag == lhe.building_tag && x.points == ard["@point"].ToString()).Select(x => x.full_name).FirstOrDefault(); hed.deviceName = device.Where(x => x.device_number == ard["@device_number"].ToString()).Select(x => x.full_name).FirstOrDefault(); - hed.value = (double)((decimal)ard["@avg_rawdata"]); + hed.value = ard["@avg_rawdata"].ToString() == "-1" ? "NaN" : Math.Round(Decimal.Parse(ard["@avg_rawdata"].ToString(), System.Globalization.NumberStyles.Float), 2).ToString(); hed.timestamp = Convert.ToDateTime(ard["@start_timestamp"].ToString()); hed.building_tag = lhe.building_tag; he.Add(hed); @@ -1322,19 +1322,19 @@ namespace FrontendWebApi.ApiControllers switch (name) { case "min": - var min = Convert.ToDecimal(real["@val"].ToString()); + var min = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@min_rawdata", min); break; case "max": - var max = Convert.ToDecimal(real["@val"].ToString()); + var max = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@max_rawdata", max); break; case "avg": - var avg = Convert.ToDecimal(real["@val"].ToString()); + var avg = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@avg_rawdata", avg); break; case "sum": - var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); + var sum = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@sum_rawdata", sum); break; } @@ -1390,19 +1390,19 @@ namespace FrontendWebApi.ApiControllers switch (name) { case "min": - var min = Convert.ToDecimal(real["@val"].ToString()); + var min = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@min_rawdata", min); break; case "max": - var max = Convert.ToDecimal(real["@val"].ToString()); + var max = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@max_rawdata", max); break; case "avg": - var avg = Convert.ToDecimal(real["@val"].ToString()); + var avg = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@avg_rawdata", avg); break; case "sum": - var sum = Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); + var sum = real["@val"].ToString() == "NaN" ? -1 : Decimal.Parse(real["@val"].ToString(), System.Globalization.NumberStyles.Float); arrangeRawData.Add("@sum_rawdata", sum); break; } diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs index f1ccac0..7275e6c 100644 --- a/FrontendWebApi/ApiControllers/HydroMeterController.cs +++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs @@ -114,7 +114,7 @@ namespace FrontendWebApi.ApiControllers var aemmEndDate = input.tableType == "year" ? $"year(DATE_ADD(fd.date, INTERVAL +1 {input.tableType}))" : $"DATE_ADD(fd.date, INTERVAL +1 {input.tableType})"; var aemmStaDate = input.tableType == "year" ? "year(fd.date)" : "fd.date"; var sql = $@"set @i = -1; - select fd.device_number, aemm.avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp + select fd.device_number, case when aemm.avg_rawdata = -1 then 'NaN' when aemm.avg_rawdata is null then '0' else aemm.avg_rawdata end as avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp from ( select * from ( @@ -161,7 +161,7 @@ namespace FrontendWebApi.ApiControllers foreach (var l in list) { l.rawData = new List(); - l.device_full_name = await backendRepository.GetOneAsync($"select full_name from device where device_number = '{l.device_number}' and deleted = 0"); + l.device_full_name = await backendRepository.GetOneAsync($"select full_name from device where device_number = '{l.device_number}'"); if (tag_quantity == "5") { l.rawData.AddRange( @@ -176,7 +176,7 @@ namespace FrontendWebApi.ApiControllers } l.building_name = await backendRepository.GetOneAsync("select full_name from building where building_tag = @building_tag and deleted = 0", new { building_tag = l.building_tag }); - l.total = l.rawData.Sum(x => x.avg_rawdata).ToString(); + l.total = l.rawData.Where(x => x.avg_rawdata != "NaN").Sum(x => Decimal.Parse(x.avg_rawdata, System.Globalization.NumberStyles.Float)).ToString(); l.price = input.price.HasValue ? (Math.Round(input.price.Value, 2)).ToString() : Math.Round((await backendRepository.GetOneAsync("select system_value from variable where system_type = 'ElectricPrice' and deleted = 0")), 2).ToString(); @@ -286,7 +286,7 @@ namespace FrontendWebApi.ApiControllers var aemmEndDate = input.tableType == "year" ? $"year(DATE_ADD(fd.date, INTERVAL +1 {input.tableType}))" : $"DATE_ADD(fd.date, INTERVAL +1 {input.tableType})"; var aemmStaDate = input.tableType == "year" ? "year(fd.date)" : "fd.date"; var sql = $@"set @i = -1; - select fd.device_number, aemm.avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp + select fd.device_number, case when aemm.avg_rawdata = -1 then 'NaN' when aemm.avg_rawdata is null then '0' else aemm.avg_rawdata end as avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp from ( select * from ( @@ -334,7 +334,7 @@ namespace FrontendWebApi.ApiControllers foreach (var l in list) { l.rawData = new List(); - l.device_full_name = await backendRepository.GetOneAsync($"select full_name from device where device_number = '{l.device_number}' and deleted = 0"); + l.device_full_name = await backendRepository.GetOneAsync($"select full_name from device where device_number = '{l.device_number}'"); if (tag_quantity == "5") { l.rawData.AddRange( @@ -349,7 +349,7 @@ namespace FrontendWebApi.ApiControllers } l.building_name = await backendRepository.GetOneAsync("select full_name from building where building_tag = @building_tag and deleted = 0", new { building_tag = l.building_tag }); - l.total = l.rawData.Sum(x => x.avg_rawdata).ToString(); + l.total = l.rawData.Where(x => x.avg_rawdata != "NaN").Sum(x => Decimal.Parse(x.avg_rawdata, System.Globalization.NumberStyles.Float)).ToString(); l.price = input.price.HasValue ? (Math.Round(input.price.Value, 2)).ToString() : Math.Round((await backendRepository.GetOneAsync("select system_value from variable where system_type = 'WaterPrice' and deleted = 0")), 2).ToString(); diff --git a/FrontendWebApi/Models/HistoryClass.cs b/FrontendWebApi/Models/HistoryClass.cs index 7fa9fcd..bb04e69 100644 --- a/FrontendWebApi/Models/HistoryClass.cs +++ b/FrontendWebApi/Models/HistoryClass.cs @@ -289,7 +289,7 @@ namespace FrontendWebApi.Models public class HistoryExport { public string deviceName { get; set; } - public double value { get; set; } + public string value { get; set; } public DateTime timestamp { get; set; } public DateTime starttime { get; set; } public DateTime? endtime { get; set; } diff --git a/FrontendWebApi/Models/HydroMeter.cs b/FrontendWebApi/Models/HydroMeter.cs index c8c3f92..67e1fe8 100644 --- a/FrontendWebApi/Models/HydroMeter.cs +++ b/FrontendWebApi/Models/HydroMeter.cs @@ -37,7 +37,7 @@ namespace FrontendWebApi.Models { public string timeStamp { get; set; } public string device_number { get; set; } - public decimal avg_rawdata { get; set; } + public string avg_rawdata { get; set; } } public class HydroMeterPriceInput