From e108b3ab1bf29348596e68e4ac1c98c64d583fee Mon Sep 17 00:00:00 2001 From: Kai Date: Thu, 29 Jul 2021 19:12:36 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E9=9B=BB=E7=AB=99=E4=BA=A4=E5=8F=89?= =?UTF-8?q?=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnalysisStationInfoController.cs | 219 +++++++++++++++++- SolarPower/Models/PowerStation.cs | 2 + SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 3 + .../Implement/OverviewRepository.cs | 12 +- .../Implement/PowerStationRepository.cs | 209 ++++++++++++++--- .../Interface/IPowerStationRepository.cs | 5 +- .../Views/AnalysisInverter/Index.cshtml | 4 +- .../Views/AnalysisStationInfo/Index.cshtml | 181 +++++++++++++-- .../StationOverviewInfo.cshtml | 6 + 9 files changed, 573 insertions(+), 68 deletions(-) diff --git a/SolarPower/Controllers/AnalysisStationInfoController.cs b/SolarPower/Controllers/AnalysisStationInfoController.cs index d861d3f..8270ab2 100644 --- a/SolarPower/Controllers/AnalysisStationInfoController.cs +++ b/SolarPower/Controllers/AnalysisStationInfoController.cs @@ -61,7 +61,7 @@ namespace SolarPower.Controllers var device_psName_Group = cityName_Group.GroupBy(x => x.PowerStationName).ToList(); var deviceDic = new Dictionary>(); - + foreach (var psName_Group in device_psName_Group) { //電站總覽 @@ -77,7 +77,7 @@ namespace SolarPower.Controllers var temp = new List(); 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(); //先將欲查詢的設備找出設備的資料庫欄位 var device_powerStationId_Group = post.DeviceIdInfos.GroupBy(x => x.PowerStationId).ToList(); - List devices = new List(); - foreach(var psId_Group in device_powerStationId_Group) + Dictionary> deviceDic = new Dictionary>(); + List selected_powerStationIds = new List(); + 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() + { + { "KWH", "發電量"}, + { "Irradiance", "日照度"}, + { "KWHKWP", "發電小時"}, + { "PR", "PR %"}, + { "SolarHour", "日照小時"}, + { "ModelTemperature", "模組溫度"}, + { "Temperature", "環境溫度計"}, + { "Humidity", "濕度"}, + { "Vane", "風速"}, + { "Dust", "落塵%"}, + }; + var XAxis = new List(); + + //電站資料 + 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(); + 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(); + 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(); + 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(); + 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(); + 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(); + 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; + 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(); + foreach (var rows in result) + { + var fields = rows as IDictionary; + 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"; diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index 0d132e7..b35ad2e 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -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 diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 6cf19d9..69d5308 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -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", }; diff --git a/SolarPower/Repository/Implement/OverviewRepository.cs b/SolarPower/Repository/Implement/OverviewRepository.cs index a8dc432..350cb7f 100644 --- a/SolarPower/Repository/Implement/OverviewRepository.cs +++ b/SolarPower/Repository/Implement/OverviewRepository.cs @@ -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(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(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(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(sql_power, new { PowerStationId = powerStationId, Year = startyear })).ToList(); } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 53795b6..95b7fe6 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -3902,7 +3902,7 @@ namespace SolarPower.Repository.Implement } - public async Task> GetPowerStationsByCompanyIdWithfilter(int companyId,string filter) + public async Task> GetPowerStationsByCompanyIdWithfilter(int companyId, string filter) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -3952,46 +3952,181 @@ namespace SolarPower.Repository.Implement } } - //public async Task> GetDeviceByPowerStationIdAndDeviceIds(string db_name, int powerStationId, List deviceIds) - //{ - // List result; - // using (IDbConnection conn = this._databaseHelper.GetConnection()) - // { - // try - // { - // var sql = @$"SELECT FROM {db_name}.device d - // WHERE d."; + public async Task> GetDeviceByPowerStationIdAndDeviceIds(string db_name, int powerStationId, List deviceIds) + { + List 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(sql, new { Filter = filter })).ToList(); - // } - // catch (Exception exception) - // { - // throw exception; - // } - // return result; - // } - //} + result = (await conn.QueryAsync(sql, new { PowerStationId = powerStationId, UID = deviceIds })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } - //public async Task> GetSensorAvgByDevices(List devices) - //{ - // //List result; - // //using (IDbConnection conn = this._databaseHelper.GetConnection()) - // //{ - // // try - // // { - // // //var sql = @$"SELECT FROM {db_name}.device d - // // // WHERE d."; + public async Task GetSensorAvgByDevices(string date, byte searchType, List 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(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 sql_select_col = new List(); + 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(sql); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + public async Task> GetPowerStationHistory(string date, byte searchType, List entities) + { + List 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(sql, new { PowerStationId = entities})).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 40d3951..4622774 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -554,7 +554,8 @@ namespace SolarPower.Repository.Interface Task> GetInverterHistoryByYear(string year, List entities); Task> GetPowerStationsByCompanyIdWithfilter(int companyId,string filter); Task> GetPowerStationsAllWithfilter(string filter); - //Task> GetDeviceByPowerStationIdAndDeviceIds(string db_name, int powerStationId, List deviceIds); - //Task> GetSensorAvgByDevices(List devices); + Task> GetDeviceByPowerStationIdAndDeviceIds(string db_name, int powerStationId, List deviceIds); + Task GetSensorAvgByDevices(string date, byte searchType, List devices); + Task> GetPowerStationHistory(string date, byte searchType, List entities); } } diff --git a/SolarPower/Views/AnalysisInverter/Index.cshtml b/SolarPower/Views/AnalysisInverter/Index.cshtml index 3d773bb..ef81084 100644 --- a/SolarPower/Views/AnalysisInverter/Index.cshtml +++ b/SolarPower/Views/AnalysisInverter/Index.cshtml @@ -21,7 +21,7 @@
- +
@@ -200,6 +200,8 @@ ] $(function () { + $('#collapse').trigger("click"); + //#region 預設初始值 $('#DateGet').val(new Date().toISOString().substring(0, 10)); document.getElementById("DateGettextdiv").style.display = "none";//隱藏 diff --git a/SolarPower/Views/AnalysisStationInfo/Index.cshtml b/SolarPower/Views/AnalysisStationInfo/Index.cshtml index 7187793..0de020c 100644 --- a/SolarPower/Views/AnalysisStationInfo/Index.cshtml +++ b/SolarPower/Views/AnalysisStationInfo/Index.cshtml @@ -21,7 +21,7 @@
- +
@@ -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 = ''; break; + case 'MTR': //模組溫度計 + device_icon = ''; + break; case 'VAN': //風速計 device_icon = ''; 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 += '
  • ' + item.title + '
  • ' }); $("#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 '' + this.series.name + '
    ' + + '' + this.x + '
    ' + + '' + this.point.y + ''; + } + }, + xAxis: { + categories: myXAxis, + labels: { + step: 1, + formatter: function () { + if (searchType == 0) { + var aa = this.value.substr(-2); + if (aa == "00") { + return '' + this.value + ''; + } else { + return '' + this.value + ''; + } + } else { + return this.value + } + } + } + }, + yAxis: myYAxis, + + series: mySeries, + }); + } } \ No newline at end of file diff --git a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml index 3848958..217db3e 100644 --- a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml +++ b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml @@ -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, }]