每小時背景執行 加入新的設備計算(風向計、累計日照量)

This commit is contained in:
Kai 2021-12-14 19:45:23 +08:00
parent 6d3bcb7d0d
commit 355ad96330
3 changed files with 70 additions and 3 deletions

View File

@ -21,7 +21,9 @@ namespace SolarPower.Models.PowerStation
EMM = 4, //環境濕度計 EMM = 4, //環境濕度計
VAN = 5, //風速計 VAN = 5, //風速計
FOM = 6, //落塵計 FOM = 6, //落塵計
PWR = 7 //電錶 PWR = 7, //電錶
WIN = 8, //風向計
TPY = 9 //累計日照量
} }
public class PowerStation : Created public class PowerStation : Created
@ -729,6 +731,8 @@ namespace SolarPower.Models.PowerStation
public double Humidity { get; set; } //濕度 public double Humidity { get; set; } //濕度
public double Vane { get; set; } //風速 public double Vane { get; set; } //風速
public double Dust { get; set; } //落塵計 public double Dust { get; set; } //落塵計
public double WingDirection { get; set; } //風向計
public double IrrDay { get; set; } //累計日照量
} }
public class AvgPyrheliometerHistory public class AvgPyrheliometerHistory

View File

@ -428,7 +428,7 @@ namespace SolarPower.Quartz.Jobs
logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message);
} }
//5. 計算該電站 - 落塵計(FOM) //6. 計算該電站 - 落塵計(FOM)
try try
{ {
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的落塵計設備資訊】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的落塵計設備資訊】", powerStation.Code, dateTime);
@ -452,6 +452,54 @@ namespace SolarPower.Quartz.Jobs
logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); 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); sensorHistoriesHour.Add(sensorHistory);
} }

View File

@ -2523,26 +2523,41 @@ namespace SolarPower.Repository.Implement
{ {
SensorTypeEnum SensorTypeEnum = (SensorTypeEnum)type; SensorTypeEnum SensorTypeEnum = (SensorTypeEnum)type;
var typename = ""; var typename = "";
var calc = "";
switch (SensorTypeEnum) switch (SensorTypeEnum)
{ {
case SensorTypeEnum.PYR: //日照計 case SensorTypeEnum.PYR: //日照計
calc = "AVG";
typename = "Irradiance"; typename = "Irradiance";
break; break;
case SensorTypeEnum.MTR: //模組溫度計 case SensorTypeEnum.MTR: //模組溫度計
calc = "AVG";
typename = "Temperature"; typename = "Temperature";
break; break;
case SensorTypeEnum.ETR: //環境溫度計 case SensorTypeEnum.ETR: //環境溫度計
calc = "AVG";
typename = "EnvTemperature"; typename = "EnvTemperature";
break; break;
case SensorTypeEnum.EMM: //環境濕度計 case SensorTypeEnum.EMM: //環境濕度計
calc = "AVG";
typename = "Humidity"; typename = "Humidity";
break; break;
case SensorTypeEnum.VAN: //風速計 case SensorTypeEnum.VAN: //風速計
calc = "AVG";
typename = "Vane"; typename = "Vane";
break; break;
case SensorTypeEnum.FOM: //落塵計 case SensorTypeEnum.FOM: //落塵計
calc = "AVG";
typename = "Dust"; typename = "Dust";
break; break;
case SensorTypeEnum.WIN: //風向計
calc = "AVG";
typename = "WingDirection";
break;
case SensorTypeEnum.TPY: //累計日照量
calc = "MAX";
typename = "IrrDay";
break;
} }
PyrheliometerHistory result; PyrheliometerHistory result;
@ -2563,7 +2578,7 @@ namespace SolarPower.Repository.Implement
sql_per_device.Add(str); 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<PyrheliometerHistory>(sql, new { DateTime = dateTime }); result = await conn.QueryFirstOrDefaultAsync<PyrheliometerHistory>(sql, new { DateTime = dateTime });
} }