1. 修改背景執行
2. bug fix
This commit is contained in:
parent
6bcdb90104
commit
0d552ad69b
@ -307,8 +307,9 @@ namespace SolarPower.Controllers
|
||||
|
||||
var inverterHistories = await overviewRepository.GetListInverterByPowerStationIdAndDate(powerStation.Id, post.SelectedDate);
|
||||
|
||||
inverterHeatMap.XAxis = inverterHistories.Select(x => x.TIMESTAMP).Distinct().ToList();
|
||||
inverterHeatMap.XAxis = inverterHistories.Select(x => Convert.ToDateTime(x.TIMESTAMP).ToString("HH:mm")).Distinct().ToList();
|
||||
inverterHeatMap.YAxis = inverterHistories.Select(x => x.INVERTERID).Distinct().ToList();
|
||||
inverterHeatMap.XAxisOnTime = new List<string>();
|
||||
|
||||
inverterHeatMap.Series = new Dictionary<string, List<HeatMapSeries>>();
|
||||
|
||||
@ -319,7 +320,7 @@ namespace SolarPower.Controllers
|
||||
foreach (var value in inverterHistory)
|
||||
{
|
||||
HeatMapSeries heatMapSeries = new HeatMapSeries();
|
||||
heatMapSeries.X = inverterHeatMap.XAxis.IndexOf(value.TIMESTAMP);
|
||||
heatMapSeries.X = inverterHeatMap.XAxis.IndexOf(Convert.ToDateTime(value.TIMESTAMP).ToString("HH:mm"));
|
||||
heatMapSeries.Y = inverterHeatMap.YAxis.IndexOf(value.INVERTERID);
|
||||
heatMapSeries.Value = value.KWHKWP;
|
||||
|
||||
@ -329,6 +330,19 @@ namespace SolarPower.Controllers
|
||||
inverterHeatMap.Series.Add(inverterHistory.Key, heats);
|
||||
}
|
||||
|
||||
for (var i = 0; i < inverterHeatMap.XAxis.Count(); i++)
|
||||
{
|
||||
|
||||
if (inverterHeatMap.XAxis[i].Substring(3, 2) != "00")
|
||||
{
|
||||
inverterHeatMap.XAxisOnTime.Add("");
|
||||
}
|
||||
else
|
||||
{
|
||||
inverterHeatMap.XAxisOnTime.Add(inverterHeatMap.XAxis[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = inverterHeatMap;
|
||||
@ -360,7 +374,7 @@ namespace SolarPower.Controllers
|
||||
{
|
||||
if (string.IsNullOrEmpty(a.FormId))
|
||||
{
|
||||
if(a.Err_status == 1)
|
||||
if (a.Err_status == 1)
|
||||
{
|
||||
a.Function = @$"<a href='javascript:;' class='btn btn-success waves-effect waves-themed mb-3 mr-2 add-btn'>填寫表單</a>";
|
||||
}
|
||||
@ -416,10 +430,25 @@ namespace SolarPower.Controllers
|
||||
var inverterHistory_group = inverterHistoriesDay.GroupBy(x => x.INVERTERID).ToList();
|
||||
foreach (var inverterHistory in inverterHistory_group)
|
||||
{
|
||||
|
||||
List<double> values = new List<double>();
|
||||
foreach (var value in inverterHistory)
|
||||
foreach(var lable in inverterkwhBar.Labels)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
var find = false;
|
||||
foreach (var value in inverterHistory)
|
||||
{
|
||||
if(value.TIMESTAMP == lable)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!find)
|
||||
{
|
||||
values.Add(0);
|
||||
}
|
||||
}
|
||||
|
||||
inverterkwhBar.Datasets.Add(inverterHistory.Key, values);
|
||||
@ -436,9 +465,23 @@ namespace SolarPower.Controllers
|
||||
foreach (var inverterHistory in inverterHistoryMonth_group)
|
||||
{
|
||||
List<double> values = new List<double>();
|
||||
foreach (var value in inverterHistory)
|
||||
foreach (var lable in inverterkwhBar.Labels)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
var find = false;
|
||||
foreach (var value in inverterHistory)
|
||||
{
|
||||
if (value.TIMESTAMP == lable)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!find)
|
||||
{
|
||||
values.Add(0);
|
||||
}
|
||||
}
|
||||
|
||||
inverterkwhBar.Datasets.Add(inverterHistory.Key, values);
|
||||
@ -477,9 +520,23 @@ namespace SolarPower.Controllers
|
||||
foreach (var inverterHistory in inverterHistoryQuaryerly_group)
|
||||
{
|
||||
List<double> values = new List<double>();
|
||||
foreach (var value in inverterHistory)
|
||||
foreach (var lable in inverterkwhBar.Labels)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
var find = false;
|
||||
foreach (var value in inverterHistory)
|
||||
{
|
||||
if (value.TIMESTAMP == lable)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!find)
|
||||
{
|
||||
values.Add(0);
|
||||
}
|
||||
}
|
||||
|
||||
inverterkwhBar.Datasets.Add(inverterHistory.Key, values);
|
||||
@ -495,9 +552,23 @@ namespace SolarPower.Controllers
|
||||
foreach (var inverterHistory in inverterHistoryYear_group)
|
||||
{
|
||||
List<double> values = new List<double>();
|
||||
foreach (var value in inverterHistory)
|
||||
foreach (var lable in inverterkwhBar.Labels)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
var find = false;
|
||||
foreach (var value in inverterHistory)
|
||||
{
|
||||
if (value.TIMESTAMP == lable)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!find)
|
||||
{
|
||||
values.Add(0);
|
||||
}
|
||||
}
|
||||
|
||||
inverterkwhBar.Datasets.Add(inverterHistory.Key, values);
|
||||
@ -505,15 +576,6 @@ namespace SolarPower.Controllers
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = inverterkwhBar;
|
||||
}
|
||||
@ -533,11 +595,11 @@ namespace SolarPower.Controllers
|
||||
var History = new List<HistoryTable>();
|
||||
ApiResult<List<HistoryTable>> apiResult = new ApiResult<List<HistoryTable>>();
|
||||
var powerStation = await powerStationRepository.GetOneAsync(post.PowerstationId);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
History = await overviewRepository.GethistoryTable(post);
|
||||
foreach(var a in History)
|
||||
foreach (var a in History)
|
||||
{
|
||||
switch (post.GroupType)
|
||||
{
|
||||
|
||||
@ -121,6 +121,7 @@ namespace SolarPower.Models
|
||||
public class InverterHeatMap
|
||||
{
|
||||
public List<string> XAxis { get; set; } //時間
|
||||
public List<string> XAxisOnTime { get; set; } //時間(整點)
|
||||
public List<string> YAxis { get; set; } //逆變器名稱
|
||||
public Dictionary<string, List<HeatMapSeries>> Series { get; set; } //數組
|
||||
}
|
||||
|
||||
@ -36,22 +36,89 @@ namespace SolarPower.Quartz.Jobs
|
||||
|
||||
List<PowerStation> calcAvgPowerStations = new List<PowerStation>();
|
||||
List<PowerStationHistoryDay> powerStationHistoryDays = new List<PowerStationHistoryDay>();
|
||||
|
||||
|
||||
List<PowerStationHistoryMonth> insertPowerStationHistoryMonths = new List<PowerStationHistoryMonth>();
|
||||
List<PowerStationHistoryMonth> updatePowerStationHistoryMonths = new List<PowerStationHistoryMonth>();
|
||||
|
||||
List<PyrheliometerHistory> pyrheliometerHistoryDays = new List<PyrheliometerHistory>();
|
||||
List<PyrheliometerHistory> insertPyrheliometerHistoryMonths = new List<PyrheliometerHistory>();
|
||||
List<PyrheliometerHistory> updatePyrheliometerHistoryMonths = new List<PyrheliometerHistory>();
|
||||
List<string> pyrheliometer_history_properties = new List<string>()
|
||||
{
|
||||
"PowerStationId",
|
||||
"Timestamp",
|
||||
"Irradiance",
|
||||
"Temperature"
|
||||
};
|
||||
|
||||
|
||||
List<InverterHistory> allofInverterHistorDays = new List<InverterHistory>();
|
||||
List<InverterHistory> insertInverterHistoryMonths = new List<InverterHistory>();
|
||||
List<InverterHistory> updateInverterHistoryMonths = new List<InverterHistory>();
|
||||
List<string> inverter_history_properties = new List<string>()
|
||||
{
|
||||
"PowerStationId",
|
||||
"TIMESTAMP",
|
||||
"INVERTERID",
|
||||
"Irradiance",
|
||||
"AC1V",
|
||||
"AC1A",
|
||||
"AC1W",
|
||||
"AC1F",
|
||||
"AC1WH",
|
||||
"AC2V",
|
||||
"AC2A",
|
||||
"AC2W",
|
||||
"AC2F",
|
||||
"AC2WH",
|
||||
"AC3V",
|
||||
"AC3A",
|
||||
"AC3W",
|
||||
"AC3F",
|
||||
"AC3WH",
|
||||
"DC1V",
|
||||
"DC1A",
|
||||
"DC1W",
|
||||
"DC1KW",
|
||||
"DC1WH",
|
||||
"DC2V",
|
||||
"DC2A",
|
||||
"DC2W",
|
||||
"DC2KW",
|
||||
"DC2WH",
|
||||
"DC3V",
|
||||
"DC3A",
|
||||
"DC3W",
|
||||
"DC3KW",
|
||||
"DC3WH",
|
||||
"DC4V",
|
||||
"DC4A",
|
||||
"DC4W",
|
||||
"DC4KW",
|
||||
"DC4WH",
|
||||
"DC5V",
|
||||
"DC5A",
|
||||
"DC5W",
|
||||
"DC5KW",
|
||||
"DC5WH",
|
||||
"PR",
|
||||
"RA1",
|
||||
"RA2",
|
||||
"RA3",
|
||||
"RA4",
|
||||
"RA5",
|
||||
"DCKW",
|
||||
"ACKW",
|
||||
"KWH",
|
||||
"TODAYKWH",
|
||||
"KWHKWP",
|
||||
};
|
||||
|
||||
List<WeatherForecast> weatherForecasts = new List<WeatherForecast>();
|
||||
|
||||
var DateTimeNow = DateTime.Now;
|
||||
|
||||
var count = 0;
|
||||
|
||||
#region 氣象觀測(取資料)
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始取得氣象觀測】");
|
||||
var client = new HttpClient();
|
||||
@ -134,113 +201,162 @@ namespace SolarPower.Quartz.Jobs
|
||||
};
|
||||
await powerStationRepository.AddWeatherForecast(weatherForecasts, weather_forecast_properties);
|
||||
|
||||
#region step2. 從電站的DB及電站編號找出該電站的控制器
|
||||
#region step2. 歸檔電站的每日資訊
|
||||
foreach (var powerStation in powerStations)
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var calcPowerStation = new PowerStation();
|
||||
calcPowerStation.Id = powerStation.Id;
|
||||
var dateNowDay = DateTimeNow.AddDays(-1).ToString("yyyy-MM-dd");
|
||||
|
||||
#region step2-1. 計算該電站的30天平均資料
|
||||
var table_name = String.Format("`{0}`.`s{1}01_station`", powerStation.SiteDB, powerStation.Code);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的30天平均資料】", powerStation.Code, dateNowDay);
|
||||
var history = await powerStationRepository.CalcAvgPowerStationHistory30day(dateNowDay, table_name);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【取得成功電站[{0}]在{1}的30天平均資料】", powerStation.Code, dateNowDay);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【電站[{0}]在{1}的30天平均資料】 - {2}", powerStation.Code, dateNowDay, System.Text.Json.JsonSerializer.Serialize(history));
|
||||
if (history != null)
|
||||
var table_name = String.Format("s{1}01_station", powerStation.SiteDB, powerStation.Code);
|
||||
var full_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, table_name);
|
||||
var exist = await powerStationRepository.ExistTable(powerStation.SiteDB, table_name);
|
||||
if (!string.IsNullOrEmpty(exist))
|
||||
{
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的30天平均資料】", powerStation.Code, dateNowDay);
|
||||
history.PowerStationId = powerStation.Id;
|
||||
var history = await powerStationRepository.CalcAvgPowerStationHistory30day(dateNowDay, full_table_name);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【取得成功電站[{0}]在{1}的30天平均資料】", powerStation.Code, dateNowDay);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【電站[{0}]在{1}的30天平均資料】 - {2}", powerStation.Code, dateNowDay, System.Text.Json.JsonSerializer.Serialize(history));
|
||||
if (history != null)
|
||||
{
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的30天平均資料】", powerStation.Code, dateNowDay);
|
||||
history.PowerStationId = powerStation.Id;
|
||||
|
||||
#region 計算電站30天的 kWh/kWp 與 PR 值
|
||||
#region 計算電站30天的 kWh/kWp 與 PR 值
|
||||
|
||||
#region 平均kWh/kWp
|
||||
//直接填寫
|
||||
calcPowerStation.Avg_kwhkwp = history.AvgKWHKWP;
|
||||
#region 平均kWh/kWp
|
||||
//直接填寫
|
||||
calcPowerStation.Avg_kwhkwp = history.AvgKWHKWP;
|
||||
#endregion
|
||||
|
||||
#region 平均PR
|
||||
//直接填寫
|
||||
calcPowerStation.Avg_PR = history.AvgPR;
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的30天平均資料】", powerStation.Code, dateNowDay);
|
||||
}
|
||||
|
||||
#region step2-2 計算電站30天的日照計平均值
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的30天日照計平均資料】", powerStation.Code, dateNowDay);
|
||||
var avgPyrheliometerHistory = await powerStationRepository.CalcAvgPyrheliometerHistory30day(dateNowDay, powerStation.Id);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【取得成功電站[{0}]在{1}的30天日照計平均資料】", powerStation.Code, dateNowDay);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【電站[{0}]在{1}的30天日照計平均資料】 - {2}", powerStation.Code, dateNowDay, System.Text.Json.JsonSerializer.Serialize(avgPyrheliometerHistory));
|
||||
if (avgPyrheliometerHistory != null)
|
||||
{
|
||||
calcPowerStation.Avg_irradiance = avgPyrheliometerHistory.AvgIrradiance;
|
||||
}
|
||||
|
||||
calcAvgPowerStations.Add(calcPowerStation);
|
||||
#endregion
|
||||
|
||||
#region 平均PR
|
||||
//直接填寫
|
||||
calcPowerStation.Avg_PR = history.AvgPR;
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的30天平均資料】", powerStation.Code, dateNowDay);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region step2-2 計算電站30天的日照計平均值
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的30天日照計平均資料】", powerStation.Code, dateNowDay);
|
||||
var avgPyrheliometerHistory = await powerStationRepository.CalcAvgPyrheliometerHistory30day(dateNowDay, powerStation.Id);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【取得成功電站[{0}]在{1}的30天日照計平均資料】", powerStation.Code, dateNowDay);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【電站[{0}]在{1}的30天日照計平均資料】 - {2}", powerStation.Code, dateNowDay, System.Text.Json.JsonSerializer.Serialize(avgPyrheliometerHistory));
|
||||
if (avgPyrheliometerHistory != null)
|
||||
{
|
||||
calcPowerStation.Avg_irradiance = avgPyrheliometerHistory.AvgIrradiance;
|
||||
}
|
||||
|
||||
calcAvgPowerStations.Add(calcPowerStation);
|
||||
#endregion
|
||||
|
||||
#region step2-3. 計算昨天的所有值總和
|
||||
//電站資訊
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始取得電站[{0}]在{1}的所有值的總和】", powerStation.Code, dateNowDay);
|
||||
var historyDay = await powerStationRepository.GetLastOnePowerStationHistoryByDay(dateNowDay, table_name);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【取得成功電站[{0}]在{1}的所有值的總和】", powerStation.Code, dateNowDay);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【電站[{0}]在{1}的所有值的總和】 - {2}", powerStation.Code, dateNowDay, System.Text.Json.JsonSerializer.Serialize(historyDay));
|
||||
var daynow = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
var moneyandcarbon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowDay, 1);
|
||||
var lastmoneyhistory = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 1,"");
|
||||
if (historyDay != null)
|
||||
if (!string.IsNullOrEmpty(exist))
|
||||
{
|
||||
historyDay.PowerStationId = powerStation.Id;
|
||||
historyDay.CARBON = moneyandcarbon.CARBON;
|
||||
historyDay.MONEY = moneyandcarbon.MONEY;
|
||||
//historyDay.TODAYCARBON = lastmoneyhistory.TODAYCARBON;
|
||||
//historyDay.TODAYMONEY = lastmoneyhistory.TODAYMONEY ;
|
||||
historyDay.TOTALCARBON = lastmoneyhistory.TOTALCARBON + moneyandcarbon.CARBON;
|
||||
historyDay.TOTALMONEY = lastmoneyhistory.TOTALMONEY + moneyandcarbon.MONEY;
|
||||
powerStationHistoryDays.Add(historyDay);
|
||||
}
|
||||
|
||||
//日照計
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的日照計所有值的平均】", powerStation.Code, dateNowDay);
|
||||
var pyrheliometerHistorDay = await powerStationRepository.CalcPyrheliometerHistoryDayDataByPowerStationId(dateNowDay, powerStation.Id);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的日照計所有值的平均】", powerStation.Code, dateNowDay);
|
||||
if (pyrheliometerHistorDay != null)
|
||||
{
|
||||
pyrheliometerHistoryDays.Add(pyrheliometerHistorDay);
|
||||
}
|
||||
|
||||
//逆變器
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的逆變器所有值的平均】", powerStation.Code, dateNowDay);
|
||||
var inverterHistoriesDay = await powerStationRepository.CalcInverterHistoryDayDataByPowerStationId(dateNowDay, powerStation.SiteDB, powerStation.Id);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的逆變器所有值的平均】", powerStation.Code, dateNowDay);
|
||||
if (inverterHistoriesDay != null)
|
||||
{
|
||||
foreach(var inverterHistoryDay in inverterHistoriesDay)
|
||||
//電站資訊
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始取得電站[{0}]在{1}的所有值的總和】", powerStation.Code, dateNowDay);
|
||||
var historyDay = await powerStationRepository.GetLastOnePowerStationHistoryByDay(dateNowDay, full_table_name);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【取得成功電站[{0}]在{1}的所有值的總和】", powerStation.Code, dateNowDay);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【電站[{0}]在{1}的所有值的總和】 - {2}", powerStation.Code, dateNowDay, System.Text.Json.JsonSerializer.Serialize(historyDay));
|
||||
var daynow = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
var moneyandcarbon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowDay, 1);
|
||||
var lastmoneyhistory = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 1, "");
|
||||
if (historyDay != null)
|
||||
{
|
||||
inverterHistoryDay.DC1KW = inverterHistoryDay.DC1W / 1000;
|
||||
inverterHistoryDay.DC2KW = inverterHistoryDay.DC2W / 1000;
|
||||
inverterHistoryDay.DC3KW = inverterHistoryDay.DC3W / 1000;
|
||||
inverterHistoryDay.DC4KW = inverterHistoryDay.DC4W / 1000;
|
||||
inverterHistoryDay.DC5KW = inverterHistoryDay.DC5W / 1000;
|
||||
historyDay.PowerStationId = powerStation.Id;
|
||||
historyDay.CARBON = moneyandcarbon.CARBON;
|
||||
historyDay.MONEY = moneyandcarbon.MONEY;
|
||||
//historyDay.TODAYCARBON = lastmoneyhistory.TODAYCARBON;
|
||||
//historyDay.TODAYMONEY = lastmoneyhistory.TODAYMONEY ;
|
||||
historyDay.TOTALCARBON = lastmoneyhistory.TOTALCARBON + moneyandcarbon.CARBON;
|
||||
historyDay.TOTALMONEY = lastmoneyhistory.TOTALMONEY + moneyandcarbon.MONEY;
|
||||
|
||||
inverterHistoryDay.DCKW = (inverterHistoryDay.DC1W + inverterHistoryDay.DC2W + inverterHistoryDay.DC3W + inverterHistoryDay.DC4W + inverterHistoryDay.DC5W) / 1000;
|
||||
inverterHistoryDay.ACKW = (inverterHistoryDay.AC1W + inverterHistoryDay.AC2W + inverterHistoryDay.AC3W) / 1000;
|
||||
|
||||
allofInverterHistorDays.Add(inverterHistoryDay);
|
||||
//日期轉換
|
||||
historyDay.Timestamp = Convert.ToDateTime(historyDay.Timestamp + ":00:00").ToString("yyyy-MM-dd");
|
||||
powerStationHistoryDays.Add(historyDay);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region step2-4. 計算這個月的所有值總和
|
||||
//日照計
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的日照計所有值的平均】", powerStation.Code, dateNowDay);
|
||||
var pyrheliometerHistorDay = await powerStationRepository.CalcPyrheliometerHistoryDayDataByPowerStationId(dateNowDay, powerStation.Id);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的日照計所有值的平均】", powerStation.Code, dateNowDay);
|
||||
if (pyrheliometerHistorDay != null)
|
||||
{
|
||||
pyrheliometerHistoryDays.Add(pyrheliometerHistorDay);
|
||||
}
|
||||
|
||||
//逆變器
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的逆變器所有值的平均】", powerStation.Code, dateNowDay);
|
||||
var inverterHistoriesDay = await powerStationRepository.CalcInverterHistoryDayDataByPowerStationId(dateNowDay, powerStation.SiteDB, powerStation.Id);
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的逆變器所有值的平均】", powerStation.Code, dateNowDay);
|
||||
if (inverterHistoriesDay != null)
|
||||
{
|
||||
foreach (var inverterHistoryDay in inverterHistoriesDay)
|
||||
{
|
||||
inverterHistoryDay.DC1KW = inverterHistoryDay.DC1W / 1000;
|
||||
inverterHistoryDay.DC2KW = inverterHistoryDay.DC2W / 1000;
|
||||
inverterHistoryDay.DC3KW = inverterHistoryDay.DC3W / 1000;
|
||||
inverterHistoryDay.DC4KW = inverterHistoryDay.DC4W / 1000;
|
||||
inverterHistoryDay.DC5KW = inverterHistoryDay.DC5W / 1000;
|
||||
|
||||
inverterHistoryDay.DCKW = (inverterHistoryDay.DC1W + inverterHistoryDay.DC2W + inverterHistoryDay.DC3W + inverterHistoryDay.DC4W + inverterHistoryDay.DC5W) / 1000;
|
||||
inverterHistoryDay.ACKW = (inverterHistoryDay.AC1W + inverterHistoryDay.AC2W + inverterHistoryDay.AC3W) / 1000;
|
||||
|
||||
allofInverterHistorDays.Add(inverterHistoryDay);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region step3. calcPowerStations UPDATE 到 power_station 資料表
|
||||
List<string> power_station_properties = new List<string>()
|
||||
{
|
||||
"Id",
|
||||
"avg_kwhkwp",
|
||||
"avg_PR",
|
||||
"avg_irradiance"
|
||||
};
|
||||
|
||||
await powerStationRepository.UpdateList(calcAvgPowerStations, power_station_properties);
|
||||
#endregion
|
||||
|
||||
#region step4. 將各電站的每日的資料insert資料表
|
||||
//每日
|
||||
List<string> history_properties_day = new List<string>()
|
||||
{
|
||||
"PowerStationId",
|
||||
"TIMESTAMP",
|
||||
"SITEID",
|
||||
"SITETYPE",
|
||||
"TODAYKWH",
|
||||
"TOTALKWH",
|
||||
"KWHKWP",
|
||||
"PR",
|
||||
"MP",
|
||||
"SolarHour",
|
||||
"MONEY",
|
||||
"CARBON",
|
||||
"TOTALMONEY",
|
||||
"TOTALCARBON"
|
||||
};
|
||||
await powerStationRepository.AddPowerStationHistoryDayList(powerStationHistoryDays, history_properties_day);
|
||||
|
||||
//每日
|
||||
await powerStationRepository.AddPyrheliometerHistoryDayList(pyrheliometerHistoryDays, pyrheliometer_history_properties);
|
||||
|
||||
//每日
|
||||
await powerStationRepository.AddInverterHistoryDayList(allofInverterHistorDays, inverter_history_properties);
|
||||
|
||||
#region step3. 歸檔電站的每月資訊
|
||||
foreach (var powerStation in powerStations)
|
||||
{
|
||||
//判斷這個月是否已存在
|
||||
var dateNowMonth = DateTimeNow.ToString("yyyy-MM");
|
||||
|
||||
@ -254,7 +370,7 @@ namespace SolarPower.Quartz.Jobs
|
||||
var lastmoneyhistorymonth = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 2, "");
|
||||
if (historyMonth != null)
|
||||
{
|
||||
|
||||
|
||||
|
||||
historyMonth.Timestamp = Convert.ToDateTime(historyMonth.Timestamp).ToString("yyyy-MM-dd");
|
||||
historyMonth.MONEY = moneyandcarbonMon.MONEY;
|
||||
@ -309,12 +425,12 @@ namespace SolarPower.Quartz.Jobs
|
||||
//電站該月份的的逆變器歷史資料
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}月份的逆變器歷史資料】", powerStation.Code, dateNowMonth);
|
||||
var exist_inverter_histories = await powerStationRepository.GetInverterHistoryByPowerStationIdAndMonth(dateNowMonth, powerStation.Id);
|
||||
if (exist_inverter_histories.Count == 0 )
|
||||
if (exist_inverter_histories.Count == 0)
|
||||
{ //新增
|
||||
var inverterHistoriesMonth = await powerStationRepository.CalcInverterHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.SiteDB, powerStation.Id);
|
||||
if (inverterHistoriesMonth.Count > 0)
|
||||
{
|
||||
foreach(var inverterHistoryMonth in inverterHistoriesMonth)
|
||||
foreach (var inverterHistoryMonth in inverterHistoriesMonth)
|
||||
{
|
||||
inverterHistoryMonth.DC1KW = inverterHistoryMonth.DC1W / 1000;
|
||||
inverterHistoryMonth.DC2KW = inverterHistoryMonth.DC2W / 1000;
|
||||
@ -354,45 +470,9 @@ namespace SolarPower.Quartz.Jobs
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的逆變器歷史資料】", powerStation.Code, dateNowMonth);
|
||||
}
|
||||
#endregion
|
||||
|
||||
count++;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region step3. calcPowerStations UPDATE 到 power_station 資料表
|
||||
List<string> power_station_properties = new List<string>()
|
||||
{
|
||||
"Id",
|
||||
"avg_kwhkwp",
|
||||
"avg_PR",
|
||||
"avg_irradiance"
|
||||
};
|
||||
|
||||
await powerStationRepository.UpdateList(calcAvgPowerStations, power_station_properties);
|
||||
#endregion
|
||||
|
||||
#region step4. 將各電站的每日及月的資料insert or update 各資料表
|
||||
//每日
|
||||
List<string> history_properties_day = new List<string>()
|
||||
{
|
||||
"PowerStationId",
|
||||
"TIMESTAMP",
|
||||
"SITEID",
|
||||
"SITETYPE",
|
||||
"TODAYKWH",
|
||||
"TOTALKWH",
|
||||
"KWHKWP",
|
||||
"PR",
|
||||
"MP",
|
||||
"SolarHour",
|
||||
"MONEY",
|
||||
"CARBON",
|
||||
"TOTALMONEY",
|
||||
"TOTALCARBON"
|
||||
};
|
||||
|
||||
await powerStationRepository.AddPowerStationHistoryDayList(powerStationHistoryDays, history_properties_day);
|
||||
|
||||
//每月
|
||||
List<string> history_properties_month = new List<string>()
|
||||
{
|
||||
@ -421,18 +501,8 @@ namespace SolarPower.Quartz.Jobs
|
||||
{
|
||||
await powerStationRepository.UpdatePowerStationHistoryMonthList(updatePowerStationHistoryMonths);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region step5. 將各電站的每日及月的日照度資料insert or update 各資料表
|
||||
List<string> pyrheliometer_history_properties = new List<string>()
|
||||
{
|
||||
"PowerStationId",
|
||||
"Timestamp",
|
||||
"Irradiance",
|
||||
"Temperature"
|
||||
};
|
||||
//每日
|
||||
await powerStationRepository.AddPyrheliometerHistoryDayList(pyrheliometerHistoryDays, pyrheliometer_history_properties);
|
||||
|
||||
//每月
|
||||
if (insertPyrheliometerHistoryMonths.Count > 0)
|
||||
@ -447,66 +517,6 @@ namespace SolarPower.Quartz.Jobs
|
||||
#endregion
|
||||
|
||||
#region step6. 將各電站的每日及月的逆變器資料insert or update 各資料表
|
||||
List<string> inverter_history_properties = new List<string>()
|
||||
{
|
||||
"PowerStationId",
|
||||
"TIMESTAMP",
|
||||
"INVERTERID",
|
||||
"Irradiance",
|
||||
"AC1V",
|
||||
"AC1A",
|
||||
"AC1W",
|
||||
"AC1F",
|
||||
"AC1WH",
|
||||
"AC2V",
|
||||
"AC2A",
|
||||
"AC2W",
|
||||
"AC2F",
|
||||
"AC2WH",
|
||||
"AC3V",
|
||||
"AC3A",
|
||||
"AC3W",
|
||||
"AC3F",
|
||||
"AC3WH",
|
||||
"DC1V",
|
||||
"DC1A",
|
||||
"DC1W",
|
||||
"DC1KW",
|
||||
"DC1WH",
|
||||
"DC2V",
|
||||
"DC2A",
|
||||
"DC2W",
|
||||
"DC2KW",
|
||||
"DC2WH",
|
||||
"DC3V",
|
||||
"DC3A",
|
||||
"DC3W",
|
||||
"DC3KW",
|
||||
"DC3WH",
|
||||
"DC4V",
|
||||
"DC4A",
|
||||
"DC4W",
|
||||
"DC4KW",
|
||||
"DC4WH",
|
||||
"DC5V",
|
||||
"DC5A",
|
||||
"DC5W",
|
||||
"DC5KW",
|
||||
"DC5WH",
|
||||
"PR",
|
||||
"RA1",
|
||||
"RA2",
|
||||
"RA3",
|
||||
"RA4",
|
||||
"RA5",
|
||||
"DCKW",
|
||||
"ACKW",
|
||||
"KWH",
|
||||
"TODAYKWH",
|
||||
"KWHKWP",
|
||||
};
|
||||
//每日
|
||||
await powerStationRepository.AddInverterHistoryDayList(allofInverterHistorDays, inverter_history_properties);
|
||||
|
||||
//每月
|
||||
if (insertInverterHistoryMonths.Count > 0)
|
||||
|
||||
@ -25,6 +25,34 @@ namespace SolarPower.Quartz.Jobs
|
||||
{
|
||||
try
|
||||
{
|
||||
//var day_array = new string[] { "15", "16", "17", "18", "19" };
|
||||
////var day_array = new string[] { "15" };
|
||||
//var time_array = new string[] { "00:02", "00:17", "00:32", "00:47",
|
||||
// "01:02", "01:17", "01:32", "01:47",
|
||||
// "02:02", "02:17", "02:32", "02:47",
|
||||
// "03:02", "03:17", "03:32", "03:47",
|
||||
// "04:02", "04:17", "04:32", "04:47",
|
||||
// "05:02", "05:17", "05:32", "05:47",
|
||||
// "06:02", "06:17", "06:32", "06:47",
|
||||
// "07:02", "07:17", "07:32", "07:47",
|
||||
// "08:02", "08:17", "08:32", "08:47",
|
||||
// "09:02", "09:17", "09:32", "09:47",
|
||||
// "10:02", "10:17", "10:32", "10:47",
|
||||
// "11:02", "11:17", "11:32", "11:47",
|
||||
// "12:02", "12:17", "12:32", "12:47",
|
||||
// "13:02", "13:17", "13:32", "13:47",
|
||||
// "14:02", "14:17", "14:32", "14:47",
|
||||
// "15:02", "15:17", "15:32", "15:47",
|
||||
// "16:02", "16:17", "16:32", "16:47",
|
||||
// "17:02", "17:17", "17:32", "17:47",
|
||||
// "18:02", "18:17", "18:32", "18:47",
|
||||
// "19:02", "19:17", "19:32", "19:47",
|
||||
// "20:02", "20:17", "20:32", "20:47",
|
||||
// "21:02", "21:17", "21:32", "21:47",
|
||||
// "22:02", "22:17", "22:32", "22:47",
|
||||
// "23:02", "23:17", "23:32", "23:47",
|
||||
//};
|
||||
|
||||
#region step1. 找出所有電站
|
||||
logger.LogInformation("【CalcInverter15minJob】【開始取得電站資料】");
|
||||
var powerStations = await powerStationRepository.GetAllAsync();
|
||||
@ -36,59 +64,74 @@ namespace SolarPower.Quartz.Jobs
|
||||
|
||||
var DateTimeNow = DateTime.Now;
|
||||
|
||||
var count = 0;
|
||||
|
||||
#region step2. 從電站的DB及電站編號找出該電站的控制器
|
||||
foreach (var powerStation in powerStations)
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
var dateNowTime = DateTimeNow.ToString("yyyy-MM-dd HH:mm");
|
||||
|
||||
var dateNowTime = DateTimeNow.ToString("yyyy-MM-dd HH:mm");
|
||||
//for (var i = 0; i < day_array.Count(); i++)
|
||||
//{
|
||||
// for (var j = 0; j < time_array.Count(); j++)
|
||||
// {
|
||||
//var dateNowTime = string.Format("2021-07-{0} {1}", day_array[i], time_array[j]);
|
||||
|
||||
//取得所有該電站的逆變器
|
||||
logger.LogInformation("【CalcInverter15minJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime);
|
||||
var controllers = await powerStationRepository.GetAllDeviceControllerId(powerStation.Id, powerStation.SiteDB);
|
||||
var inverters = await powerStationRepository.InverterTable(controllers, powerStation.SiteDB);
|
||||
var inverterIds = inverters.Where(x => x.Enabled == 1 && x.Status != 0).Select(x => x.InverterId).ToList();
|
||||
logger.LogInformation("【CalcInverter15minJob】【取得成功電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime);
|
||||
|
||||
var calcInverter15min = new InverterHistory();
|
||||
|
||||
#region step2-1. 計算該電站逆變器每15min 的值
|
||||
var table_name = String.Format("`{0}`.`s{1}01_inv`", powerStation.SiteDB, powerStation.Code);
|
||||
logger.LogInformation("【CalcInverter15minJob】【開始計算電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime);
|
||||
calcInverter15mins = await powerStationRepository.CalcInverterHisyort15minData(dateNowTime, powerStation.SiteDB, table_name, inverterIds);
|
||||
logger.LogInformation("【CalcInverter15minJob】【計算完成電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime);
|
||||
if (calcInverter15mins.Count() > 0)
|
||||
{
|
||||
foreach (var inverterHistory in calcInverter15mins)
|
||||
#region step2. 從電站的DB及電站編號找出該電站的控制器
|
||||
foreach (var powerStation in powerStations)
|
||||
{
|
||||
inverterHistory.TIMESTAMP = Convert.ToDateTime(inverterHistory.TIMESTAMP + ":00").ToString("yyyy-MM-dd HH:mm:ss");
|
||||
inverterHistory.PowerStationId = powerStation.Id;
|
||||
|
||||
|
||||
|
||||
//取得所有該電站的逆變器
|
||||
logger.LogInformation("【CalcInverter15minJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime);
|
||||
var controllers = await powerStationRepository.GetAllDeviceControllerId(powerStation.Id, powerStation.SiteDB);
|
||||
var inverters = await powerStationRepository.InverterTable(controllers, powerStation.SiteDB);
|
||||
var inverterIds = inverters.Where(x => x.Enabled == 1 && x.Status != 0).Select(x => x.InverterId).ToList();
|
||||
logger.LogInformation("【CalcInverter15minJob】【取得成功電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime);
|
||||
|
||||
var calcInverter15min = new InverterHistory();
|
||||
|
||||
#region step2-1. 計算該電站逆變器每15min 的值
|
||||
var table_name = String.Format("s{1}01_inv", powerStation.SiteDB, powerStation.Code);
|
||||
var full_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, table_name);
|
||||
var exist = await powerStationRepository.ExistTable(powerStation.SiteDB, table_name);
|
||||
|
||||
if (!string.IsNullOrEmpty(exist))
|
||||
{
|
||||
logger.LogInformation("【CalcInverter15minJob】【開始計算電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime);
|
||||
calcInverter15mins = await powerStationRepository.CalcInverterHisyort15minData(dateNowTime, powerStation.SiteDB, full_table_name, inverterIds);
|
||||
logger.LogInformation("【CalcInverter15minJob】【計算完成電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime);
|
||||
if (calcInverter15mins.Count() > 0)
|
||||
{
|
||||
foreach (var inverterHistory in calcInverter15mins)
|
||||
{
|
||||
inverterHistory.TIMESTAMP = Convert.ToDateTime(inverterHistory.TIMESTAMP + ":00").ToString("yyyy-MM-dd HH:mm:ss");
|
||||
inverterHistory.PowerStationId = powerStation.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
count++;
|
||||
}
|
||||
#endregion
|
||||
#region step3. 將 inverter INSERT 到 inverter_history_hour 資料表
|
||||
List<string> inverter_history_properties = new List<string>()
|
||||
{
|
||||
"PowerStationId",
|
||||
"INVERTERID",
|
||||
"TIMESTAMP",
|
||||
"KWH",
|
||||
"TODAYKWH",
|
||||
"KWHKWP",
|
||||
};
|
||||
|
||||
await powerStationRepository.AddInverter15minHistory(calcInverter15mins, inverter_history_properties);
|
||||
#endregion
|
||||
// }
|
||||
//}
|
||||
|
||||
#region step3. 將 inverter INSERT 到 inverter_history_hour 資料表
|
||||
List<string> inverter_history_properties = new List<string>()
|
||||
{
|
||||
"PowerStationId",
|
||||
"INVERTERID",
|
||||
"TIMESTAMP",
|
||||
"KWH",
|
||||
"TODAYKWH",
|
||||
"KWHKWP",
|
||||
};
|
||||
|
||||
await powerStationRepository.AddInverter15minHistory(calcInverter15mins, inverter_history_properties);
|
||||
#endregion
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
||||
@ -29,6 +29,10 @@ namespace SolarPower.Quartz.Jobs
|
||||
{
|
||||
try
|
||||
{
|
||||
var DateTimeNow = DateTime.Now;
|
||||
var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH");
|
||||
logger.LogInformation("【CalcPowerStationJob】【任務開始】");
|
||||
|
||||
#region step1. 找出所有電站
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始取得電站資料】");
|
||||
var powerStations = await powerStationRepository.GetAllAsync();
|
||||
@ -43,9 +47,6 @@ namespace SolarPower.Quartz.Jobs
|
||||
List<PowerStation> calcPowerStations = new List<PowerStation>();
|
||||
List<WeatherObservation> weatherObservations = new List<WeatherObservation>();
|
||||
|
||||
var DateTimeNow = DateTime.Now;
|
||||
|
||||
var count = 0;
|
||||
#region 氣象觀測(取資料)
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始取得氣象觀測】");
|
||||
var client = new HttpClient();
|
||||
@ -56,164 +57,165 @@ namespace SolarPower.Quartz.Jobs
|
||||
logger.LogInformation("【CalcPowerStationJob】【取得成功氣象觀測】");
|
||||
#endregion
|
||||
|
||||
|
||||
#region step2. 從電站的DB及電站編號找出該電站的控制器
|
||||
foreach (var powerStation in powerStations)
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var calcPowerStation = new PowerStation();
|
||||
calcPowerStation.Id = powerStation.Id;
|
||||
|
||||
var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH");
|
||||
|
||||
#region step2-1. 取得該電站的當前這小時的歷史資料
|
||||
var table_name = String.Format("`{0}`.s{1}01_station", powerStation.SiteDB, powerStation.Code);
|
||||
var table_name = String.Format("s{1}01_station", powerStation.SiteDB, powerStation.Code);
|
||||
var full_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, table_name);
|
||||
var exist = await powerStationRepository.ExistTable(powerStation.SiteDB, table_name);
|
||||
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
||||
var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, table_name);
|
||||
logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
||||
logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的每小時歷史資料】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(history));
|
||||
var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id,0,dateTime);
|
||||
|
||||
if (history != null)
|
||||
if (!string.IsNullOrEmpty(exist))
|
||||
{
|
||||
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");
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
||||
var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, full_table_name);
|
||||
logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
||||
logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的每小時歷史資料】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(history));
|
||||
var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime);
|
||||
|
||||
#region 計算單一電站每小時發電量、發電金額等資料
|
||||
|
||||
#region 發電量
|
||||
//每小時發電量(直接填寫
|
||||
calcPowerStation.kwh = history.KWH;
|
||||
//今日發電量(直接填寫
|
||||
calcPowerStation.Today_kWh = history.TodayKWh;
|
||||
//總發電量(直接填寫
|
||||
calcPowerStation.Total_kWh = history.TotalKWH;
|
||||
#endregion
|
||||
|
||||
#region 發電金額
|
||||
//發電金額
|
||||
switch (powerStation.SolarType)
|
||||
if (history != null)
|
||||
{
|
||||
case (int)SolarTypeEnum.SelfSold: //自建躉售
|
||||
//今日發電金額 計算方式:todaykWh * 授電費率
|
||||
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
|
||||
history.MONEY = history.KWH * powerStation.PowerRate;
|
||||
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");
|
||||
|
||||
//總發電金額 計算方式:totalkWh * 授電費率
|
||||
calcPowerStation.Total_Money = history.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;
|
||||
#region 計算單一電站每小時發電量、發電金額等資料
|
||||
|
||||
foreach (var landBuilding in landBuildings)
|
||||
{
|
||||
sumLeaseRate += landBuilding.LeaseRate;
|
||||
}
|
||||
avgLeaseRate = sumLeaseRate / landBuildings.Count();
|
||||
#region 發電量
|
||||
//每小時發電量(直接填寫
|
||||
calcPowerStation.kwh = history.KWH;
|
||||
//今日發電量(直接填寫
|
||||
calcPowerStation.Today_kWh = history.TodayKWh;
|
||||
//總發電量(直接填寫
|
||||
calcPowerStation.Total_kWh = history.TotalKWH;
|
||||
#endregion
|
||||
|
||||
//今日發電金額計算方式:todaykWh * 出借費率(各個土地房屋租借比率平均)
|
||||
calcPowerStation.Today_Money = history.TodayKWh * avgLeaseRate;
|
||||
#region 發電金額
|
||||
//發電金額
|
||||
switch (powerStation.SolarType)
|
||||
{
|
||||
case (int)SolarTypeEnum.SelfSold: //自建躉售
|
||||
//今日發電金額 計算方式:todaykWh * 授電費率
|
||||
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
|
||||
history.MONEY = history.KWH * powerStation.PowerRate;
|
||||
|
||||
history.MONEY = history.KWH * avgLeaseRate;
|
||||
//總發電金額 計算方式:totalkWh * 授電費率
|
||||
calcPowerStation.Total_Money = history.TotalKWH * avgLeaseRate;
|
||||
break;
|
||||
case (int)SolarTypeEnum.SelfUse: //自建自用
|
||||
//今日發電金額 計算方式:todaykWh * 授電費率
|
||||
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
|
||||
//總發電金額 計算方式:totalkWh * 授電費率
|
||||
calcPowerStation.Total_Money = history.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;
|
||||
|
||||
history.MONEY = history.KWH * powerStation.PowerRate;
|
||||
foreach (var landBuilding in landBuildings)
|
||||
{
|
||||
sumLeaseRate += landBuilding.LeaseRate;
|
||||
}
|
||||
avgLeaseRate = sumLeaseRate / landBuildings.Count();
|
||||
|
||||
//總發電金額 計算方式:totalkWh * 授電費率
|
||||
calcPowerStation.Total_Money = history.TotalKWH * powerStation.PowerRate;
|
||||
break;
|
||||
//今日發電金額計算方式:todaykWh * 出借費率(各個土地房屋租借比率平均)
|
||||
calcPowerStation.Today_Money = history.TodayKWh * avgLeaseRate;
|
||||
|
||||
history.MONEY = history.KWH * avgLeaseRate;
|
||||
//總發電金額 計算方式:totalkWh * 授電費率
|
||||
calcPowerStation.Total_Money = history.TotalKWH * avgLeaseRate;
|
||||
break;
|
||||
case (int)SolarTypeEnum.SelfUse: //自建自用
|
||||
//今日發電金額 計算方式:todaykWh * 授電費率
|
||||
calcPowerStation.Today_Money = history.TodayKWh * powerStation.PowerRate;
|
||||
|
||||
history.MONEY = history.KWH * powerStation.PowerRate;
|
||||
|
||||
//總發電金額 計算方式:totalkWh * 授電費率
|
||||
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(await powerStationRepository.GetOneVariableByName("CarbonRate"));
|
||||
|
||||
//今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
|
||||
calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate;
|
||||
|
||||
history.CARBON = history.KWH * carbonRate;
|
||||
//總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
|
||||
calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
|
||||
history.TODAYCARBON = lastmoneyhistorybyhour.TODAYCARBON + history.KWH * carbonRate;
|
||||
history.TOTALCARBON = lastmoneyhistorybyhour.TOTALCARBON + history.KWH * carbonRate;
|
||||
history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate;
|
||||
history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate;
|
||||
#endregion
|
||||
|
||||
#region 發電時間
|
||||
calcPowerStation.SolarHour = history.SolarHour;
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
powerStationHistoriesHour.Add(history);
|
||||
|
||||
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region kWh/kWp
|
||||
//直接填寫
|
||||
calcPowerStation.Today_kwhkwp = history.KWHKWP;
|
||||
#endregion
|
||||
#region step2-2. 取得該電站的當前這小時的日照度歷史資料
|
||||
//1. 找出該電站所有日照計設備(包含共享
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的日照計設備資訊】", powerStation.Code, dateTime);
|
||||
var deviceInfos = await powerStationRepository.GetListPyrheliometerByPowerStationId(powerStation.Id, powerStation.SiteDB);
|
||||
logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的日照計設備資訊】", powerStation.Code, dateTime);
|
||||
logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的日照計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(deviceInfos));
|
||||
|
||||
#region PR
|
||||
//直接填寫
|
||||
calcPowerStation.Today_PR = history.PR;
|
||||
#endregion
|
||||
|
||||
#region 減碳量
|
||||
carbonRate = Convert.ToDouble(await powerStationRepository.GetOneVariableByName("CarbonRate"));
|
||||
|
||||
//今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
|
||||
calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate;
|
||||
|
||||
history.CARBON = history.KWH * carbonRate;
|
||||
//總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
|
||||
calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
|
||||
#endregion
|
||||
history.TODAYCARBON = lastmoneyhistorybyhour.TODAYCARBON + history.KWH * carbonRate;
|
||||
history.TOTALCARBON = lastmoneyhistorybyhour.TOTALCARBON + history.KWH * carbonRate;
|
||||
history.TODAYMONEY = lastmoneyhistorybyhour.TODAYMONEY + history.KWH * powerStation.PowerRate;
|
||||
history.TOTALMONEY = lastmoneyhistorybyhour.TOTALMONEY + history.KWH * powerStation.PowerRate;
|
||||
#endregion
|
||||
|
||||
powerStationHistoriesHour.Add(history);
|
||||
|
||||
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region step2-2. 取得該電站的當前這小時的日照度歷史資料
|
||||
//1. 找出該電站所有日照計設備(包含共享
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的日照計設備資訊】", powerStation.Code, dateTime);
|
||||
var deviceInfos = await powerStationRepository.GetListPyrheliometerByPowerStationId(powerStation.Id, powerStation.SiteDB);
|
||||
logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的日照計設備資訊】", powerStation.Code, dateTime);
|
||||
logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的日照計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(deviceInfos));
|
||||
|
||||
if (deviceInfos != null)
|
||||
{
|
||||
//2. 計算該電站所有日照計設的每小時的平均在依照日照計數量平均
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的日照計的日照度】", powerStation.Code, dateTime);
|
||||
var pyrheliometerHistory = await powerStationRepository.GetPyrheliometerHistoryPerHour(dateTime, deviceInfos, 0);
|
||||
|
||||
if (pyrheliometerHistory != null)
|
||||
if (deviceInfos != null)
|
||||
{
|
||||
calcPowerStation.Today_irradiance = pyrheliometerHistory.Irradiance;
|
||||
//2. 計算該電站所有日照計設的每小時的平均在依照日照計數量平均
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的日照計的日照度】", powerStation.Code, dateTime);
|
||||
var pyrheliometerHistory = await powerStationRepository.GetPyrheliometerHistoryPerHour(dateTime, deviceInfos, 0);
|
||||
|
||||
pyrheliometerHistory.Timestamp = Convert.ToDateTime(pyrheliometerHistory.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
|
||||
pyrheliometerHistory.PowerStationId = powerStation.Id;
|
||||
pyrheliometerHistoriesHour.Add(pyrheliometerHistory);
|
||||
if (pyrheliometerHistory != null)
|
||||
{
|
||||
calcPowerStation.Today_irradiance = pyrheliometerHistory.Irradiance;
|
||||
|
||||
pyrheliometerHistory.Timestamp = Convert.ToDateTime(pyrheliometerHistory.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
|
||||
pyrheliometerHistory.PowerStationId = powerStation.Id;
|
||||
pyrheliometerHistoriesHour.Add(pyrheliometerHistory);
|
||||
}
|
||||
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的日照計的日照度】", powerStation.Code, dateTime);
|
||||
}
|
||||
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的日照計的日照度】", powerStation.Code, dateTime);
|
||||
}
|
||||
//2. 計算該電站所有溫度計設的每小時的平均在依照溫度計數量平均
|
||||
// 找出該電站所有溫度計設備(包含共享
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的溫度計設備資訊】", powerStation.Code, dateTime);
|
||||
var tempdeviceInfos = await powerStationRepository.GetListTempByPowerStationId(powerStation.Id, powerStation.SiteDB);
|
||||
logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的溫度計設備資訊】", powerStation.Code, dateTime);
|
||||
logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的溫度計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(tempdeviceInfos));
|
||||
if (tempdeviceInfos != null)
|
||||
{
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的溫度計的平均溫度】", powerStation.Code, dateTime);
|
||||
var tempHistory = await powerStationRepository.GetPyrheliometerHistoryPerHour(dateTime, tempdeviceInfos, 1);
|
||||
if (tempHistory != null)
|
||||
//2. 計算該電站所有溫度計設的每小時的平均在依照溫度計數量平均
|
||||
// 找出該電站所有溫度計設備(包含共享
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的溫度計設備資訊】", powerStation.Code, dateTime);
|
||||
var tempdeviceInfos = await powerStationRepository.GetListTempByPowerStationId(powerStation.Id, powerStation.SiteDB);
|
||||
logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的溫度計設備資訊】", powerStation.Code, dateTime);
|
||||
logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的溫度計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(tempdeviceInfos));
|
||||
if (tempdeviceInfos != null)
|
||||
{
|
||||
tempHistory.Timestamp = Convert.ToDateTime(tempHistory.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
|
||||
tempHistory.PowerStationId = powerStation.Id;
|
||||
TempHistoriesHour.Add(tempHistory);
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的溫度計的平均溫度】", powerStation.Code, dateTime);
|
||||
var tempHistory = await powerStationRepository.GetPyrheliometerHistoryPerHour(dateTime, tempdeviceInfos, 1);
|
||||
if (tempHistory != null)
|
||||
{
|
||||
tempHistory.Timestamp = Convert.ToDateTime(tempHistory.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
|
||||
tempHistory.PowerStationId = powerStation.Id;
|
||||
TempHistoriesHour.Add(tempHistory);
|
||||
|
||||
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的溫度計的平均溫度】", powerStation.Code, dateTime);
|
||||
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的溫度計的平均溫度】", powerStation.Code, dateTime);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region step2-3. 計算該電站所有逆變器每小時值
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateTime);
|
||||
@ -223,29 +225,34 @@ namespace SolarPower.Quartz.Jobs
|
||||
logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateTime);
|
||||
logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的逆變器設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(inverterIds));
|
||||
|
||||
var inverter_table_name = String.Format("`{0}`.s{1}01_inv", powerStation.SiteDB, powerStation.Code);
|
||||
var inverter_table_name = String.Format("s{0}01_inv", powerStation.Code);
|
||||
var full_inverter_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, inverter_table_name);
|
||||
var exist_inverter_table = await powerStationRepository.ExistTable(powerStation.SiteDB, full_inverter_table_name);
|
||||
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的逆變器的資訊】", powerStation.Code, dateTime);
|
||||
inverterHistories = await powerStationRepository.CalcInverterHisyortHourData(dateTime, powerStation.SiteDB, inverter_table_name, inverterIds);
|
||||
//取得日照計要找的欄位資訊
|
||||
var pyrheliometer = await powerStationRepository.GetFirstPyrheliometerInfo(powerStation.Id, powerStation.SiteDB);
|
||||
var pyrheliometerValue = await powerStationRepository.GetFirstPyrheliometerValue(dateTime, pyrheliometer.DBName, pyrheliometer.TableName, pyrheliometer.ColName);
|
||||
foreach (var inverterHistory in inverterHistories)
|
||||
if (!string.IsNullOrEmpty(exist_inverter_table))
|
||||
{
|
||||
inverterHistory.Irradiance = pyrheliometerValue;
|
||||
inverterHistory.DC1KW = inverterHistory.DC1W / 1000;
|
||||
inverterHistory.DC2KW = inverterHistory.DC2W / 1000;
|
||||
inverterHistory.DC3KW = inverterHistory.DC3W / 1000;
|
||||
inverterHistory.DC4KW = inverterHistory.DC4W / 1000;
|
||||
inverterHistory.DC5KW = inverterHistory.DC5W / 1000;
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的逆變器的資訊】", powerStation.Code, dateTime);
|
||||
inverterHistories = await powerStationRepository.CalcInverterHisyortHourData(dateTime, powerStation.SiteDB, full_inverter_table_name, inverterIds);
|
||||
//取得日照計要找的欄位資訊
|
||||
var pyrheliometer = await powerStationRepository.GetFirstPyrheliometerInfo(powerStation.Id, powerStation.SiteDB);
|
||||
var pyrheliometerValue = await powerStationRepository.GetFirstPyrheliometerValue(dateTime, pyrheliometer.DBName, pyrheliometer.TableName, pyrheliometer.ColName);
|
||||
foreach (var inverterHistory in inverterHistories)
|
||||
{
|
||||
inverterHistory.Irradiance = pyrheliometerValue;
|
||||
inverterHistory.DC1KW = inverterHistory.DC1W / 1000;
|
||||
inverterHistory.DC2KW = inverterHistory.DC2W / 1000;
|
||||
inverterHistory.DC3KW = inverterHistory.DC3W / 1000;
|
||||
inverterHistory.DC4KW = inverterHistory.DC4W / 1000;
|
||||
inverterHistory.DC5KW = inverterHistory.DC5W / 1000;
|
||||
|
||||
inverterHistory.DCKW = (inverterHistory.DC1W + inverterHistory.DC2W + inverterHistory.DC3W + inverterHistory.DC4W + inverterHistory.DC5W) / 1000;
|
||||
inverterHistory.ACKW = (inverterHistory.AC1W + inverterHistory.AC2W + inverterHistory.AC3W) / 1000;
|
||||
inverterHistory.DCKW = (inverterHistory.DC1W + inverterHistory.DC2W + inverterHistory.DC3W + inverterHistory.DC4W + inverterHistory.DC5W) / 1000;
|
||||
inverterHistory.ACKW = (inverterHistory.AC1W + inverterHistory.AC2W + inverterHistory.AC3W) / 1000;
|
||||
|
||||
inverterHistory.TIMESTAMP = Convert.ToDateTime(inverterHistory.TIMESTAMP + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
|
||||
inverterHistory.PowerStationId = powerStation.Id;
|
||||
inverterHistory.TIMESTAMP = Convert.ToDateTime(inverterHistory.TIMESTAMP + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
|
||||
inverterHistory.PowerStationId = powerStation.Id;
|
||||
}
|
||||
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的逆變器的資訊】", powerStation.Code, dateTime);
|
||||
}
|
||||
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的逆變器的資訊】", powerStation.Code, dateTime);
|
||||
#endregion
|
||||
|
||||
#region 確認是否有觀測站(沒有則新增)
|
||||
@ -297,8 +304,6 @@ namespace SolarPower.Quartz.Jobs
|
||||
|
||||
weatherObservations.Add(weatherObservation);
|
||||
calcPowerStations.Add(calcPowerStation);
|
||||
|
||||
count++;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -361,6 +366,7 @@ namespace SolarPower.Quartz.Jobs
|
||||
"today_carbon",
|
||||
"total_carbon",
|
||||
"today_irradiance",
|
||||
"SolarHour",
|
||||
"WeathersStationId",
|
||||
"TodayWeatherTemp",
|
||||
"TodayWeather",
|
||||
@ -440,6 +446,8 @@ namespace SolarPower.Quartz.Jobs
|
||||
"Temp"
|
||||
};
|
||||
await powerStationRepository.AddWeatherObservation(weatherObservations, weather_observation_properties);
|
||||
|
||||
logger.LogInformation("【CalcPowerStationJob】【任務完成】");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
@ -315,9 +315,12 @@ namespace SolarPower.Repository.Implement
|
||||
{
|
||||
try
|
||||
{
|
||||
var sql = @$"SELECT * FROM inverter_history_15min WHERE PowerStationId = @PowerStationId AND DATE_FORMAT(TIMESTAMP, '%Y-%m-%d') = @DateTime";
|
||||
var startDateTime = dateTime + " 05:00";
|
||||
var endDataTime = dateTime + " 19:00";
|
||||
|
||||
result = (await conn.QueryAsync<InverterHistory>(sql, new { PowerStationId = powerStationId, DateTime = dateTime })).ToList();
|
||||
var sql = @$"SELECT * FROM inverter_history_15min WHERE PowerStationId = @PowerStationId AND DATE_FORMAT(TIMESTAMP, '%Y-%m-%d %H:%i') BETWEEN @StartDateTime AND @EndDateTime";
|
||||
|
||||
result = (await conn.QueryAsync<InverterHistory>(sql, new { PowerStationId = powerStationId, StartDateTime = startDateTime, EndDateTime = endDataTime })).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
@ -2630,7 +2630,7 @@ namespace SolarPower.Repository.Implement
|
||||
LEFT JOIN (
|
||||
SELECT MAX(FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i')) AS TIMESTAMP,
|
||||
sub_inv.INVERTERID,
|
||||
SUM(sub_inv.WH)/1000 AS KWH
|
||||
AVG(sub_inv.WH)/1000 AS KWH
|
||||
FROM {table_name} sub_inv
|
||||
WHERE FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') BETWEEN @StartDateTime AND @EndDateTime
|
||||
AND sub_inv.INVERTERID IN @InverterIds
|
||||
@ -2738,7 +2738,7 @@ namespace SolarPower.Repository.Implement
|
||||
SELECT
|
||||
FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H') AS TIMESTAMP,
|
||||
inv.INVERTERID,
|
||||
SUM(inv.WH)/1000 AS KWH
|
||||
AVG(inv.WH)/1000 AS KWH
|
||||
FROM {table_name} inv
|
||||
WHERE DATE_FORMAT(FROM_UNIXTIME(inv.TIMESTAMP/1000), '%Y-%m-%d %H') = @DateTime
|
||||
AND inv.INVERTERID IN @InverterIds
|
||||
@ -2795,7 +2795,7 @@ namespace SolarPower.Repository.Implement
|
||||
FROM {db_name}.{table_name}
|
||||
WHERE FROM_UNIXTIME(TIMESTAMP/1000, '%Y-%m-%d %H') = @DateTime";
|
||||
|
||||
result = await conn.QueryFirstAsync<double>(sql, new { DateTime = dateTime });
|
||||
result = await conn.QueryFirstOrDefaultAsync<double>(sql, new { DateTime = dateTime });
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@ -3303,5 +3303,24 @@ namespace SolarPower.Repository.Implement
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> ExistTable(string db_name,string table_name)
|
||||
{
|
||||
string result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = @DBName AND TABLE_NAME = @TableName;";
|
||||
|
||||
result = await conn.QueryFirstOrDefaultAsync<string>(sql, new { DBName = db_name, TableName = table_name });
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -537,5 +537,6 @@ namespace SolarPower.Repository.Interface
|
||||
Task<NowWeather> SelectNowWeather(int CityId);
|
||||
Task<MoneyAndCarbon> GetMoneyAndCarbonWithHistoryHour(int powerstationId, string dateTime, int type);
|
||||
Task<MoneyAndCarbon> GetLastMoneyAndCarbonInHour(int powerstationId,int type,string time);
|
||||
Task<string> ExistTable(string db_name, string table_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,6 +157,7 @@
|
||||
var groupType = 0; //0:日 1:月 2:年 3:歷年
|
||||
var historyRange = "";
|
||||
var selectInverterkwhBarType = 0;
|
||||
var HeapMapXAxis = [];
|
||||
|
||||
$(function () {
|
||||
var url = new URL(location.href);
|
||||
@ -1776,6 +1777,7 @@
|
||||
}
|
||||
|
||||
HeatMap = rel.data;
|
||||
HeapMapXAxis = HeatMap.xAxis
|
||||
|
||||
|
||||
myseries = Object.keys(HeatMap.series).map(function (key) {
|
||||
@ -1793,14 +1795,14 @@
|
||||
Highcharts.chart('container', {
|
||||
chart: {
|
||||
type: 'heatmap',
|
||||
height: 600
|
||||
},
|
||||
|
||||
title: {
|
||||
text: '逆變器單日kWhkWp'
|
||||
},
|
||||
|
||||
xAxis: {
|
||||
categories: HeatMap.xAxis
|
||||
categories: HeatMap.xAxisOnTime
|
||||
},
|
||||
yAxis: {
|
||||
categories: HeatMap.yAxis,
|
||||
@ -1808,6 +1810,7 @@
|
||||
},
|
||||
colorAxis: {
|
||||
min: 0,
|
||||
max: 1,
|
||||
minColor: '#0000FF',
|
||||
maxColor: '#FF0000',
|
||||
stops: [
|
||||
@ -1822,11 +1825,11 @@
|
||||
verticalAlign: 'top',
|
||||
|
||||
},*@
|
||||
|
||||
tooltip: {
|
||||
formatter: function () {
|
||||
return '<b>' + getPointCategoryName(this.point, 'x') + '</b> sold <br><b>' +
|
||||
this.point.value + '</b> items on <br><b>' + getPointCategoryName(this.point, 'y') + '</b>';
|
||||
return '<b>' + getPointCategoryName(this.point, 'y') + '</b><br>' +
|
||||
'<span>' + getPointCategoryName(this.point, 'x') + '</span><br>' +
|
||||
'<b style = "color:rgb(103, 180, 172);" >' + this.point.value + '</b>';
|
||||
}
|
||||
},
|
||||
|
||||
@ -1843,6 +1846,10 @@
|
||||
var series = point.series,
|
||||
isY = dimension === 'y',
|
||||
axis = series[isY ? 'yAxis' : 'xAxis'];
|
||||
|
||||
if (!isY) {
|
||||
axis.categories = HeapMapXAxis;
|
||||
}
|
||||
return axis.categories[point[isY ? 'y' : 'x']];
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user