1. 修改背景執行

2. bug fix
This commit is contained in:
Kai 2021-07-20 20:33:32 +08:00
parent 6bcdb90104
commit 0d552ad69b
9 changed files with 581 additions and 427 deletions

View File

@ -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;
@ -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 lable in inverterkwhBar.Labels)
{
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 lable in inverterkwhBar.Labels)
{
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 lable in inverterkwhBar.Labels)
{
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 lable in inverterkwhBar.Labels)
{
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;
}

View File

@ -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; } //數組
}

View File

@ -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,22 +201,21 @@ 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);
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);
var history = await powerStationRepository.CalcAvgPowerStationHistory30day(dateNowDay, table_name);
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)
@ -173,7 +239,6 @@ namespace SolarPower.Quartz.Jobs
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的30天平均資料】", powerStation.Code, dateNowDay);
}
#endregion
#region step2-2 30
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的30天日照計平均資料】", powerStation.Code, dateNowDay);
@ -187,11 +252,15 @@ namespace SolarPower.Quartz.Jobs
calcAvgPowerStations.Add(calcPowerStation);
#endregion
}
#endregion
#region step2-3.
if (!string.IsNullOrEmpty(exist))
{
//電站資訊
logger.LogInformation("【CalcAvgPowerStationJob】【開始取得電站[{0}]在{1}的所有值的總和】", powerStation.Code, dateNowDay);
var historyDay = await powerStationRepository.GetLastOnePowerStationHistoryByDay(dateNowDay, table_name);
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");
@ -206,6 +275,9 @@ namespace SolarPower.Quartz.Jobs
//historyDay.TODAYMONEY = lastmoneyhistory.TODAYMONEY ;
historyDay.TOTALCARBON = lastmoneyhistory.TOTALCARBON + moneyandcarbon.CARBON;
historyDay.TOTALMONEY = lastmoneyhistory.TOTALMONEY + moneyandcarbon.MONEY;
//日期轉換
historyDay.Timestamp = Convert.ToDateTime(historyDay.Timestamp + ":00:00").ToString("yyyy-MM-dd");
powerStationHistoryDays.Add(historyDay);
}
@ -239,8 +311,52 @@ namespace SolarPower.Quartz.Jobs
}
}
#endregion
}
}
#endregion
#region step2-4.
#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");
@ -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)

View File

@ -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,17 +64,20 @@ namespace SolarPower.Quartz.Jobs
var DateTimeNow = DateTime.Now;
var count = 0;
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]);
#region step2. DB及電站編號找出該電站的控制器
foreach (var powerStation in powerStations)
{
if (count > 0)
{
break;
}
var dateNowTime = DateTimeNow.ToString("yyyy-MM-dd HH:mm");
//取得所有該電站的逆變器
logger.LogInformation("【CalcInverter15minJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime);
@ -58,9 +89,14 @@ namespace SolarPower.Quartz.Jobs
var calcInverter15min = new InverterHistory();
#region step2-1. 15min
var table_name = String.Format("`{0}`.`s{1}01_inv`", powerStation.SiteDB, powerStation.Code);
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, table_name, inverterIds);
calcInverter15mins = await powerStationRepository.CalcInverterHisyort15minData(dateNowTime, powerStation.SiteDB, full_table_name, inverterIds);
logger.LogInformation("【CalcInverter15minJob】【計算完成電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime);
if (calcInverter15mins.Count() > 0)
{
@ -70,9 +106,12 @@ namespace SolarPower.Quartz.Jobs
inverterHistory.PowerStationId = powerStation.Id;
}
}
}
#endregion
count++;
}
#endregion
@ -89,6 +128,10 @@ namespace SolarPower.Quartz.Jobs
await powerStationRepository.AddInverter15minHistory(calcInverter15mins, inverter_history_properties);
#endregion
// }
//}
}
catch (Exception exception)

View File

@ -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,25 +57,21 @@ 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);
if (!string.IsNullOrEmpty(exist))
{
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, table_name);
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);
@ -158,13 +155,17 @@ namespace SolarPower.Quartz.Jobs
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
#region
calcPowerStation.SolarHour = history.SolarHour;
#endregion
#endregion
powerStationHistoriesHour.Add(history);
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
@ -214,6 +215,7 @@ namespace SolarPower.Quartz.Jobs
}
}
#endregion
}
#region step2-3.
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateTime);
@ -223,10 +225,14 @@ 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);
if (!string.IsNullOrEmpty(exist_inverter_table))
{
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的逆變器的資訊】", powerStation.Code, dateTime);
inverterHistories = await powerStationRepository.CalcInverterHisyortHourData(dateTime, powerStation.SiteDB, inverter_table_name, inverterIds);
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);
@ -246,6 +252,7 @@ namespace SolarPower.Quartz.Jobs
inverterHistory.PowerStationId = powerStation.Id;
}
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)
{

View File

@ -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)
{

View File

@ -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;
}
}
}
}

View File

@ -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);
}
}

View File

@ -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']];
}