This commit is contained in:
cesar liu 2022-08-08 11:44:30 +08:00
commit cb772ef326
7 changed files with 530 additions and 174 deletions

View File

@ -93,6 +93,7 @@ namespace SolarPower.Quartz.Jobs
{ {
var calcPowerStation = new PowerStation(); var calcPowerStation = new PowerStation();
calcPowerStation.Id = powerStation.Id; calcPowerStation.Id = powerStation.Id;
string calcPowerStationTime = "";
#region step2-1. #region step2-1.
var table_name = String.Format("s{1}01_station", powerStation.SiteDB, powerStation.Code); var table_name = String.Format("s{1}01_station", powerStation.SiteDB, powerStation.Code);
@ -107,6 +108,8 @@ namespace SolarPower.Quartz.Jobs
{ {
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, full_table_name); var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, full_table_name);
//await setHistoryPerHourForPowerStation(dateTime, full_table_name, powerStation);
// 當前用不到 // 當前用不到
// var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime); // var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime);
@ -126,12 +129,12 @@ namespace SolarPower.Quartz.Jobs
#region #region
#region #region
//每小時發電量(直接填寫 ////每小時發電量(直接填寫
calcPowerStation.kwh = history.KWH; //calcPowerStation.kwh = history.KWH;
//今日發電量(直接填寫 ////今日發電量(直接填寫
calcPowerStation.Today_kWh = history.TodayKWh; //calcPowerStation.Today_kWh = history.TodayKWh;
//總發電量(直接填寫 ////總發電量(直接填寫
calcPowerStation.Total_kWh = history.TotalKWH; //calcPowerStation.Total_kWh = history.TotalKWH;
#endregion #endregion
#region #region
@ -141,96 +144,96 @@ namespace SolarPower.Quartz.Jobs
history.TOTALMONEY = history.TotalKWH * powerStation.PowerRate; history.TOTALMONEY = history.TotalKWH * powerStation.PowerRate;
//即時發電金額 //即時發電金額
switch (powerStation.SolarType) //switch (powerStation.SolarType)
{ //{
case (int)SolarTypeEnum.SelfSold: //自建躉售 // case (int)SolarTypeEnum.SelfSold: //自建躉售
//if (lastmoneyhistorybyhour != null) // //if (lastmoneyhistorybyhour != null)
//{ // //{
// history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate; // // history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate;
// history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate; // // history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate;
//} // //}
//else // //else
//{ // //{
// history.TODAYMONEY = history.KWH * powerStation.PowerRate; // // history.TODAYMONEY = history.KWH * powerStation.PowerRate;
// history.TOTALMONEY = history.KWH * powerStation.PowerRate; // // history.TOTALMONEY = history.KWH * powerStation.PowerRate;
//} // //}
//今日發電金額 計算方式todaykWh * 授電費率 // //今日發電金額 計算方式todaykWh * 授電費率
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate; // calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
//calcPowerStation.Today_Money = history.TODAYMONEY; // //calcPowerStation.Today_Money = history.TODAYMONEY;
////總發電金額 計算方式totalkWh * 授電費率 // ////總發電金額 計算方式totalkWh * 授電費率
calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate; // calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate;
//calcPowerStation.Total_Money = history.TOTALMONEY; // //calcPowerStation.Total_Money = history.TOTALMONEY;
break; // break;
case (int)SolarTypeEnum.HireSold: //租建躉售 // case (int)SolarTypeEnum.HireSold: //租建躉售
//找出該電站的所有土地房屋資訊 // //找出該電站的所有土地房屋資訊
var landBuildings = await powerStationRepository.GetAllLandBuildingInfoByPowerStationId(powerStation.Id, powerStation.SiteDB); // var landBuildings = await powerStationRepository.GetAllLandBuildingInfoByPowerStationId(powerStation.Id, powerStation.SiteDB);
var sumLeaseRate = 0.00; // var sumLeaseRate = 0.00;
var avgLeaseRate = 0.00; // var avgLeaseRate = 0.00;
foreach (var landBuilding in landBuildings) // foreach (var landBuilding in landBuildings)
{ // {
sumLeaseRate += landBuilding.LeaseRate; // sumLeaseRate += landBuilding.LeaseRate;
} // }
//avgLeaseRate = sumLeaseRate / landBuildings.Count(); // //avgLeaseRate = sumLeaseRate / landBuildings.Count();
//if (lastmoneyhistorybyhour != null) // //if (lastmoneyhistorybyhour != null)
//{ // //{
// history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate; // // history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate;
// history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate; // // history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate;
// //今日發電金額計算方式todaykWh * 出借費率(各個土地房屋租借比率平均) // // //今日發電金額計算方式todaykWh * 出借費率(各個土地房屋租借比率平均)
// calcPowerStation.Today_Money = lastmoneyhistorybyhour.TODAYMONEY + (history.KWH * powerStation.PowerRate * sumLeaseRate); // // calcPowerStation.Today_Money = lastmoneyhistorybyhour.TODAYMONEY + (history.KWH * powerStation.PowerRate * sumLeaseRate);
// //總發電金額 計算方式totalkWh * 授電費率 // // //總發電金額 計算方式totalkWh * 授電費率
// calcPowerStation.Total_Money = lastmoneyhistorybyhour.TOTALMONEY + (history.KWH * powerStation.PowerRate * sumLeaseRate); // // calcPowerStation.Total_Money = lastmoneyhistorybyhour.TOTALMONEY + (history.KWH * powerStation.PowerRate * sumLeaseRate);
//} // //}
//else // //else
//{ // //{
// history.TODAYMONEY = history.KWH * powerStation.PowerRate; // // history.TODAYMONEY = history.KWH * powerStation.PowerRate;
// history.TOTALMONEY = history.KWH * powerStation.PowerRate; // // history.TOTALMONEY = history.KWH * powerStation.PowerRate;
// calcPowerStation.Today_Money = history.KWH * powerStation.PowerRate * sumLeaseRate; // // calcPowerStation.Today_Money = history.KWH * powerStation.PowerRate * sumLeaseRate;
// calcPowerStation.Total_Money = history.KWH * powerStation.PowerRate * sumLeaseRate; // // calcPowerStation.Total_Money = history.KWH * powerStation.PowerRate * sumLeaseRate;
//} // //}
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100; // calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100;
calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100; // calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100;
break; // break;
case (int)SolarTypeEnum.SelfUse: //自建自用 // case (int)SolarTypeEnum.SelfUse: //自建自用
//if (lastmoneyhistorybyhour != null) // //if (lastmoneyhistorybyhour != null)
//{ // //{
// history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate; // // history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate;
// history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate; // // history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate;
//} // //}
//else // //else
//{ // //{
// history.TODAYMONEY = history.KWH * powerStation.PowerRate; // // history.TODAYMONEY = history.KWH * powerStation.PowerRate;
// history.TOTALMONEY = history.KWH * powerStation.PowerRate; // // history.TOTALMONEY = history.KWH * powerStation.PowerRate;
//} // //}
//今日發電金額 計算方式todaykWh * 授電費率 // //今日發電金額 計算方式todaykWh * 授電費率
//calcPowerStation.Today_Money = history.TODAYMONEY; // //calcPowerStation.Today_Money = history.TODAYMONEY;
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate; // calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
//總發電金額 計算方式totalkWh * 授電費率 // //總發電金額 計算方式totalkWh * 授電費率
//calcPowerStation.Total_Money = history.TOTALMONEY; // //calcPowerStation.Total_Money = history.TOTALMONEY;
calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate; // calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate;
break; // break;
} //}
#endregion #endregion
#region kWh/kWp #region kWh/kWp
//直接填寫 ////直接填寫
calcPowerStation.Today_kwhkwp = history.KWHKWP; //calcPowerStation.Today_kwhkwp = history.KWHKWP;
#endregion #endregion
#region PR #region PR
//直接填寫 //直接填寫
calcPowerStation.Today_PR = history.PR; //calcPowerStation.Today_PR = history.PR;
#endregion #endregion
#region #region
@ -252,19 +255,123 @@ namespace SolarPower.Quartz.Jobs
//今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值] //今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
//calcPowerStation.Today_Carbon = history.TODAYCARBON; //calcPowerStation.Today_Carbon = history.TODAYCARBON;
calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate; //calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate;
//總減碳量(總發電量 * (0.554/1000)[抓資料庫值] //總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
//calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate; //calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate; //calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
#endregion #endregion
#region #region
calcPowerStation.SolarHour = history.SolarHour; //calcPowerStation.SolarHour = history.SolarHour;
#endregion #endregion
#endregion #endregion
#region for calcPowerStation
var dateTimeforPowerStation = DateTime.Now.ToString("yyyy-MM-dd");//取當天
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料 for calcPowerStation】", powerStation.Code, dateTimeforPowerStation);
var history_for_powerStation = await powerStationRepository.GetPowerStationHistoryPerHourForPowerStation(dateTimeforPowerStation, full_table_name);
if (history_for_powerStation == null)
{
logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料 for calcPowerStation發電量、發電金額等資料設定為0】", powerStation.Code, dateTimeforPowerStation);
calcPowerStation.kwh = 0;
calcPowerStation.Today_kWh = 0;
calcPowerStation.Total_kWh = 0;
calcPowerStation.Today_Money = 0;
calcPowerStation.Total_Money = 0;
calcPowerStation.Today_kwhkwp = 0;
calcPowerStation.Today_PR = 0;
calcPowerStation.Today_Carbon = 0;
calcPowerStation.Total_Carbon = 0;
calcPowerStation.SolarHour = 0;
}
else
{
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的每小時歷史資料 for calcPowerStation】", powerStation.Code, dateTimeforPowerStation);
#region
//每小時發電量(直接填寫
calcPowerStation.kwh = history_for_powerStation.KWH;
//今日發電量(直接填寫
calcPowerStation.Today_kWh = history_for_powerStation.TodayKWh;
//總發電量(直接填寫
calcPowerStation.Total_kWh = history_for_powerStation.TotalKWH;
#endregion
#region
history_for_powerStation.MONEY = history_for_powerStation.KWH * powerStation.PowerRate;
history_for_powerStation.TODAYMONEY = history_for_powerStation.TodayKWh * powerStation.PowerRate;
history_for_powerStation.TOTALMONEY = history_for_powerStation.TotalKWH * powerStation.PowerRate;
//即時發電金額
switch (powerStation.SolarType)
{
case (int)SolarTypeEnum.SelfSold: //自建躉售
//今日發電金額 計算方式todaykWh * 授電費率
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate;
////總發電金額 計算方式totalkWh * 授電費率
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate;
break;
case (int)SolarTypeEnum.HireSold: //租建躉售
//找出該電站的所有土地房屋資訊
var landBuildings = await powerStationRepository.GetAllLandBuildingInfoByPowerStationId(powerStation.Id, powerStation.SiteDB);
var sumLeaseRate = 0.00;
var avgLeaseRate = 0.00;
foreach (var landBuilding in landBuildings)
{
sumLeaseRate += landBuilding.LeaseRate;
}
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100;
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100;
break;
case (int)SolarTypeEnum.SelfUse: //自建自用
//今日發電金額 計算方式todaykWh * 授電費率
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate;
//總發電金額 計算方式totalkWh * 授電費率
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate;
break;
}
#endregion
#region kWh/kWp
////直接填寫
calcPowerStation.Today_kwhkwp = history_for_powerStation.KWHKWP;
#endregion
#region PR
//直接填寫
calcPowerStation.Today_PR = history_for_powerStation.PR;
#endregion
#region
carbonRate = Convert.ToDouble(await powerStationRepository.GetOneVariableByName("CarbonRate"));
history_for_powerStation.CARBON = history_for_powerStation.KWH * carbonRate;
history_for_powerStation.TODAYCARBON = history_for_powerStation.TodayKWh * carbonRate;
history_for_powerStation.TOTALCARBON = history_for_powerStation.TotalKWH * carbonRate;
//今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
calcPowerStation.Today_Carbon = history_for_powerStation.TodayKWh * carbonRate;
//總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
calcPowerStation.Total_Carbon = history_for_powerStation.TotalKWH * carbonRate;
#endregion
#region
calcPowerStation.SolarHour = history_for_powerStation.SolarHour;
#endregion
#region
calcPowerStationTime = history_for_powerStation.Timestamp;
#endregion
}
#endregion
powerStationHistoriesHour.Add(history); powerStationHistoriesHour.Add(history);
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
@ -299,10 +406,19 @@ namespace SolarPower.Quartz.Jobs
{ {
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime);
var pyrheliometerHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR)); var pyrheliometerHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR));
string dateTimeForCalc;
if (calcPowerStationTime != "")
{
dateTimeForCalc = calcPowerStationTime;
}
else
{
dateTimeForCalc = dateTime;
}
var pyrheliometerHistory_for_calcPowerStation = await powerStationRepository.CalcSensorHistoryPerHour(dateTimeForCalc, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR));
if (pyrheliometerHistory != null) if (pyrheliometerHistory != null)
{ {
calcPowerStation.Today_irradiance = pyrheliometerHistory.Irradiance; calcPowerStation.Today_irradiance = pyrheliometerHistory_for_calcPowerStation.Irradiance;
sensorHistory.Irradiance = pyrheliometerHistory.Irradiance; sensorHistory.Irradiance = pyrheliometerHistory.Irradiance;
@ -492,10 +608,10 @@ namespace SolarPower.Quartz.Jobs
sensorHistory.IrrDay = TPYHistory.IrrDay; sensorHistory.IrrDay = TPYHistory.IrrDay;
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime);
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime);
var ss = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id); var ss = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id);
if (ss != null) if (ss != null)
{ {
sensorHistory.IrrDayHour = double.Parse( ss); sensorHistory.IrrDayHour = double.Parse(ss);
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime);
} }
@ -508,30 +624,6 @@ namespace SolarPower.Quartz.Jobs
logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message);
} }
//9. 計算該電站 - 每小時累計日照量(IrrDayHour)
//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.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id);
// if (TPYHistory != null)
// {
// sensorHistory.IrrDayHour = TPYHistory.IrrDayHour;
// 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);
} }
@ -672,9 +764,9 @@ namespace SolarPower.Quartz.Jobs
double p2 = Convert.ToDouble(powerLocation[1].Replace("°", string.Empty)); double p2 = Convert.ToDouble(powerLocation[1].Replace("°", string.Empty));
double dLat = Convert.ToDouble(Location.Lat); double dLat = Convert.ToDouble(Location.Lat);
double dLon = Convert.ToDouble(Location.Lon); double dLon = Convert.ToDouble(Location.Lon);
double x = Math.Pow(p1 - dLat, 2) ; double x = Math.Pow(p1 - dLat, 2);
double y = Math.Pow(p2 - dLon, 2); double y = Math.Pow(p2 - dLon, 2);
var nowLocation = Math.Sqrt(x + y); var nowLocation = Math.Sqrt(x + y);
//var nowLocation = Math.Sqrt(Math.Pow(Convert.ToDouble(powerLocation[0]) //var nowLocation = Math.Sqrt(Math.Pow(Convert.ToDouble(powerLocation[0])
// - Convert.ToDouble(Location.Lat), 2) // - Convert.ToDouble(Location.Lat), 2)
// + Math.Pow(Convert.ToDouble(powerLocation[1]) // + Math.Pow(Convert.ToDouble(powerLocation[1])
@ -980,5 +1072,99 @@ namespace SolarPower.Quartz.Jobs
} }
} }
} }
public async Task setHistoryPerHourForPowerStation(string dateTime, string full_table_name, PowerStation powerStation)
{
var calcPowerStation = new PowerStation();
calcPowerStation.Id = powerStation.Id;
var history_for_powerStation = await powerStationRepository.GetPowerStationHistoryPerHourForPowerStation(dateTime, full_table_name);
if (history_for_powerStation == null)
{
//logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
//每小時發電量(直接填寫
calcPowerStation.kwh = 0;
//今日發電量(直接填寫
calcPowerStation.Today_kWh = 0;
//總發電量(直接填寫
calcPowerStation.Total_kWh = 0;
}
else
{
//每小時發電量(直接填寫
calcPowerStation.kwh = history_for_powerStation.KWH;
//今日發電量(直接填寫
calcPowerStation.Today_kWh = history_for_powerStation.TodayKWh;
//總發電量(直接填寫
calcPowerStation.Total_kWh = history_for_powerStation.TotalKWH;
#region
history_for_powerStation.MONEY = history_for_powerStation.KWH * powerStation.PowerRate;
history_for_powerStation.TODAYMONEY = history_for_powerStation.TodayKWh * powerStation.PowerRate;
history_for_powerStation.TOTALMONEY = history_for_powerStation.TotalKWH * powerStation.PowerRate;
//即時發電金額
switch (powerStation.SolarType)
{
case (int)SolarTypeEnum.SelfSold: //自建躉售
//今日發電金額 計算方式todaykWh * 授電費率
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate;
////總發電金額 計算方式totalkWh * 授電費率
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate;
break;
case (int)SolarTypeEnum.HireSold: //租建躉售
//找出該電站的所有土地房屋資訊
var landBuildings = await powerStationRepository.GetAllLandBuildingInfoByPowerStationId(powerStation.Id, powerStation.SiteDB);
var sumLeaseRate = 0.00;
var avgLeaseRate = 0.00;
foreach (var landBuilding in landBuildings)
{
sumLeaseRate += landBuilding.LeaseRate;
}
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100;
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100;
break;
case (int)SolarTypeEnum.SelfUse: //自建自用
//今日發電金額 計算方式todaykWh * 授電費率
calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate;
//總發電金額 計算方式totalkWh * 授電費率
calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate;
break;
}
#endregion
#region PR
//直接填寫
calcPowerStation.Today_PR = history_for_powerStation.PR;
#endregion
#region
carbonRate = Convert.ToDouble(await powerStationRepository.GetOneVariableByName("CarbonRate"));
history_for_powerStation.CARBON = history_for_powerStation.KWH * carbonRate;
history_for_powerStation.TODAYCARBON = history_for_powerStation.TodayKWh * carbonRate;
history_for_powerStation.TOTALCARBON = history_for_powerStation.TotalKWH * carbonRate;
//今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
calcPowerStation.Today_Carbon = history_for_powerStation.TodayKWh * carbonRate;
//總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
calcPowerStation.Total_Carbon = history_for_powerStation.TotalKWH * carbonRate;
#endregion
#region
calcPowerStation.SolarHour = history_for_powerStation.SolarHour;
#endregion
}
}
} }
} }

