From 355ad963308c1f23114889257fbab9dac2cab0d6 Mon Sep 17 00:00:00 2001 From: Kai Date: Tue, 14 Dec 2021 19:45:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F=E5=B0=8F=E6=99=82=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E5=9F=B7=E8=A1=8C=20=E5=8A=A0=E5=85=A5=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E8=A8=AD=E5=82=99=E8=A8=88=E7=AE=97(=E9=A2=A8=E5=90=91?= =?UTF-8?q?=E8=A8=88=E3=80=81=E7=B4=AF=E8=A8=88=E6=97=A5=E7=85=A7=E9=87=8F?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Models/PowerStation.cs | 6 ++- SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 50 ++++++++++++++++++- .../Implement/PowerStationRepository.cs | 17 ++++++- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index 4d2e793..d4367f6 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -21,7 +21,9 @@ namespace SolarPower.Models.PowerStation EMM = 4, //環境濕度計 VAN = 5, //風速計 FOM = 6, //落塵計 - PWR = 7 //電錶 + PWR = 7, //電錶 + WIN = 8, //風向計 + TPY = 9 //累計日照量 } public class PowerStation : Created @@ -729,6 +731,8 @@ namespace SolarPower.Models.PowerStation public double Humidity { get; set; } //濕度 public double Vane { get; set; } //風速 public double Dust { get; set; } //落塵計 + public double WingDirection { get; set; } //風向計 + public double IrrDay { get; set; } //累計日照量 } public class AvgPyrheliometerHistory diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index e6fa27e..85d8213 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -428,7 +428,7 @@ namespace SolarPower.Quartz.Jobs logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); } - //5. 計算該電站 - 落塵計(FOM) + //6. 計算該電站 - 落塵計(FOM) try { logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的落塵計設備資訊】", powerStation.Code, dateTime); @@ -452,6 +452,54 @@ namespace SolarPower.Quartz.Jobs logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); } + //7. 計算該電站 - 風向計(WIN) + try + { + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的風向計設備資訊】", powerStation.Code, dateTime); + var WINdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.WIN.ToString(), powerStation.SiteDB); + logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的風向計設備資訊】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的風向計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(WINdeviceInfos)); + if (WINdeviceInfos != null && WINdeviceInfos.Count() > 0) + { + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的風向計的平均%】", powerStation.Code, dateTime); + var WINHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, WINdeviceInfos, Convert.ToInt32(SensorTypeEnum.WIN)); + if (WINHistory != null) + { + sensorHistory.WingDirection = WINHistory.WingDirection; + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的風向計的平均值】", powerStation.Code, dateTime); + } + } + } + catch (Exception ex) + { + logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的風向計的平均值】", powerStation.Code, dateTime); + logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + } + + //8. 計算該電站 - 累計日照量(TPY) + try + { + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的累計日照量設備資訊】", powerStation.Code, dateTime); + var TPYdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.TPY.ToString(), powerStation.SiteDB); + logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的累計日照量備資訊】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的累計日照量設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(TPYdeviceInfos)); + if (TPYdeviceInfos != null && TPYdeviceInfos.Count() > 0) + { + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的累計日照量的平均%】", powerStation.Code, dateTime); + var TPYHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, TPYdeviceInfos, Convert.ToInt32(SensorTypeEnum.TPY)); + if (TPYHistory != null) + { + sensorHistory.IrrDay = TPYHistory.IrrDay; + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime); + } + } + } + catch (Exception ex) + { + logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime); + logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + } + sensorHistoriesHour.Add(sensorHistory); } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index f748416..ac15bf7 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -2523,26 +2523,41 @@ namespace SolarPower.Repository.Implement { SensorTypeEnum SensorTypeEnum = (SensorTypeEnum)type; var typename = ""; + var calc = ""; switch (SensorTypeEnum) { case SensorTypeEnum.PYR: //日照計 + calc = "AVG"; typename = "Irradiance"; break; case SensorTypeEnum.MTR: //模組溫度計 + calc = "AVG"; typename = "Temperature"; break; case SensorTypeEnum.ETR: //環境溫度計 + calc = "AVG"; typename = "EnvTemperature"; break; case SensorTypeEnum.EMM: //環境濕度計 + calc = "AVG"; typename = "Humidity"; break; case SensorTypeEnum.VAN: //風速計 + calc = "AVG"; typename = "Vane"; break; case SensorTypeEnum.FOM: //落塵計 + calc = "AVG"; typename = "Dust"; break; + case SensorTypeEnum.WIN: //風向計 + calc = "AVG"; + typename = "WingDirection"; + break; + case SensorTypeEnum.TPY: //累計日照量 + calc = "MAX"; + typename = "IrrDay"; + break; } PyrheliometerHistory result; @@ -2563,7 +2578,7 @@ namespace SolarPower.Repository.Implement sql_per_device.Add(str); } - var sql = @$"SELECT a.TIMESTAMP, AVG(a.SENSOR) AS {typename} FROM(" + string.Join(" UNION ", sql_per_device) + @") a GROUP BY `TIMESTAMP`"; + var sql = @$"SELECT a.TIMESTAMP, {calc}(a.SENSOR) AS {typename} FROM(" + string.Join(" UNION ", sql_per_device) + @") a GROUP BY `TIMESTAMP`"; result = await conn.QueryFirstOrDefaultAsync(sql, new { DateTime = dateTime }); }