Merge branch 'master' into Willy
This commit is contained in:
commit
cf48a1da16
@ -77,7 +77,7 @@ namespace SolarPower.Controllers
|
||||
|
||||
var temp = new List<PowerStationDevice>();
|
||||
temp.Add(powerStation);
|
||||
foreach(var device in psName_Group)
|
||||
foreach (var device in psName_Group)
|
||||
{
|
||||
temp.Add(device);
|
||||
}
|
||||
@ -109,26 +109,227 @@ namespace SolarPower.Controllers
|
||||
try
|
||||
{
|
||||
AnalysisDevice analysisDevice = new AnalysisDevice();
|
||||
analysisDevice.Series = new List<DeviceHistoryInfo>();
|
||||
|
||||
//先將欲查詢的設備找出設備的資料庫欄位
|
||||
var device_powerStationId_Group = post.DeviceIdInfos.GroupBy(x => x.PowerStationId).ToList();
|
||||
List<Device> devices = new List<Device>();
|
||||
foreach(var psId_Group in device_powerStationId_Group)
|
||||
Dictionary<int, List<Device>> deviceDic = new Dictionary<int, List<Device>>();
|
||||
List<int> selected_powerStationIds = new List<int>();
|
||||
foreach (var psId_Group in device_powerStationId_Group)
|
||||
{
|
||||
var powerStation = await powerStationRepository.GetOneAsync(psId_Group.Key);
|
||||
|
||||
//區分電站總覽or設備
|
||||
selected_powerStationIds = psId_Group.Where(x => x.DeviceType == "PWS").Select(x => Convert.ToInt32(x.DeviceId)).ToList();
|
||||
var selected_device = psId_Group.Where(x => x.DeviceType != "PWS").Select(x => x.DeviceId).ToList();
|
||||
|
||||
//var temp_device = await powerStationRepository.GetDeviceByPowerStationIdAndDeviceIds(powerStation.SiteDB, powerStation.Id, selected_device);
|
||||
|
||||
//devices.AddRange(temp_device);
|
||||
var temp_device = await powerStationRepository.GetDeviceByPowerStationIdAndDeviceIds(powerStation.SiteDB, powerStation.Id, selected_device);
|
||||
if (temp_device.Count() > 0)
|
||||
{
|
||||
deviceDic.Add(psId_Group.Key, temp_device);
|
||||
}
|
||||
}
|
||||
|
||||
if(post.SearchType == 0)
|
||||
{ //單日
|
||||
analysisDevice.MultipleYaxes = new Dictionary<string, string>()
|
||||
{
|
||||
{ "KWH", "發電量"},
|
||||
{ "Irradiance", "日照度"},
|
||||
{ "KWHKWP", "發電小時"},
|
||||
{ "PR", "PR %"},
|
||||
{ "SolarHour", "日照小時"},
|
||||
{ "ModelTemperature", "模組溫度"},
|
||||
{ "Temperature", "環境溫度計"},
|
||||
{ "Humidity", "濕度"},
|
||||
{ "Vane", "風速"},
|
||||
{ "Dust", "落塵%"},
|
||||
};
|
||||
|
||||
var XAxis = new List<string>();
|
||||
|
||||
//電站資料
|
||||
var powerStationHistories = await powerStationRepository.GetPowerStationHistory(post.SelectedDate, post.SearchType, selected_powerStationIds);
|
||||
|
||||
XAxis.AddRange(powerStationHistories.Select(x => x.Timestamp).Distinct().ToList());
|
||||
|
||||
var powerStationHistories_Id_Group = powerStationHistories.GroupBy(x => x.PowerStationId).ToList();
|
||||
|
||||
foreach (var item in powerStationHistories_Id_Group)
|
||||
{
|
||||
var powerStation = await powerStationRepository.GetOneAsync(item.Key);
|
||||
|
||||
var temp_item = item.OrderBy(x => x.Timestamp).ToList();
|
||||
|
||||
DeviceHistoryInfo Irradiance = new DeviceHistoryInfo();
|
||||
Irradiance.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["Irradiance"]);
|
||||
Irradiance.YaxesKey = "Irradiance";
|
||||
Irradiance.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
{
|
||||
Irradiance.Values.Add(history.Irradiance);
|
||||
}
|
||||
else
|
||||
{
|
||||
Irradiance.Values.Add(0);
|
||||
}
|
||||
}
|
||||
analysisDevice.Series.Add(Irradiance);
|
||||
|
||||
DeviceHistoryInfo KWH = new DeviceHistoryInfo();
|
||||
KWH.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["KWH"]);
|
||||
KWH.YaxesKey = "KWH";
|
||||
KWH.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
{
|
||||
KWH.Values.Add(Math.Round(history.KWH, 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
KWH.Values.Add(0);
|
||||
}
|
||||
}
|
||||
analysisDevice.Series.Add(KWH);
|
||||
|
||||
DeviceHistoryInfo solarHour = new DeviceHistoryInfo();
|
||||
solarHour.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["SolarHour"]);
|
||||
solarHour.YaxesKey = "SolarHour";
|
||||
solarHour.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
{
|
||||
solarHour.Values.Add(Math.Round(history.SolarHour, 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
solarHour.Values.Add(0);
|
||||
}
|
||||
}
|
||||
analysisDevice.Series.Add(solarHour);
|
||||
|
||||
DeviceHistoryInfo KWHKWP = new DeviceHistoryInfo();
|
||||
KWHKWP.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["KWHKWP"]);
|
||||
KWHKWP.YaxesKey = "KWHKWP";
|
||||
KWHKWP.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
{
|
||||
KWHKWP.Values.Add(Math.Round(history.KWHKWP, 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
KWHKWP.Values.Add(0);
|
||||
}
|
||||
}
|
||||
analysisDevice.Series.Add(KWHKWP);
|
||||
|
||||
DeviceHistoryInfo PR = new DeviceHistoryInfo();
|
||||
PR.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["PR"]);
|
||||
PR.YaxesKey = "PR";
|
||||
PR.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
{
|
||||
PR.Values.Add(Math.Round(history.PR, 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
PR.Values.Add(0);
|
||||
}
|
||||
}
|
||||
analysisDevice.Series.Add(PR);
|
||||
|
||||
DeviceHistoryInfo modelTemperature = new DeviceHistoryInfo();
|
||||
modelTemperature.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["ModelTemperature"]);
|
||||
modelTemperature.YaxesKey = "ModelTemperature";
|
||||
modelTemperature.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
{
|
||||
modelTemperature.Values.Add(Math.Round(history.Temperature, 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
modelTemperature.Values.Add(0);
|
||||
}
|
||||
}
|
||||
analysisDevice.Series.Add(modelTemperature);
|
||||
}
|
||||
|
||||
//設備資料
|
||||
foreach (var devices in deviceDic)
|
||||
{
|
||||
var result = await powerStationRepository.GetSensorAvgByDevices(post.SelectedDate, post.SearchType, devices.Value);
|
||||
|
||||
foreach (var rows in result)
|
||||
{
|
||||
var fields = rows as IDictionary<string, object>;
|
||||
XAxis.Add(fields["TIMESTAMP"].ToString());
|
||||
}
|
||||
|
||||
|
||||
foreach (var device in devices.Value)
|
||||
{
|
||||
DeviceHistoryInfo deviceHistoryInfo = new DeviceHistoryInfo();
|
||||
var suffix = "";
|
||||
var YaxesKey = "";
|
||||
switch (device.Type)
|
||||
{
|
||||
case "PYR": //日照計
|
||||
suffix = analysisDevice.MultipleYaxes["Irradiance"];
|
||||
YaxesKey = "Irradiance";
|
||||
break;
|
||||
case "ETR": //環境溫度計
|
||||
suffix = analysisDevice.MultipleYaxes["Temperature"];
|
||||
YaxesKey = "Temperature";
|
||||
break;
|
||||
case "MTR": //模組溫度計
|
||||
suffix = analysisDevice.MultipleYaxes["ModelTemperature"];
|
||||
YaxesKey = "ModelTemperature";
|
||||
break;
|
||||
case "VAN": //風速計
|
||||
suffix = analysisDevice.MultipleYaxes["Vane"];
|
||||
YaxesKey = "Vane";
|
||||
break;
|
||||
case "FOM": //落塵計
|
||||
suffix = analysisDevice.MultipleYaxes["Dust"];
|
||||
YaxesKey = "Dust";
|
||||
break;
|
||||
case "EMM": //環境濕度計
|
||||
suffix = analysisDevice.MultipleYaxes["Humidity"];
|
||||
YaxesKey = "Humidity";
|
||||
break;
|
||||
default:
|
||||
suffix = string.Empty;
|
||||
break;
|
||||
}
|
||||
deviceHistoryInfo.Name = string.Format("{0}:{1}", device.Name, suffix);
|
||||
deviceHistoryInfo.YaxesKey = YaxesKey;
|
||||
deviceHistoryInfo.Values = new List<double>();
|
||||
foreach (var rows in result)
|
||||
{
|
||||
var fields = rows as IDictionary<string, object>;
|
||||
if (XAxis.IndexOf(fields["TIMESTAMP"].ToString()) > -1)
|
||||
{
|
||||
deviceHistoryInfo.Values.Add(Math.Round(Convert.ToDouble(fields[device.UID]), 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceHistoryInfo.Values.Add(0);
|
||||
}
|
||||
}
|
||||
|
||||
analysisDevice.Series.Add(deviceHistoryInfo);
|
||||
}
|
||||
}
|
||||
|
||||
analysisDevice.XAxis = XAxis.Distinct().ToList();
|
||||
|
||||
apiResult.Code = "0000";
|
||||
|
||||
|
||||
@ -593,6 +593,8 @@ namespace SolarPower.Models.PowerStation
|
||||
public double TOTALMONEY { get; set; }
|
||||
public double TODAYCARBON { get; set; }
|
||||
public double TOTALCARBON { get; set; }
|
||||
public double Irradiance { get; set; }
|
||||
public double Temperature { get; set; }
|
||||
}
|
||||
|
||||
public class AvgPowerStationHistory
|
||||
|
||||
@ -32,6 +32,8 @@ namespace SolarPower.Quartz.Jobs
|
||||
var DateTimeNow = DateTime.Now;
|
||||
var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH");
|
||||
|
||||
dateTime = "2021-07-26 16";
|
||||
|
||||
logger.LogInformation("【CalcPowerStationJob】【任務開始】");
|
||||
|
||||
#region step1. 找出所有電站
|
||||
@ -455,6 +457,7 @@ namespace SolarPower.Quartz.Jobs
|
||||
"ACKW",
|
||||
"KWH",
|
||||
"TODAYKWH",
|
||||
"TOTALKWH",
|
||||
"KWHKWP",
|
||||
};
|
||||
|
||||
|
||||
@ -202,7 +202,8 @@ namespace SolarPower.Repository.Implement
|
||||
FROM power_station_history_hour ps
|
||||
LEFT JOIN sensor_history_hour pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d %H') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d %H')
|
||||
WHERE ps.PowerStationId = @PowerStationId
|
||||
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = @NowDay ORDER BY ps.timestamp";
|
||||
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = @NowDay
|
||||
ORDER BY ps.timestamp";
|
||||
|
||||
result = (await conn.QueryAsync<PowerIrradiance>(sql_power, new { PowerStationId = powerStationId, NowDay = nowDay })).ToList();
|
||||
}
|
||||
@ -226,7 +227,8 @@ namespace SolarPower.Repository.Implement
|
||||
FROM power_station_history_day ps
|
||||
LEFT JOIN sensor_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d')
|
||||
WHERE ps.PowerStationId = @PowerStationId
|
||||
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay ORDER BY ps.timestamp";
|
||||
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay
|
||||
ORDER BY ps.timestamp";
|
||||
|
||||
result = (await conn.QueryAsync<PowerIrradiance>(sql_power, new { PowerStationId = powerStationId, StartDay = startDay, NowDay = nowDay })).ToList();
|
||||
}
|
||||
@ -250,7 +252,8 @@ namespace SolarPower.Repository.Implement
|
||||
FROM power_station_history_day ps
|
||||
LEFT JOIN sensor_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d')
|
||||
WHERE ps.PowerStationId = @PowerStationId
|
||||
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay";
|
||||
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay
|
||||
ORDER BY ps.timestamp";
|
||||
|
||||
result = (await conn.QueryAsync<PowerIrradiance>(sql_power, new { PowerStationId = powerStationId, StartDay = startDay, NowDay = nowDay })).ToList();
|
||||
}
|
||||
@ -275,7 +278,8 @@ namespace SolarPower.Repository.Implement
|
||||
FROM power_station_history_month ps
|
||||
LEFT JOIN sensor_history_month pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m') = DATE_FORMAT(pyr.timestamp, '%Y-%m')
|
||||
WHERE ps.PowerStationId = @PowerStationId
|
||||
AND DATE_FORMAT(ps.timestamp, '%Y') = @Year";
|
||||
AND DATE_FORMAT(ps.timestamp, '%Y') = @Year
|
||||
ORDER BY ps.timestamp";
|
||||
|
||||
result = (await conn.QueryAsync<PowerIrradiance>(sql_power, new { PowerStationId = powerStationId, Year = startyear })).ToList();
|
||||
}
|
||||
|
||||
@ -3902,7 +3902,7 @@ namespace SolarPower.Repository.Implement
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<PowerStationIdAndCity>> GetPowerStationsByCompanyIdWithfilter(int companyId,string filter)
|
||||
public async Task<List<PowerStationIdAndCity>> GetPowerStationsByCompanyIdWithfilter(int companyId, string filter)
|
||||
{
|
||||
List<PowerStationIdAndCity> result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
@ -3952,46 +3952,181 @@ namespace SolarPower.Repository.Implement
|
||||
}
|
||||
}
|
||||
|
||||
//public async Task<List<Device>> GetDeviceByPowerStationIdAndDeviceIds(string db_name, int powerStationId, List<string> deviceIds)
|
||||
//{
|
||||
// List<Device> result;
|
||||
// using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var sql = @$"SELECT FROM {db_name}.device d
|
||||
// WHERE d.";
|
||||
public async Task<List<Device>> GetDeviceByPowerStationIdAndDeviceIds(string db_name, int powerStationId, List<string> deviceIds)
|
||||
{
|
||||
List<Device> result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var sql = @$"SELECT * FROM {db_name}.device d
|
||||
WHERE d.PowerStationId = @PowerStationId AND UID IN @UID";
|
||||
|
||||
|
||||
// result = (await conn.QueryAsync<PowerStationIdAndCity>(sql, new { Filter = filter })).ToList();
|
||||
// }
|
||||
// catch (Exception exception)
|
||||
// {
|
||||
// throw exception;
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//}
|
||||
result = (await conn.QueryAsync<Device>(sql, new { PowerStationId = powerStationId, UID = deviceIds })).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//public async Task<List<Device>> GetSensorAvgByDevices(List<Device> devices)
|
||||
//{
|
||||
// //List<Device> result;
|
||||
// //using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
// //{
|
||||
// // try
|
||||
// // {
|
||||
// // //var sql = @$"SELECT FROM {db_name}.device d
|
||||
// // // WHERE d.";
|
||||
public async Task<dynamic> GetSensorAvgByDevices(string date, byte searchType, List<Device> devices)
|
||||
{
|
||||
dynamic result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var date_format = "";
|
||||
var table_name = "";
|
||||
var where_date = "";
|
||||
|
||||
var start_date = "";
|
||||
var end_date = "";
|
||||
switch (searchType)
|
||||
{
|
||||
case 0:
|
||||
date_format = "%H:%i";
|
||||
table_name = "sensoravg_history_hour";
|
||||
where_date = $" DATE_FORMAT(sen.TIMESTAMP, '%Y-%m-%d') = '{date}'";
|
||||
break;
|
||||
case 1:
|
||||
date_format = "%Y-%m-%d";
|
||||
table_name = "sensoravg_history_day";
|
||||
|
||||
// // //result = (await conn.QueryAsync<PowerStationIdAndCity>(sql, new { Filter = filter })).ToList();
|
||||
// // }
|
||||
// // catch (Exception exception)
|
||||
// // {
|
||||
// // throw exception;
|
||||
// // }
|
||||
// // return result;
|
||||
// //}
|
||||
//}
|
||||
var date_split = date.Split('-');
|
||||
start_date = Convert.ToDateTime(date_split[0].Trim()).ToString("yyyy-MM-dd");
|
||||
end_date = Convert.ToDateTime(date_split[1].Trim()).ToString("yyyy-MM-dd");
|
||||
where_date = $" DATE_FORMAT(sen.TIMESTAMP, '%Y-%m-%d') BETWEEN '{start_date}' AND '{end_date}'";
|
||||
break;
|
||||
case 2:
|
||||
date_format = "%Y-%m-%d";
|
||||
table_name = "sensoravg_history_day";
|
||||
start_date = Convert.ToDateTime(date).ToString("yyyy-MM-dd");
|
||||
end_date = Convert.ToDateTime(date).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
|
||||
where_date = $" DATE_FORMAT(sen.TIMESTAMP, '%Y-%m-%d') BETWEEN '{start_date}' AND '{end_date}'";
|
||||
break;
|
||||
case 3:
|
||||
date_format = "%Y-%m";
|
||||
table_name = "sensoravg_history_month";
|
||||
where_date = $" DATE_FORMAT(sen.TIMESTAMP, '%Y') = '{date}'";
|
||||
break;
|
||||
}
|
||||
|
||||
List<string> sql_select_col = new List<string>();
|
||||
var sql_sub = "";
|
||||
|
||||
for (var i = 0; i < devices.Count(); i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
sql_select_col.Add($"DATE_FORMAT(sen.TIMESTAMP, '{date_format}') AS TIMESTAMP");
|
||||
sql_select_col.Add(string.Concat("`", devices[i].UID, "`"));
|
||||
|
||||
sql_sub += @$" FROM (SELECT sen.TIMESTAMP, sen.{devices[i].ColName} AS `{devices[i].UID}` FROM {table_name} sen WHERE sen.PowerStationId = {devices[i].PowerStationId} AND {where_date}) sen";
|
||||
}
|
||||
else
|
||||
{
|
||||
sql_select_col.Add(string.Concat("`", devices[i].UID, "`"));
|
||||
|
||||
sql_sub += @$" LEFT JOIN (
|
||||
SELECT sen.TIMESTAMP, sen.{devices[i].ColName} AS `{devices[i].UID}`
|
||||
FROM {table_name} sen
|
||||
WHERE sen.PowerStationId = {devices[i].PowerStationId} AND {where_date}) sen{i}
|
||||
ON sen.TIMESTAMP = sen{i}.TIMESTAMP";
|
||||
}
|
||||
}
|
||||
|
||||
var select_col = string.Join(", ", sql_select_col);
|
||||
var sql = $"SELECT {select_col} " + sql_sub;
|
||||
|
||||
result = await conn.QueryAsync<dynamic>(sql);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<PowerStationHistory>> GetPowerStationHistory(string date, byte searchType, List<int> entities)
|
||||
{
|
||||
List<PowerStationHistory> result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var KWH_col = "";
|
||||
var date_format = "";
|
||||
var table_name = "";
|
||||
var where_date = "";
|
||||
var letf_join_table = "";
|
||||
|
||||
var start_date = "";
|
||||
var end_date = "";
|
||||
switch (searchType)
|
||||
{
|
||||
case 0:
|
||||
KWH_col = "ps.KWH";
|
||||
date_format = "%H:%i";
|
||||
table_name = "power_station_history_hour";
|
||||
letf_join_table = "sensor_history_hour";
|
||||
where_date = $" AND DATE_FORMAT(ps.TIMESTAMP, '%Y-%m-%d') = '{date}'";
|
||||
break;
|
||||
case 1:
|
||||
KWH_col = "ps.TODAYKWH AS KWH";
|
||||
date_format = "%Y-%m-%d";
|
||||
table_name = "power_station_history_day";
|
||||
letf_join_table = "sensor_history_day";
|
||||
var date_split = date.Split('-');
|
||||
start_date = Convert.ToDateTime(date_split[0].Trim()).ToString("yyyy-MM-dd");
|
||||
end_date = Convert.ToDateTime(date_split[1].Trim()).ToString("yyyy-MM-dd");
|
||||
where_date = $" AND DATE_FORMAT(ps.TIMESTAMP, '%Y-%m-%d') BETWEEN '{start_date}' AND '{end_date}'";
|
||||
break;
|
||||
case 2:
|
||||
KWH_col = "ps.TODAYKWH AS KWH";
|
||||
date_format = "%Y-%m-%d";
|
||||
table_name = "power_station_history_day";
|
||||
letf_join_table = "sensor_history_day";
|
||||
start_date = Convert.ToDateTime(date).ToString("yyyy-MM-dd");
|
||||
end_date = Convert.ToDateTime(date).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
|
||||
where_date = $" AND DATE_FORMAT(ps.TIMESTAMP, '%Y-%m-%d') BETWEEN '{start_date}' AND '{end_date}'";
|
||||
break;
|
||||
case 3:
|
||||
KWH_col = "ps.MONTHKWH AS KWH";
|
||||
date_format = "%Y-%m";
|
||||
table_name = "power_station_history_month";
|
||||
letf_join_table = "sensor_history_month";
|
||||
where_date = $" AND DATE_FORMAT(ps.TIMESTAMP, '%Y') = '{date}'";
|
||||
break;
|
||||
}
|
||||
|
||||
var sql = $@"SELECT
|
||||
ps.PowerStationId,
|
||||
DATE_FORMAT(ps.TIMESTAMP, '{date_format}') AS TIMESTAMP,
|
||||
{KWH_col},
|
||||
ps.SOLARHOUR,
|
||||
ps.KWHKWP,
|
||||
ps.PR,
|
||||
sen.Irradiance,
|
||||
sen.Temperature
|
||||
FROM {table_name} ps
|
||||
LEFT JOIN {letf_join_table} sen ON ps.PowerStationId = sen.PowerStationId AND ps.TIMESTAMP = sen.TIMESTAMP
|
||||
WHERE ps.PowerStationId IN @PowerStationId
|
||||
{where_date}";
|
||||
|
||||
result = (await conn.QueryAsync<PowerStationHistory>(sql, new { PowerStationId = entities})).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -554,7 +554,8 @@ namespace SolarPower.Repository.Interface
|
||||
Task<List<InverterHistory>> GetInverterHistoryByYear(string year, List<StationIdWithInverterIds> entities);
|
||||
Task<List<PowerStationIdAndCity>> GetPowerStationsByCompanyIdWithfilter(int companyId,string filter);
|
||||
Task<List<PowerStationIdAndCity>> GetPowerStationsAllWithfilter(string filter);
|
||||
//Task<List<Device>> GetDeviceByPowerStationIdAndDeviceIds(string db_name, int powerStationId, List<string> deviceIds);
|
||||
//Task<List<Device>> GetSensorAvgByDevices(List<Device> devices);
|
||||
Task<List<Device>> GetDeviceByPowerStationIdAndDeviceIds(string db_name, int powerStationId, List<string> deviceIds);
|
||||
Task<dynamic> GetSensorAvgByDevices(string date, byte searchType, List<Device> devices);
|
||||
Task<List<PowerStationHistory>> GetPowerStationHistory(string date, byte searchType, List<int> entities);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto px-0">
|
||||
<a href="javascript:;" data-target=".sidebar" data-toggle="collapse" class="btn btn-default btn-xs btn-icon waves-effect waves-themed" style="border-radius: 0;"><i onclick="myfunc(this)" class="fal fa-angle-right fa-lg py-3"></i></a>
|
||||
<a href="javascript:;" id="collapse" data-target=".sidebar" data-toggle="collapse" class="btn btn-default btn-xs btn-icon waves-effect waves-themed" style="border-radius: 0;"><i onclick="myfunc(this)" class="fal fa-angle-right fa-lg py-3"></i></a>
|
||||
</div>
|
||||
|
||||
<main class="col px-5 pl-md-2 main">
|
||||
@ -200,6 +200,8 @@
|
||||
]
|
||||
|
||||
$(function () {
|
||||
$('#collapse').trigger("click");
|
||||
|
||||
//#region 預設初始值
|
||||
$('#DateGet').val(new Date().toISOString().substring(0, 10));
|
||||
document.getElementById("DateGettextdiv").style.display = "none";//隱藏
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto px-0">
|
||||
<a href="javascript:;" data-target=".sidebar" data-toggle="collapse" class="btn btn-default btn-xs btn-icon waves-effect waves-themed" style="border-radius: 0;"><i onclick="myfunc(this)" class="fal fa-angle-right fa-lg py-3"></i></a>
|
||||
<a href="javascript:;" id="collapse" data-target=".sidebar" data-toggle="collapse" class="btn btn-default btn-xs btn-icon waves-effect waves-themed" style="border-radius: 0;"><i onclick="myfunc(this)" class="fal fa-angle-right fa-lg py-3"></i></a>
|
||||
</div>
|
||||
|
||||
<main class="col px-5 pl-md-2 main">
|
||||
@ -117,16 +117,29 @@
|
||||
var datepicker;
|
||||
var timerange;//選取時間
|
||||
var selected_device = [];
|
||||
var PWS_compare_col = [{ key: "KWH", title: "發電量" }, { key: "Irradiance", title: "日照度" }]
|
||||
var PYR_compare_col = [{ key: "Irradiance", title: "日照度" }];
|
||||
var ETR_compare_col = [{ key: "Temperature", title: "環境溫度計" }];
|
||||
var EMM_compare_col = [{ key: "Humidity", title: "濕度" }];
|
||||
var VAN_compare_col = [{ key: "Vane", title: "風速" }];
|
||||
var FOM_compare_col = [{ key: "Dust", title: "落塵%" }];
|
||||
var PWS_compare_col = [
|
||||
{ key: "KWH", title: "發電量", default: true },
|
||||
{ key: "Irradiance", title: "日照度", default: true},
|
||||
{ key: "KWHKWP", title: "發電小時", default: false },
|
||||
{ key: "PR", title: "PR %", default: false },
|
||||
{ key: "ModelTemperature", title: "模組溫度", default: false },
|
||||
{ key: "SolarHour", title: "日照小時", default: false }
|
||||
]
|
||||
var PYR_compare_col = [{ key: "Irradiance", title: "日照度", default: true }];
|
||||
var ETR_compare_col = [{ key: "Temperature", title: "環境溫度計", default: true }];
|
||||
var MTR_compare_col = [{ key: "ModelTemperature", title: "模組溫度", default: true }];
|
||||
var EMM_compare_col = [{ key: "Humidity", title: "濕度", default: true }];
|
||||
var VAN_compare_col = [{ key: "Vane", title: "風速", default: true }];
|
||||
var FOM_compare_col = [{ key: "Dust", title: "落塵%", default: true }];
|
||||
var all_selected_compare_col = [];
|
||||
var checked_compare_col = [];
|
||||
var default_compare_col = [];
|
||||
var selected_YAxis = [];
|
||||
var analysisStationInfo;
|
||||
var chart;
|
||||
|
||||
$(function () {
|
||||
$('#collapse').trigger("click");
|
||||
|
||||
//#region 預設初始值
|
||||
$('#DateGet').val(new Date().toISOString().substring(0, 10));
|
||||
document.getElementById("DateGettextdiv").style.display = "none";//隱藏
|
||||
@ -323,6 +336,9 @@
|
||||
case 'ETR': //環境溫度計
|
||||
PushAllSelectedCompareCol(ETR_compare_col);
|
||||
break;
|
||||
case 'MTR': //模組溫度計
|
||||
PushAllSelectedCompareCol(MTR_compare_col);
|
||||
break;
|
||||
case 'VAN': //風速計
|
||||
PushAllSelectedCompareCol(VAN_compare_col);
|
||||
break;
|
||||
@ -337,9 +353,11 @@
|
||||
} else {
|
||||
if (selected_device.some(x => x.deviceId == this.value)) {
|
||||
|
||||
var cancel_device = this.value;
|
||||
|
||||
var temp_index;
|
||||
selected_device.find(function (obj, index) {
|
||||
if (obj.deviceId == this.value) {
|
||||
if (obj.deviceId == cancel_device) {
|
||||
temp_index = index;
|
||||
}
|
||||
});
|
||||
@ -360,7 +378,9 @@
|
||||
break;
|
||||
case 'ETR': //環境溫度計
|
||||
RemoveAllSelectedCompareCol(ETR_compare_col);
|
||||
|
||||
break;
|
||||
case 'MTR': //模組溫度計
|
||||
RemoveAllSelectedCompareCol(MTR_compare_col);
|
||||
break;
|
||||
case 'VAN': //風速計
|
||||
RemoveAllSelectedCompareCol(VAN_compare_col);
|
||||
@ -379,8 +399,6 @@
|
||||
|
||||
console.log("all_selected_compare_col", all_selected_compare_col);
|
||||
ChangeCompareSelectOption()
|
||||
|
||||
console.log("selected_device", selected_device);
|
||||
});
|
||||
|
||||
$('#js_list_accordion').on("change", 'input[name="selectedDeviceLayer2[]"]', function (event) {
|
||||
@ -391,6 +409,26 @@
|
||||
}
|
||||
});
|
||||
|
||||
$('#compare-dropdown-menu').on('change', 'input[name="compare_col[]"]', function (e) {
|
||||
if (this.checked) {
|
||||
selected_YAxis.push($(this).val());
|
||||
if ($.inArray($(this).val(), default_compare_col) == -1) {
|
||||
default_compare_col.push($(this).val());
|
||||
}
|
||||
} else {
|
||||
selected_YAxis.splice($.inArray($(this).val(), selected_YAxis), 1);
|
||||
|
||||
if ($.inArray($(this).val(), default_compare_col) >0) {
|
||||
default_compare_col.splice($.inArray($(this).val(), default_compare_col), 1);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("default_compare_col", default_compare_col)
|
||||
console.log("selected_YAxis", selected_YAxis)
|
||||
|
||||
ReloadHighCharts();
|
||||
});
|
||||
|
||||
function GetPowerStationCollapse(filter) {
|
||||
var url = "/AnalysisStationInfo/GetDeviceCollapse"
|
||||
|
||||
@ -453,6 +491,9 @@
|
||||
case 'ETR': //環境溫度計
|
||||
device_icon = '<i class="fal fa-thermometer-half"></i>';
|
||||
break;
|
||||
case 'MTR': //模組溫度計
|
||||
device_icon = '<i class="fal fa-thermometer-half"></i>';
|
||||
break;
|
||||
case 'VAN': //風速計
|
||||
device_icon = '<i class="fal fa-wind"></i>';
|
||||
break;
|
||||
@ -511,7 +552,13 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (item.default && $.inArray(item.key, default_compare_col) == -1) {
|
||||
default_compare_col.push(item.key);
|
||||
}
|
||||
});
|
||||
|
||||
console.log("default_compare_col", default_compare_col);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
@ -524,6 +571,15 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$.each(all_selected_compare_col, function (index, item) {
|
||||
if (item.count <= 0) {
|
||||
if ($.inArray(item.key, default_compare_col) > -1)
|
||||
default_compare_col.splice($.inArray(item.key, default_compare_col), 1);
|
||||
}
|
||||
});
|
||||
|
||||
console.log("default_compare_col", default_compare_col);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
@ -534,6 +590,12 @@
|
||||
str += '<li><a href="javascript:void(0)" class="dropdown-item" tabIndex="-1">' + item.title + '<input type="checkbox" class="float-right" name="compare_col[]" value="' + item.key + '" /></a></li>'
|
||||
});
|
||||
$("#compare-dropdown-menu").append(str);
|
||||
|
||||
$('input[name="compare_col[]"]').each(function () {
|
||||
if ($.inArray(this.value, default_compare_col) > -1) {
|
||||
$(this).prop('checked', true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function GetAnalysisStationInfo() {
|
||||
@ -562,21 +624,110 @@
|
||||
|
||||
if (searchType != 0) {
|
||||
$('input[name="compare_col[]"]').each(function () {
|
||||
if ($.inArray(this.value, default_compare_date) > -1) {
|
||||
if ($.inArray(this.value, default_compare_col) > -1) {
|
||||
$(this).prop('checked', true).trigger('change');
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
$('input[name="compare_col[]"]').each(function () {
|
||||
if ($.inArray(this.value, default_compare_row_data) > -1) {
|
||||
if ($.inArray(this.value, default_compare_col) > -1) {
|
||||
$(this).prop('checked', true).trigger('change');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@*ReloadHighCharts();*@
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
function ReloadHighCharts() {
|
||||
|
||||
myYAxis = []; mySeries = [];
|
||||
|
||||
myXAxis = analysisStationInfo.xAxis
|
||||
|
||||
Object.keys(analysisStationInfo.multipleYaxes).map(function (key, index) {
|
||||
|
||||
if (selected_YAxis.indexOf(key) > -1) {
|
||||
var yAxis = {
|
||||
title: {
|
||||
text: analysisStationInfo.multipleYaxes[key],
|
||||
},
|
||||
id: key,
|
||||
opposite: myYAxis.length > 0 ? true : false,
|
||||
showEmpty: false
|
||||
}
|
||||
|
||||
myYAxis.push(yAxis);
|
||||
}
|
||||
});
|
||||
|
||||
analysisStationInfo.series.map(function (item, index) {
|
||||
if (selected_YAxis.indexOf(item.yaxesKey) > -1) {
|
||||
var ser = {
|
||||
type: 'spline',
|
||||
name: item.name,
|
||||
data: item.values,
|
||||
yAxis: item.yaxesKey,
|
||||
}
|
||||
|
||||
mySeries.push(ser);
|
||||
}
|
||||
});
|
||||
|
||||
if (chart) {
|
||||
chart.destroy();
|
||||
}
|
||||
|
||||
chart = new Highcharts.Chart({
|
||||
lang: { //匯出相關中文名稱配置
|
||||
printChart: '列印圖表',
|
||||
downloadJPEG: '下載JPEG檔案',
|
||||
downloadPDF: '下載PDF檔案',
|
||||
downloadPNG: '下載PNG檔案',
|
||||
downloadSVG: '下載SVG檔案',
|
||||
downloadCSV: '下載CSV檔案',
|
||||
downloadXLS: '下載XLS檔案',
|
||||
viewData: '檢視資料表格',
|
||||
viewFullscreen: '全屏檢視'
|
||||
},
|
||||
chart: {
|
||||
renderTo: 'container',
|
||||
height: 600,
|
||||
animation: false
|
||||
},
|
||||
title: {
|
||||
text: '交叉分析圖表'
|
||||
},
|
||||
tooltip: {
|
||||
formatter: function () {
|
||||
return '<b>' + this.series.name + '</b><br>' +
|
||||
'<span>' + this.x + '</span><br>' +
|
||||
'<b style = "color:rgb(103, 180, 172);" >' + this.point.y + '</b>';
|
||||
}
|
||||
},
|
||||
xAxis: {
|
||||
categories: myXAxis,
|
||||
labels: {
|
||||
step: 1,
|
||||
formatter: function () {
|
||||
if (searchType == 0) {
|
||||
var aa = this.value.substr(-2);
|
||||
if (aa == "00") {
|
||||
return '<span>' + this.value + '</span>';
|
||||
} else {
|
||||
return '<span style="display:none">' + this.value + '</span>';
|
||||
}
|
||||
} else {
|
||||
return this.value
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
yAxis: myYAxis,
|
||||
|
||||
series: mySeries,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
}
|
||||
@ -352,6 +352,7 @@
|
||||
label: '輸出功率',
|
||||
yAxisID: 'A',
|
||||
backgroundColor: 'rgb(103, 180, 172)',
|
||||
order: 2,
|
||||
data: chart7day.powerDatas
|
||||
}, {
|
||||
type: 'line',
|
||||
@ -364,6 +365,7 @@
|
||||
borderWidth: 2,
|
||||
pointRadius: 4,
|
||||
pointHoverRadius: 5,
|
||||
order: 1,
|
||||
fill: false,
|
||||
data: chart7day.irradianceDatas,
|
||||
}]
|
||||
@ -417,6 +419,7 @@
|
||||
label: '輸出功率',
|
||||
yAxisID: 'A',
|
||||
backgroundColor: 'rgb(103, 180, 172)',
|
||||
order: 2,
|
||||
data: chartMonth.powerDatas
|
||||
}, {
|
||||
type: 'line',
|
||||
@ -429,6 +432,7 @@
|
||||
borderWidth: 2,
|
||||
pointRadius: 4,
|
||||
pointHoverRadius: 5,
|
||||
order: 1,
|
||||
fill: false,
|
||||
data: chartMonth.irradianceDatas,
|
||||
}]
|
||||
@ -482,6 +486,7 @@
|
||||
label: '輸出功率',
|
||||
yAxisID: 'A',
|
||||
backgroundColor: 'rgb(103, 180, 172)',
|
||||
order: 2,
|
||||
data: chartYear.powerDatas
|
||||
}, {
|
||||
type: 'line',
|
||||
@ -494,6 +499,7 @@
|
||||
borderWidth: 2,
|
||||
pointRadius: 4,
|
||||
pointHoverRadius: 5,
|
||||
order: 1,
|
||||
fill: false,
|
||||
data: chartYear.irradianceDatas,
|
||||
}]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user