View File

@ -2189,6 +2189,33 @@ namespace SolarPower.Repository.Implement
} }
} }
public async Task<PowerStationHistory> GetPowerStationHistoryPerHourForPowerStation(string dateTime, string table_name)
{
PowerStationHistory result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $@"
SELECT
DATE_FORMAT(FROM_UNIXTIME(timestamp / 1000), '%Y-%m-%d %H') AS TIMESTAMP,
SITEID, SiteType, KWH, TodayKWh, TotalKWH,
KWHKWP, PR, MP, SolarHour
FROM {table_name}
WHERE DATE_FORMAT(FROM_UNIXTIME(timestamp / 1000), '%Y-%m-%d') = @DateTime
AND kwh > 0
order by timestamp desc";
result = await conn.QueryFirstOrDefaultAsync<PowerStationHistory>(sql, new { DateTime = dateTime }, commandTimeout: 600);//加上時間
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task<AvgPowerStationHistory> CalcAvgPowerStationHistory30day(string nowDay, string table_name) public async Task<AvgPowerStationHistory> CalcAvgPowerStationHistory30day(string nowDay, string table_name)
{ {
AvgPowerStationHistory result; AvgPowerStationHistory result;

View File

@ -633,5 +633,6 @@ namespace SolarPower.Repository.Interface
Task<List<PowerStation>> GetAllNoStatusAsync(); Task<List<PowerStation>> GetAllNoStatusAsync();
Task<string> CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId); Task<string> CalcIrrDayHourHistoryPerHour(string dateTime, int powerStationId);
Task<PowerStationHistory> GetPowerStationHistoryPerHourForPowerStation(string dateTime, string table_name);
} }
} }

View File

@ -2366,7 +2366,7 @@
data: kwhBar.datasets[key], data: kwhBar.datasets[key],
backgroundColor: bgColorlist[index], backgroundColor: bgColorlist[index],
} }
hideLoading(); return dataset;
}); });
$('#inverter-kWh-convas-div').empty(); $('#inverter-kWh-convas-div').empty();

View File

@ -56,8 +56,7 @@
<button type="button" class="btn btn-success waves-effect waves-themed" onclick="LoadInvertAnalysiskwhBar()">查詢</button> <button type="button" class="btn btn-success waves-effect waves-themed" onclick="LoadInvertAnalysiskwhBar()">查詢</button>
</div> </div>
</div> </div>
<div class="row mb-5 justify-content-start d-flex flex-wrap">
<div id="inverter-kWh-convas-div"> <div class="row mb-5 justify-content-start d-flex flex-wrap" id="inverter-kWh-convas-div">
<canvas id="inverter-kWh"></canvas> <canvas id="inverter-kWh"></canvas>
</div>
</div> </div>

View File

@ -276,6 +276,33 @@ namespace solarApp.Service
} }
} }
public PowerStationHistory GetPowerStationHistoryPerHourForPowerStation(string dateTime, string table_name)
{
PowerStationHistory result;
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
try
{
var sql = $@"
SELECT
DATE_FORMAT(FROM_UNIXTIME(timestamp / 1000), '%Y-%m-%d %H') AS TIMESTAMP,
SITEID, SiteType, KWH, TodayKWh, TotalKWH,
KWHKWP, PR, MP, SolarHour
FROM {table_name}
WHERE DATE_FORMAT(FROM_UNIXTIME(timestamp / 1000), '%Y-%m-%d') = @DateTime
AND kwh > 0
order by timestamp desc";
result = conn.QueryFirstOrDefault<PowerStationHistory>(sql, new { DateTime = dateTime }, commandTimeout: 600);//加上時間
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
/// <summary> /// <summary>
/// 透過電站編號,取得所有土地房屋資訊 /// 透過電站編號,取得所有土地房屋資訊
/// </summary> /// </summary>

View File

@ -80,6 +80,7 @@ namespace solarApp.Service
{ {
var calcPowerStation = new PowerStation(); var calcPowerStation = new PowerStation();
calcPowerStation.Id = powerStation.Id; calcPowerStation.Id = powerStation.Id;
string calcPowerStationTime = "";
#region step2-1. #region step2-1.
var table_name = String.Format("s{1}01_station", powerStation.SiteDB, powerStation.Code); var table_name = String.Format("s{1}01_station", powerStation.SiteDB, powerStation.Code);
@ -92,53 +93,167 @@ namespace solarApp.Service
} }
else else
{ {
// logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); //// logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
var history = stationSvc.GetPowerStationHistoryPerHour(dateTime, full_table_name); //var history = stationSvc.GetPowerStationHistoryPerHour(dateTime, full_table_name);
// 當前用不到 //// 當前用不到
// var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime); //// var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime);
if (history == null) //if (history == null)
//{
// // logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
//}
//else
//{
// // logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
// // logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的每小時歷史資料】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(history));
// // logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
// history.PowerStationId = powerStation.Id;
// history.Timestamp = Convert.ToDateTime(history.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
// #region 計算單一電站每小時發電量、發電金額等資料
// #region 發電量
// //每小時發電量(直接填寫
// calcPowerStation.kwh = history.KWH;
// //今日發電量(直接填寫
// calcPowerStation.Today_kWh = history.TodayKWh;
// //總發電量(直接填寫
// calcPowerStation.Total_kWh = history.TotalKWH;
// #endregion
// #region 發電金額
// history.MONEY = history.KWH * powerStation.PowerRate;
// history.TODAYMONEY = history.TodayKWh * powerStation.PowerRate;
// history.TOTALMONEY = history.TotalKWH * powerStation.PowerRate;
// //即時發電金額
// switch (powerStation.SolarType)
// {
// case (int)SolarTypeEnum.SelfSold: //自建躉售
// //今日發電金額 計算方式todaykWh * 授電費率
// calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
// //calcPowerStation.Today_Money = history.TODAYMONEY;
// ////總發電金額 計算方式totalkWh * 授電費率
// calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate;
// //calcPowerStation.Total_Money = history.TOTALMONEY;
// break;
// case (int)SolarTypeEnum.HireSold: //租建躉售
// //找出該電站的所有土地房屋資訊
// var landBuildings = stationSvc.GetAllLandBuildingInfoByPowerStationId(powerStation.Id, powerStation.SiteDB);
// var sumLeaseRate = 0.00;
// var avgLeaseRate = 0.00;
// foreach (var landBuilding in landBuildings)
// {
// sumLeaseRate += landBuilding.LeaseRate;
// }
// calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100;
// calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100;
// break;
// case (int)SolarTypeEnum.SelfUse: //自建自用
// //今日發電金額 計算方式todaykWh * 授電費率
// //calcPowerStation.Today_Money = history.TODAYMONEY;
// calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
// //總發電金額 計算方式totalkWh * 授電費率
// //calcPowerStation.Total_Money = history.TOTALMONEY;
// calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate;
// break;
// }
// #endregion
// #region kWh/kWp
// //直接填寫
// calcPowerStation.Today_kwhkwp = history.KWHKWP;
// #endregion
// #region PR
// //直接填寫
// calcPowerStation.Today_PR = history.PR;
// #endregion
// #region 減碳量
// carbonRate = Convert.ToDouble(stationSvc.GetOneVariableByName("CarbonRate"));
// history.CARBON = history.KWH * carbonRate;
// history.TODAYCARBON = history.TodayKWh * carbonRate;
// history.TOTALCARBON = history.TotalKWH * carbonRate;
// //今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
// //calcPowerStation.Today_Carbon = history.TODAYCARBON;
// calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate;
// //總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
// //calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
// calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
// #endregion
// #region 發電時間
// calcPowerStation.SolarHour = history.SolarHour;
// #endregion
// #endregion
// powerStationHistoriesHour.Add(history);
// // logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
//}
#region for calcPowerStation
//logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料 for calcPowerStation】", powerStation.Code, dateTime);
//var dateTimeforPowerStation = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");
var dateTimeforPowerStation = DateTime.Now.ToString("yyyy-MM-dd");
var history_for_powerStation = stationSvc.GetPowerStationHistoryPerHourForPowerStation(dateTimeforPowerStation, full_table_name);
if (history_for_powerStation == null)
{ {
// logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); //logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料 for calcPowerStation發電量、發電金額等資料設定為0】", powerStation.Code, dateTime);
calcPowerStation.kwh = 0;
calcPowerStation.Today_kWh = 0;
calcPowerStation.Total_kWh = 0;
calcPowerStation.Today_Money = 0;
calcPowerStation.Total_Money = 0;
calcPowerStation.Today_kwhkwp = 0;
calcPowerStation.Today_PR = 0;
calcPowerStation.Today_Carbon = 0;
calcPowerStation.Total_Carbon = 0;
calcPowerStation.SolarHour = 0;
} }
else else
{ {
// logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); //logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的每小時歷史資料 for calcPowerStation】", powerStation.Code, dateTime);
// logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的每小時歷史資料】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(history));
// logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
history.PowerStationId = powerStation.Id;
history.Timestamp = Convert.ToDateTime(history.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
#region
#region #region
//每小時發電量(直接填寫 //每小時發電量(直接填寫
calcPowerStation.kwh = history.KWH; calcPowerStation.kwh = history_for_powerStation.KWH;
//今日發電量(直接填寫 //今日發電量(直接填寫
calcPowerStation.Today_kWh = history.TodayKWh; calcPowerStation.Today_kWh = history_for_powerStation.TodayKWh;
//總發電量(直接填寫 //總發電量(直接填寫
calcPowerStation.Total_kWh = history.TotalKWH; calcPowerStation.Total_kWh = history_for_powerStation.TotalKWH;
#endregion #endregion
#region #region
history_for_powerStation.MONEY = history_for_powerStation.KWH * powerStation.PowerRate;
history.MONEY = history.KWH * powerStation.PowerRate; history_for_powerStation.TODAYMONEY = history_for_powerStation.TodayKWh * powerStation.PowerRate;
history.TODAYMONEY = history.TodayKWh * powerStation.PowerRate; history_for_powerStation.TOTALMONEY = history_for_powerStation.TotalKWH * powerStation.PowerRate;
history.TOTALMONEY = history.TotalKWH * powerStation.PowerRate;
//即時發電金額 //即時發電金額
switch (powerStation.SolarType) switch (powerStation.SolarType)
{ {
case (int)SolarTypeEnum.SelfSold: //自建躉售 case (int)SolarTypeEnum.SelfSold: //自建躉售
//今日發電金額 計算方式todaykWh * 授電費率
//今日發電金額 計算方式todaykWh * 授電費率 calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate;
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
//calcPowerStation.Today_Money = history.TODAYMONEY;
////總發電金額 計算方式totalkWh * 授電費率 ////總發電金額 計算方式totalkWh * 授電費率
calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate; calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate;
//calcPowerStation.Total_Money = history.TOTALMONEY;
break; break;
case (int)SolarTypeEnum.HireSold: //租建躉售 case (int)SolarTypeEnum.HireSold: //租建躉售
//找出該電站的所有土地房屋資訊 //找出該電站的所有土地房屋資訊
@ -151,61 +266,53 @@ namespace solarApp.Service
sumLeaseRate += landBuilding.LeaseRate; sumLeaseRate += landBuilding.LeaseRate;
} }
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100; calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate * sumLeaseRate / 100;
calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100; calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate * sumLeaseRate / 100;
break; break;
case (int)SolarTypeEnum.SelfUse: //自建自用 case (int)SolarTypeEnum.SelfUse: //自建自用
//今日發電金額 計算方式todaykWh * 授電費率 //今日發電金額 計算方式todaykWh * 授電費率
//calcPowerStation.Today_Money = history.TODAYMONEY; calcPowerStation.Today_Money = history_for_powerStation.TodayKWh * powerStation.PowerRate;
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
//總發電金額 計算方式totalkWh * 授電費率 //總發電金額 計算方式totalkWh * 授電費率
//calcPowerStation.Total_Money = history.TOTALMONEY; calcPowerStation.Total_Money = history_for_powerStation.TotalKWH * powerStation.PowerRate;
calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate;
break; break;
} }
#endregion #endregion
#region kWh/kWp #region kWh/kWp
//直接填寫 ////直接填寫
calcPowerStation.Today_kwhkwp = history.KWHKWP; calcPowerStation.Today_kwhkwp = history_for_powerStation.KWHKWP;
#endregion #endregion
#region PR #region PR
//直接填寫 //直接填寫
calcPowerStation.Today_PR = history.PR; calcPowerStation.Today_PR = history_for_powerStation.PR;
#endregion #endregion
#region #region
carbonRate = Convert.ToDouble(stationSvc.GetOneVariableByName("CarbonRate")); carbonRate = Convert.ToDouble(stationSvc.GetOneVariableByName("CarbonRate"));
history_for_powerStation.CARBON = history_for_powerStation.KWH * carbonRate;
history.CARBON = history.KWH * carbonRate; history_for_powerStation.TODAYCARBON = history_for_powerStation.TodayKWh * carbonRate;
history.TODAYCARBON = history.TodayKWh * carbonRate; history_for_powerStation.TOTALCARBON = history_for_powerStation.TotalKWH * carbonRate;
history.TOTALCARBON = history.TotalKWH * carbonRate;
//今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值] //今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
//calcPowerStation.Today_Carbon = history.TODAYCARBON; calcPowerStation.Today_Carbon = history_for_powerStation.TodayKWh * carbonRate;
calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate;
//總減碳量(總發電量 * (0.554/1000)[抓資料庫值] //總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
//calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate; calcPowerStation.Total_Carbon = history_for_powerStation.TotalKWH * carbonRate;
calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
#endregion #endregion
#region #region
calcPowerStation.SolarHour = history.SolarHour; calcPowerStation.SolarHour = history_for_powerStation.SolarHour;
#endregion
#endregion #endregion
powerStationHistoriesHour.Add(history); #region
calcPowerStationTime = history_for_powerStation.Timestamp;
// logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); #endregion
} }
#endregion
} }
#endregion #endregion
@ -236,7 +343,16 @@ namespace solarApp.Service
{ {
// logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime); // logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime);
var pyrheliometerHistory = stationSvc.CalcSensorHistoryPerHour(dateTime, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR)); var pyrheliometerHistory = stationSvc.CalcSensorHistoryPerHour(dateTime, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR));
string dateTimeForCalc;
if (calcPowerStationTime != "")
{
dateTimeForCalc = calcPowerStationTime;
}
else
{
dateTimeForCalc = dateTime;
}
var pyrheliometerHistory_for_calcPowerStation = stationSvc.CalcSensorHistoryPerHour(dateTimeForCalc, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR));
if (pyrheliometerHistory != null) if (pyrheliometerHistory != null)
{ {
calcPowerStation.Today_irradiance = pyrheliometerHistory.Irradiance; calcPowerStation.Today_irradiance = pyrheliometerHistory.Irradiance;
@ -314,7 +430,7 @@ namespace solarApp.Service
"SolarHour" "SolarHour"
}; };
// logger.LogInformation("【update Power_Station 】【update Power_Station】", dateTime); // logger.LogInformation("【update Power_Station 】【update Power_Station】", dateTime);
//stationSvc.UpdateList(calcPowerStations, power_station_properties); stationSvc.UpdateList(calcPowerStations, power_station_properties);
#endregion #endregion
//} //}