diff --git a/SolarPower/Controllers/AnalysisInverterController.cs b/SolarPower/Controllers/AnalysisInverterController.cs index 11879eb..e2c4ff8 100644 --- a/SolarPower/Controllers/AnalysisInverterController.cs +++ b/SolarPower/Controllers/AnalysisInverterController.cs @@ -97,14 +97,18 @@ namespace SolarPower.Controllers List series = new List(); var powerStation_Group = post.InverterIdInfos.GroupBy(x => x.PowerStationId).ToList(); - if(post.SearchType == 0) + if (post.SearchType == 0) { //單日 var StationCodeWithInverterIdsList = new List(); foreach (var ps in powerStation_Group) { var powerStation = await powerStationRepository.GetOneAsync(ps.Key); + //找出該電站所有日照計設備(包含共享 + var deviceInfos = await powerStationRepository.GetListPyrheliometerByPowerStationId(powerStation.Id, powerStation.SiteDB); + StationCodeWithInverterIds stationCodeWithInverterIds = new StationCodeWithInverterIds(); + stationCodeWithInverterIds.Sensor = deviceInfos.First().ColName; stationCodeWithInverterIds.SiteDB = powerStation.SiteDB; stationCodeWithInverterIds.Code = powerStation.Code; stationCodeWithInverterIds.InverterIds = ps.Select(x => x.InverterId).ToList(); @@ -153,11 +157,31 @@ namespace SolarPower.Controllers series = new List(); + + #region 比較欄位 foreach (var item in inverterHistories_Group) { var temp_item = item.OrderBy(x => x.TIMESTAMP).ToList(); + InverterHistoryInfo Irradiance = new InverterHistoryInfo(); + Irradiance.Name = string.Format("{0}:{1}", item.Key, "日照度"); + Irradiance.YaxesKey = "Irradiance"; + Irradiance.Values = new List(); + foreach (var history in temp_item) + { + if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) + { + Irradiance.Values.Add(Math.Round(history.Irradiance, 2)); + } + else + { + Irradiance.Values.Add(0); + } + } + series.Add(Irradiance); + + InverterHistoryInfo DCKW = new InverterHistoryInfo(); DCKW.Name = string.Format("{0}:{1}", item.Key, "直流功率 (KW)"); DCKW.YaxesKey = "DCKW"; @@ -166,7 +190,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DCKW.Values.Add(history.DCKW); + DCKW.Values.Add(Math.Round(history.DCKW, 2)); } else { @@ -183,7 +207,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - ACKW.Values.Add(history.ACKW); + ACKW.Values.Add(Math.Round(history.ACKW, 2)); } else { @@ -200,7 +224,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC1V.Values.Add(history.DC1V); + DC1V.Values.Add(Math.Round(history.DC1V, 2)); } else { @@ -217,7 +241,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC1A.Values.Add(history.DC1A); + DC1A.Values.Add(Math.Round(history.DC1A, 2)); } else { @@ -234,7 +258,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC1KW.Values.Add(history.DC1W / 1000); + DC1KW.Values.Add(Math.Round(history.DC1W / 1000, 2)); } else { @@ -251,7 +275,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC2V.Values.Add(history.DC2V); + DC2V.Values.Add(Math.Round(history.DC2V, 2)); } else { @@ -268,7 +292,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC2A.Values.Add(history.DC2A); + DC2A.Values.Add(Math.Round(history.DC2A, 2)); } else { @@ -285,7 +309,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC2KW.Values.Add(history.DC2W / 1000); + DC2KW.Values.Add(Math.Round(history.DC2W / 1000, 2)); } else { @@ -302,7 +326,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC3V.Values.Add(history.DC3V); + DC3V.Values.Add(Math.Round(history.DC3V, 2)); } else { @@ -319,7 +343,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC3A.Values.Add(history.DC3A); + DC3A.Values.Add(Math.Round(history.DC3A, 2)); } else { @@ -336,7 +360,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC3KW.Values.Add(history.DC3W / 1000); + DC3KW.Values.Add(Math.Round(history.DC3W / 1000, 2)); } else { @@ -353,7 +377,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC4V.Values.Add(history.DC4V); + DC4V.Values.Add(Math.Round(history.DC4V, 2)); } else { @@ -370,7 +394,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC4A.Values.Add(history.DC4A); + DC4A.Values.Add(Math.Round(history.DC4A, 2)); } else { @@ -387,7 +411,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC4KW.Values.Add(history.DC4W / 1000); + DC4KW.Values.Add(Math.Round(history.DC4W / 1000, 2)); } else { @@ -404,7 +428,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC5V.Values.Add(history.DC5V); + DC5V.Values.Add(Math.Round(history.DC5V, 2)); } else { @@ -421,7 +445,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC5A.Values.Add(history.DC5A); + DC5A.Values.Add(Math.Round(history.DC5A, 2)); } else { @@ -438,7 +462,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - DC5KW.Values.Add(history.DC5W / 1000); + DC5KW.Values.Add(Math.Round(history.DC5W / 1000, 2)); } else { @@ -455,7 +479,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - AC1V.Values.Add(history.AC1V); + AC1V.Values.Add(Math.Round(history.AC1V, 2)); } else { @@ -472,7 +496,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - AC2V.Values.Add(history.AC2V); + AC2V.Values.Add(Math.Round(history.AC2V, 2)); } else { @@ -489,7 +513,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - AC3V.Values.Add(history.AC3V); + AC3V.Values.Add(Math.Round(history.AC3V, 2)); } else { @@ -506,7 +530,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - AC1A.Values.Add(history.AC1A); + AC1A.Values.Add(Math.Round(history.AC1A, 2)); } else { @@ -523,7 +547,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - AC2A.Values.Add(history.AC2A); + AC2A.Values.Add(Math.Round(history.AC2A, 2)); } else { @@ -540,7 +564,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - AC3A.Values.Add(history.AC3A); + AC3A.Values.Add(Math.Round(history.AC3A, 2)); } else { @@ -557,7 +581,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - PR.Values.Add(history.PR); + PR.Values.Add(Math.Round(history.PR, 2)); } else { @@ -574,7 +598,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - RA1.Values.Add(history.RA1); + RA1.Values.Add(Math.Round(history.RA1, 2)); } else { @@ -591,7 +615,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - RA2.Values.Add(history.RA2); + RA2.Values.Add(Math.Round(history.RA2, 2)); } else { @@ -608,7 +632,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - RA3.Values.Add(history.RA3); + RA3.Values.Add(Math.Round(history.RA3, 2)); } else { @@ -625,7 +649,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - RA4.Values.Add(history.RA4); + RA4.Values.Add(Math.Round(history.RA4, 2)); } else { @@ -642,7 +666,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - RA5.Values.Add(history.RA5); + RA5.Values.Add(Math.Round(history.RA5, 2)); } else { @@ -719,7 +743,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - Irradiance.Values.Add(history.Irradiance); + Irradiance.Values.Add(Math.Round(history.Irradiance, 2)); } else { @@ -736,7 +760,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - KWH.Values.Add(history.KWH); + KWH.Values.Add(Math.Round(history.KWH, 2)); } else { @@ -753,7 +777,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - TodayKWH.Values.Add(history.TODAYKWH); + TodayKWH.Values.Add(Math.Round(history.TODAYKWH, 2)); } else { @@ -770,7 +794,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - TotalKWH.Values.Add(history.TOTALKWH); + TotalKWH.Values.Add(Math.Round(history.TOTALKWH, 2)); } else { @@ -788,7 +812,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - PR.Values.Add(history.PR); + PR.Values.Add(Math.Round(history.PR, 2)); } else { @@ -805,7 +829,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - RA1.Values.Add(history.RA1); + RA1.Values.Add(Math.Round(history.RA1, 2)); } else { @@ -822,7 +846,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - RA2.Values.Add(history.RA2); + RA2.Values.Add(Math.Round(history.RA2, 2)); } else { @@ -839,7 +863,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - RA3.Values.Add(history.RA3); + RA3.Values.Add(Math.Round(history.RA3, 2)); } else { @@ -856,7 +880,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - RA4.Values.Add(history.RA4); + RA4.Values.Add(Math.Round(history.RA4, 2)); } else { @@ -873,7 +897,7 @@ namespace SolarPower.Controllers { if (analysisInverter.XAxis.IndexOf(history.TIMESTAMP) > -1) { - RA5.Values.Add(history.RA5); + RA5.Values.Add(Math.Round(history.RA5, 2)); } else { diff --git a/SolarPower/Controllers/AnalysisStationInfoController.cs b/SolarPower/Controllers/AnalysisStationInfoController.cs index 8270ab2..3c9b253 100644 --- a/SolarPower/Controllers/AnalysisStationInfoController.cs +++ b/SolarPower/Controllers/AnalysisStationInfoController.cs @@ -114,6 +114,7 @@ namespace SolarPower.Controllers //先將欲查詢的設備找出設備的資料庫欄位 var device_powerStationId_Group = post.DeviceIdInfos.GroupBy(x => x.PowerStationId).ToList(); Dictionary> deviceDic = new Dictionary>(); + List meterDic = new List(); List selected_powerStationIds = new List(); foreach (var psId_Group in device_powerStationId_Group) { @@ -121,7 +122,18 @@ namespace SolarPower.Controllers //區分電站總覽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 selected_meter = psId_Group.Where(x => x.DeviceType == "PWR").Select(x => x.DeviceId).ToList(); + var selected_device = psId_Group.Where(x => x.DeviceType != "PWS" && x.DeviceType != "PWR").Select(x => x.DeviceId).ToList(); + + var temp_meter = await powerStationRepository.GetDeviceByPowerStationIdAndDeviceIds(powerStation.SiteDB, powerStation.Id, selected_meter); + if (temp_meter.Count() > 0) + { + StationIdWithMeterIds stationIdWithMeterIds = new StationIdWithMeterIds(); + stationIdWithMeterIds.PowerStationId = psId_Group.Key; + stationIdWithMeterIds.MeterIds = temp_meter.Select(x => x.UID).ToList(); + + meterDic.Add(stationIdWithMeterIds); + } var temp_device = await powerStationRepository.GetDeviceByPowerStationIdAndDeviceIds(powerStation.SiteDB, powerStation.Id, selected_device); if (temp_device.Count() > 0) @@ -142,11 +154,21 @@ namespace SolarPower.Controllers { "Humidity", "濕度"}, { "Vane", "風速"}, { "Dust", "落塵%"}, + { "OUTPUT_KWH", "輸出發電量(kWh)"}, + { "INPUT_KWH", "輸入發電量(kWh)"}, + { "V_AB", "電壓 AB(V)"}, + { "V_BC", "電壓 BC(V)"}, + { "V_CA", "電壓 CA(V)"}, + { "I_A", "電流 A(A)"}, + { "I_B", "電流 B(A)"}, + { "I_C", "電流 C(A)"}, + { "P", "有效功率(kW)"}, + { "F", "頻率(Hz)"}, }; var XAxis = new List(); - //電站資料 + #region 電站資料 var powerStationHistories = await powerStationRepository.GetPowerStationHistory(post.SelectedDate, post.SearchType, selected_powerStationIds); XAxis.AddRange(powerStationHistories.Select(x => x.Timestamp).Distinct().ToList()); @@ -261,8 +283,193 @@ namespace SolarPower.Controllers } analysisDevice.Series.Add(modelTemperature); } + #endregion - //設備資料 + #region 電錶資料 + var meterHistories = await powerStationRepository.GetMeterHistory(post.SelectedDate, post.SearchType, meterDic); + + XAxis.AddRange(meterHistories.Select(x => x.TIMESTAMP).Distinct().ToList()); + + var meterHistories_Id_Group = meterHistories.GroupBy(x => x.METERID).ToList(); + + foreach (var item in meterHistories_Id_Group) + { + var temp_item = item.OrderBy(x => x.TIMESTAMP).ToList(); + + DeviceHistoryInfo OUTPUT_KWH = new DeviceHistoryInfo(); + OUTPUT_KWH.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["OUTPUT_KWH"]); + OUTPUT_KWH.YaxesKey = "OUTPUT_KWH"; + OUTPUT_KWH.Values = new List(); + foreach (var history in temp_item) + { + if (XAxis.IndexOf(history.TIMESTAMP) > -1) + { + OUTPUT_KWH.Values.Add(Math.Round(history.OUTPUT_KWH, 2)); + } + else + { + OUTPUT_KWH.Values.Add(0); + } + } + analysisDevice.Series.Add(OUTPUT_KWH); + + DeviceHistoryInfo INPUT_KWH = new DeviceHistoryInfo(); + INPUT_KWH.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["INPUT_KWH"]); + INPUT_KWH.YaxesKey = "INPUT_KWH"; + INPUT_KWH.Values = new List(); + foreach (var history in temp_item) + { + if (XAxis.IndexOf(history.TIMESTAMP) > -1) + { + INPUT_KWH.Values.Add(Math.Round(history.INPUT_KWH, 2)); + } + else + { + INPUT_KWH.Values.Add(0); + } + } + analysisDevice.Series.Add(INPUT_KWH); + + DeviceHistoryInfo V_AB = new DeviceHistoryInfo(); + V_AB.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["V_AB"]); + V_AB.YaxesKey = "V_AB"; + V_AB.Values = new List(); + foreach (var history in temp_item) + { + if (XAxis.IndexOf(history.TIMESTAMP) > -1) + { + V_AB.Values.Add(Math.Round(history.V_AB, 2)); + } + else + { + V_AB.Values.Add(0); + } + } + analysisDevice.Series.Add(V_AB); + + DeviceHistoryInfo V_BC = new DeviceHistoryInfo(); + V_BC.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["V_BC"]); + V_BC.YaxesKey = "V_BC"; + V_BC.Values = new List(); + foreach (var history in temp_item) + { + if (XAxis.IndexOf(history.TIMESTAMP) > -1) + { + V_BC.Values.Add(Math.Round(history.V_BC, 2)); + } + else + { + V_BC.Values.Add(0); + } + } + analysisDevice.Series.Add(V_BC); + + DeviceHistoryInfo V_CA = new DeviceHistoryInfo(); + V_CA.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["V_BC"]); + V_CA.YaxesKey = "V_CA"; + V_CA.Values = new List(); + foreach (var history in temp_item) + { + if (XAxis.IndexOf(history.TIMESTAMP) > -1) + { + V_CA.Values.Add(Math.Round(history.V_CA, 2)); + } + else + { + V_CA.Values.Add(0); + } + } + analysisDevice.Series.Add(V_CA); + + DeviceHistoryInfo I_A = new DeviceHistoryInfo(); + I_A.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["I_A"]); + I_A.YaxesKey = "I_A"; + I_A.Values = new List(); + foreach (var history in temp_item) + { + if (XAxis.IndexOf(history.TIMESTAMP) > -1) + { + I_A.Values.Add(Math.Round(history.I_A, 2)); + } + else + { + I_A.Values.Add(0); + } + } + analysisDevice.Series.Add(I_A); + + DeviceHistoryInfo I_B = new DeviceHistoryInfo(); + I_B.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["I_B"]); + I_B.YaxesKey = "I_B"; + I_B.Values = new List(); + foreach (var history in temp_item) + { + if (XAxis.IndexOf(history.TIMESTAMP) > -1) + { + I_B.Values.Add(Math.Round(history.I_B, 2)); + } + else + { + I_B.Values.Add(0); + } + } + analysisDevice.Series.Add(I_B); + + DeviceHistoryInfo I_C = new DeviceHistoryInfo(); + I_C.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["I_C"]); + I_C.YaxesKey = "I_C"; + I_C.Values = new List(); + foreach (var history in temp_item) + { + if (XAxis.IndexOf(history.TIMESTAMP) > -1) + { + I_C.Values.Add(Math.Round(history.I_C, 2)); + } + else + { + I_C.Values.Add(0); + } + } + analysisDevice.Series.Add(I_C); + + DeviceHistoryInfo P = new DeviceHistoryInfo(); + P.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["P"]); + P.YaxesKey = "P"; + P.Values = new List(); + foreach (var history in temp_item) + { + if (XAxis.IndexOf(history.TIMESTAMP) > -1) + { + P.Values.Add(Math.Round(history.P, 2)); + } + else + { + P.Values.Add(0); + } + } + analysisDevice.Series.Add(P); + + DeviceHistoryInfo F = new DeviceHistoryInfo(); + F.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["F"]); + F.YaxesKey = "F"; + F.Values = new List(); + foreach (var history in temp_item) + { + if (XAxis.IndexOf(history.TIMESTAMP) > -1) + { + F.Values.Add(Math.Round(history.F, 2)); + } + else + { + F.Values.Add(0); + } + } + analysisDevice.Series.Add(F); + } + + #endregion + + #region 設備資料 foreach (var devices in deviceDic) { var result = await powerStationRepository.GetSensorAvgByDevices(post.SelectedDate, post.SearchType, devices.Value); @@ -328,6 +535,7 @@ namespace SolarPower.Controllers analysisDevice.Series.Add(deviceHistoryInfo); } } + #endregion analysisDevice.XAxis = XAxis.Distinct().ToList(); diff --git a/SolarPower/Controllers/MyBaseController.cs b/SolarPower/Controllers/MyBaseController.cs index 6c88f24..dffc646 100644 --- a/SolarPower/Controllers/MyBaseController.cs +++ b/SolarPower/Controllers/MyBaseController.cs @@ -90,7 +90,7 @@ namespace SolarPower.Controllers new RouteValueDictionary { {"controller", "Login"}, - {"action", "Index"} + {"action", "SignOut"} }); return; } diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index e9dca8a..096a854 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -239,7 +239,7 @@ namespace SolarPower.Controllers powerStation = await powerStationRepository.GetOneAsync(post.Id); //取得該公司DB Name - var company = await companyRepository.GetOneAsync(myUser.CompanyId); + var company = await companyRepository.GetOneAsync(post.CompanyId); if (powerStation == null) { @@ -263,7 +263,7 @@ namespace SolarPower.Controllers powerStation = new PowerStation() { - CompanyId = myUser.CompanyId, + CompanyId = post.CompanyId, CityId = post.CityId, AreaId = post.AreaId, Address = post.Address, @@ -286,6 +286,9 @@ namespace SolarPower.Controllers PhotovoltaicPanelAmount = post.PhotovoltaicPanelAmount, SiteDB = company.SiteDB, SolarType = post.SolarType, + line_token = post.line_token, + Estimate_kwh = post.Estimate_kwh, + EstimateEfficacy = post.EstimateEfficacy, CreatedBy = myUser.Id }; @@ -314,6 +317,9 @@ namespace SolarPower.Controllers "PhotovoltaicPanelAmount", "SiteDB", "SolarType", + "line_token", + "Estimate_kwh", + "EstimateEfficacy", "CreatedBy" }; @@ -404,6 +410,9 @@ namespace SolarPower.Controllers PhotovoltaicPanelSpecification = post.PhotovoltaicPanelSpecification, PhotovoltaicPanelAmount = post.PhotovoltaicPanelAmount, SolarType = post.SolarType, + line_token = post.line_token, + Estimate_kwh = post.Estimate_kwh, + EstimateEfficacy = post.EstimateEfficacy, UpdatedBy = myUser.Id }; @@ -429,6 +438,9 @@ namespace SolarPower.Controllers "PhotovoltaicPanelSpecification", "PhotovoltaicPanelAmount", "SolarType", + "line_token", + "Estimate_kwh", + "EstimateEfficacy", "UpdatedBy", }; diff --git a/SolarPower/DBSchema/solar_power_schema.sql b/SolarPower/DBSchema/solar_power_schema.sql index 141635b..357a5d1 100644 --- a/SolarPower/DBSchema/solar_power_schema.sql +++ b/SolarPower/DBSchema/solar_power_schema.sql @@ -825,7 +825,7 @@ CREATE TABLE IF NOT EXISTS `variable` ( DELETE FROM `variable`; /*!40000 ALTER TABLE `variable` DISABLE KEYS */; INSERT INTO `variable` (`id`, `name`, `value`, `remark`) VALUES - (1, 'Type', '{"Type":[{"Name":"日照計","EName":"PYR"},{"Name":"模組溫度計","EName":"MTR"},{"Name":"環境溫度計","EName":"ETR"},{"Name":"環境濕度計","EName":"EMM"},{"Name":"風速計","EName":"VAN"},{"Name":" 電表","EName":"PWR"}]}', '裝置類型'); + (1, 'Type', '{"Type":[{"Name":"日照計","EName":"PYR"},{"Name":"模組溫度計","EName":"MTR"},{"Name":"環境溫度計","EName":"ETR"},{"Name":"環境濕度計","EName":"EMM"},{"Name":"風速計","EName":"VAN"},{"Name":" 電錶","EName":"PWR"}]}', '裝置類型'); /*!40000 ALTER TABLE `variable` ENABLE KEYS */; @@ -1983,6 +1983,105 @@ ALTER TABLE `inverter_history_day` ALTER TABLE `inverter_history_month` ADD COLUMN `TOTALKWH` DOUBLE NULL DEFAULT NULL AFTER `TODAYKWH`; +-- 加入電錶每小時歷史紀錄 20210730 +CREATE TABLE `meter_history_hour` ( + `Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `TIMESTAMP` TIMESTAMP NULL DEFAULT NULL, + `METERID` VARCHAR(500) NULL DEFAULT NULL COMMENT '電錶ID' COLLATE 'utf8mb4_unicode_ci', + `V_A` DOUBLE NULL DEFAULT NULL COMMENT '電壓A', + `V_B` DOUBLE NULL DEFAULT NULL COMMENT '電壓B', + `V_C` DOUBLE NULL DEFAULT NULL COMMENT '電壓C', + `V_AB` DOUBLE NULL DEFAULT NULL COMMENT '電壓AB', + `V_BC` DOUBLE NULL DEFAULT NULL COMMENT '電壓BC', + `V_CA` DOUBLE NULL DEFAULT NULL COMMENT '電壓CA', + `I_A` DOUBLE NULL DEFAULT NULL COMMENT '電流A ', + `I_B` DOUBLE NULL DEFAULT NULL COMMENT '電流B', + `I_C` DOUBLE NULL DEFAULT NULL COMMENT '電流C', + `I_AB` DOUBLE NULL DEFAULT NULL COMMENT '電流AB', + `I_BC` DOUBLE NULL DEFAULT NULL COMMENT '電流BC', + `I_CA` DOUBLE NULL DEFAULT NULL COMMENT '電流CA', + `P` DOUBLE NULL DEFAULT NULL COMMENT '有效功率', + `VAR` DOUBLE NULL DEFAULT NULL COMMENT '虛功率', + `S` DOUBLE NULL DEFAULT NULL COMMENT '視在功率', + `F` DOUBLE NULL DEFAULT NULL COMMENT '頻率', + `OUTPUT_KWH` DOUBLE NULL DEFAULT NULL COMMENT '輸出發電量', + `INPUT_KWH` DOUBLE NULL DEFAULT NULL COMMENT '出入發電量', + PRIMARY KEY (`Id`) USING BTREE, + INDEX `IDX_01` (`PowerStationId`) USING BTREE +) +COMMENT='電錶每小時歷史紀錄' +COLLATE='utf8mb4_unicode_ci' +ENGINE=InnoDB +; + +-- 加入電錶每天歷史紀錄 20210730 +CREATE TABLE `meter_history_day` ( + `Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `TIMESTAMP` TIMESTAMP NULL DEFAULT NULL, + `METERID` VARCHAR(500) NULL DEFAULT NULL COMMENT '電錶ID' COLLATE 'utf8mb4_unicode_ci', + `V_A` DOUBLE NULL DEFAULT NULL COMMENT '電壓A', + `V_B` DOUBLE NULL DEFAULT NULL COMMENT '電壓B', + `V_C` DOUBLE NULL DEFAULT NULL COMMENT '電壓C', + `V_AB` DOUBLE NULL DEFAULT NULL COMMENT '電壓AB', + `V_BC` DOUBLE NULL DEFAULT NULL COMMENT '電壓BC', + `V_CA` DOUBLE NULL DEFAULT NULL COMMENT '電壓CA', + `I_A` DOUBLE NULL DEFAULT NULL COMMENT '電流A ', + `I_B` DOUBLE NULL DEFAULT NULL COMMENT '電流B', + `I_C` DOUBLE NULL DEFAULT NULL COMMENT '電流C', + `I_AB` DOUBLE NULL DEFAULT NULL COMMENT '電流AB', + `I_BC` DOUBLE NULL DEFAULT NULL COMMENT '電流BC', + `I_CA` DOUBLE NULL DEFAULT NULL COMMENT '電流CA', + `P` DOUBLE NULL DEFAULT NULL COMMENT '有效功率', + `VAR` DOUBLE NULL DEFAULT NULL COMMENT '虛功率', + `S` DOUBLE NULL DEFAULT NULL COMMENT '視在功率', + `F` DOUBLE NULL DEFAULT NULL COMMENT '頻率', + `OUTPUT_KWH` DOUBLE NULL DEFAULT NULL COMMENT '輸出發電量', + `INPUT_KWH` DOUBLE NULL DEFAULT NULL COMMENT '出入發電量', + PRIMARY KEY (`Id`) USING BTREE, + INDEX `IDX_01` (`PowerStationId`) USING BTREE +) +COMMENT='電錶每天歷史紀錄' +COLLATE='utf8mb4_unicode_ci' +ENGINE=InnoDB +; + +-- 加入電錶每月歷史紀錄 20210730 +CREATE TABLE `meter_history_month` ( + `Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `TIMESTAMP` TIMESTAMP NULL DEFAULT NULL, + `METERID` VARCHAR(500) NULL DEFAULT NULL COMMENT '電錶ID' COLLATE 'utf8mb4_unicode_ci', + `V_A` DOUBLE NULL DEFAULT NULL COMMENT '電壓A', + `V_B` DOUBLE NULL DEFAULT NULL COMMENT '電壓B', + `V_C` DOUBLE NULL DEFAULT NULL COMMENT '電壓C', + `V_AB` DOUBLE NULL DEFAULT NULL COMMENT '電壓AB', + `V_BC` DOUBLE NULL DEFAULT NULL COMMENT '電壓BC', + `V_CA` DOUBLE NULL DEFAULT NULL COMMENT '電壓CA', + `I_A` DOUBLE NULL DEFAULT NULL COMMENT '電流A ', + `I_B` DOUBLE NULL DEFAULT NULL COMMENT '電流B', + `I_C` DOUBLE NULL DEFAULT NULL COMMENT '電流C', + `I_AB` DOUBLE NULL DEFAULT NULL COMMENT '電流AB', + `I_BC` DOUBLE NULL DEFAULT NULL COMMENT '電流BC', + `I_CA` DOUBLE NULL DEFAULT NULL COMMENT '電流CA', + `P` DOUBLE NULL DEFAULT NULL COMMENT '有效功率', + `VAR` DOUBLE NULL DEFAULT NULL COMMENT '虛功率', + `S` DOUBLE NULL DEFAULT NULL COMMENT '視在功率', + `F` DOUBLE NULL DEFAULT NULL COMMENT '頻率', + `OUTPUT_KWH` DOUBLE NULL DEFAULT NULL COMMENT '輸出發電量', + `INPUT_KWH` DOUBLE NULL DEFAULT NULL COMMENT '出入發電量', + PRIMARY KEY (`Id`) USING BTREE, + INDEX `IDX_01` (`PowerStationId`) USING BTREE +) +COMMENT='電錶每月歷史紀錄' +COLLATE='utf8mb4_unicode_ci' +ENGINE=InnoDB +; + + + + /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; /*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */; diff --git a/SolarPower/Models/AnalysisInverter.cs b/SolarPower/Models/AnalysisInverter.cs index f39e70c..7358cab 100644 --- a/SolarPower/Models/AnalysisInverter.cs +++ b/SolarPower/Models/AnalysisInverter.cs @@ -29,6 +29,7 @@ namespace SolarPower.Models public class StationCodeWithInverterIds { + public string Sensor { get; set; } public string SiteDB { get; set; } public string Code { get; set; } public List InverterIds { get; set; } @@ -53,4 +54,10 @@ namespace SolarPower.Models public int PowerStationId { get; set; } public List InverterIds { get; set; } } + + public class StationIdWithMeterIds + { + public int PowerStationId { get; set; } + public List MeterIds { get; set; } + } } diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index b35ad2e..595b4e3 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -131,6 +131,9 @@ namespace SolarPower.Models.PowerStation public double TodayWeatherTemp { get; set; } //今日溫度 public string WeathersStationId { get; set; }//氣象站編號 public string RateOfRain { get; set; }//降雨機率 + public string line_token { get; set; }//line_token + public double Estimate_kwh { get; set; }//預估發電度數 + public double EstimateEfficacy { get; set; }//預估發電效能 public string CreatorName { get; set; } //創建者名稱 } @@ -195,6 +198,10 @@ namespace SolarPower.Models.PowerStation public string PhotovoltaicPanelSpecification { get; set; } //光電板規格 public int PhotovoltaicPanelAmount { get; set; } //光電板規格 public byte SolarType { get; set; } //電站類型 + public string line_token { get; set; }//line_token + public double Estimate_kwh { get; set; }//預估發電度數 + public double EstimateEfficacy { get; set; }//預估發電效能 + public int CompanyId { get; set; } } public class UpdatePowerStationInfo : Updated @@ -218,6 +225,9 @@ namespace SolarPower.Models.PowerStation public string PhotovoltaicPanelSpecification { get; set; } //光電板規格 public int PhotovoltaicPanelAmount { get; set; } //光電板規格 public byte SolarType { get; set; } //電站類型 + public string line_token { get; set; }//line_token + public double Estimate_kwh { get; set; }//預估發電度數 + public double EstimateEfficacy { get; set; }//預估發電效能 } public class PostBoETPCInfo @@ -886,5 +896,30 @@ namespace SolarPower.Models.PowerStation } + public class MeterHistory + { + public string TIMESTAMP { get; set; } + public int PowerStationId { get; set; } + public string METERID { get; set; } + public double V_A { get; set; } + public double V_B { get; set; } + public double V_C { get; set; } + public double V_AB { get; set; } + public double V_BC { get; set; } + public double V_CA { get; set; } + public double I_A { get; set; } + public double I_B { get; set; } + public double I_C { get; set; } + public double I_AB { get; set; } + public double I_BC { get; set; } + public double I_CA { get; set; } + public double P { get; set; } + public double VAR { get; set; } + public double S { get; set; } + public double F { get; set; } + public double OUTPUT_KWH { get; set; } + public double INPUT_KWH { get; set; } + } + } diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 69d5308..c3f75b4 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -1,4 +1,6 @@ -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Quartz; using SolarPower.Models.PowerStation; @@ -17,12 +19,18 @@ namespace SolarPower.Quartz.Jobs private readonly ILogger logger; private readonly IPowerStationRepository powerStationRepository; + public IWebHostEnvironment environment; + private double carbonRate; - public CalcPowerStationJob(ILogger logger, IPowerStationRepository powerStationRepository) + public CalcPowerStationJob( + ILogger logger, + IPowerStationRepository powerStationRepository, + IWebHostEnvironment environment) { this.logger = logger; this.powerStationRepository = powerStationRepository; + this.environment = environment; } public async Task Execute(IJobExecutionContext context) @@ -32,7 +40,10 @@ namespace SolarPower.Quartz.Jobs var DateTimeNow = DateTime.Now; var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH"); - dateTime = "2021-07-26 16"; + if (this.environment.IsDevelopment()) + { + dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH"); + } logger.LogInformation("【CalcPowerStationJob】【任務開始】"); @@ -286,13 +297,17 @@ namespace SolarPower.Quartz.Jobs double shortLocation = 9999; foreach (var Location in observation.Records.Location) { - var powerLocation = powerStation.Coordinate.Split(','); - var nowLocation = Math.Sqrt(Math.Pow(Convert.ToDouble(powerLocation[0]) - Convert.ToDouble(Location.Lat), 2) + Math.Pow(Convert.ToDouble(powerLocation[1]) - Convert.ToDouble(Location.Lon), 2)); - if (nowLocation < shortLocation) + + if(powerStation.Coordinate != null) { - shortLocation = nowLocation; - weatherStationId = Location.StationId; - calcPowerStation.TodayWeatherTemp = Convert.ToDouble(Location.WeatherElement[0].ElementValue); + var powerLocation = powerStation.Coordinate.Split(','); + var nowLocation = Math.Sqrt(Math.Pow(Convert.ToDouble(powerLocation[0]) - Convert.ToDouble(Location.Lat), 2) + Math.Pow(Convert.ToDouble(powerLocation[1]) - Convert.ToDouble(Location.Lon), 2)); + if (nowLocation < shortLocation) + { + shortLocation = nowLocation; + weatherStationId = Location.StationId; + calcPowerStation.TodayWeatherTemp = Convert.ToDouble(Location.WeatherElement[0].ElementValue); + } } } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 95b7fe6..8e4fa4a 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -3748,11 +3748,13 @@ namespace SolarPower.Repository.Implement foreach (var entity in entities) { var table_name = string.Format("`{0}`.`s{1}01_inv`", entity.SiteDB, entity.Code); + var sensor_table_name = string.Format("`{0}`.`s{1}01_sensoravg`", entity.SiteDB, entity.Code); var inverterIds = string.Join("','", entity.InverterIds); var temp_sql = $@"SELECT FROM_UNIXTIME(inv.TIMESTAMP/1000, '%H:%i') AS TIMESTAMP, inv.INVERTERID, + sen.{entity.Sensor} AS Irradiance, ((inv.DC1W + inv.DC2W + inv.DC3W + inv.DC4W + inv.DC5W) / 1000) AS DCKW, ((inv.AC1W + inv.AC2W + inv.AC3W) / 1000) AS ACKW, inv.AC1V, @@ -3797,6 +3799,7 @@ namespace SolarPower.Repository.Implement inv.RA4, inv.RA5 FROM {table_name} inv + LEFT JOIN {sensor_table_name} sen ON FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') = FROM_UNIXTIME(sen.TIMESTAMP/1000, '%Y-%m-%d %H:%i') WHERE FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d') = @NowDay AND INVERTERID IN ('{inverterIds}')"; @@ -4041,7 +4044,7 @@ namespace SolarPower.Repository.Implement } var select_col = string.Join(", ", sql_select_col); - var sql = $"SELECT {select_col} " + sql_sub; + var sql = $"SELECT {select_col} " + sql_sub + " ORDER BY sen.TIMESTAMP"; result = await conn.QueryAsync(sql); } @@ -4117,7 +4120,8 @@ namespace SolarPower.Repository.Implement 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}"; + {where_date} + ORDER BY ps.TIMESTAMP"; result = (await conn.QueryAsync(sql, new { PowerStationId = entities})).ToList(); } @@ -4128,5 +4132,86 @@ namespace SolarPower.Repository.Implement return result; } } + + public async Task> GetMeterHistory(string date, byte searchType, List entities) + { + List 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 = "meter_history_hour"; + where_date = $" AND DATE_FORMAT(m.TIMESTAMP, '%Y-%m-%d') = '{date}'"; + break; + case 1: + date_format = "%Y-%m-%d"; + table_name = "meter_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(m.TIMESTAMP, '%Y-%m-%d') BETWEEN '{start_date}' AND '{end_date}'"; + break; + case 2: + date_format = "%Y-%m-%d"; + table_name = "power_station_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(m.TIMESTAMP, '%Y-%m-%d') BETWEEN '{start_date}' AND '{end_date}'"; + break; + case 3: + date_format = "%Y-%m"; + table_name = "power_station_history_month"; + where_date = $" AND DATE_FORMAT(m.TIMESTAMP, '%Y') = '{date}'"; + break; + } + + List sql_perSiteDB = new List(); + var sql = ""; + foreach (var entity in entities) + { + var meterIds = string.Join("','", entity.MeterIds); + + var temp_sql = $@"SELECT + DATE_FORMAT(m.TIMESTAMP, '{date_format}') AS TIMESTAMP, + m.METERID, + m.V_AB, + m.V_BC, + m.V_CA, + m.I_A, + m.I_B, + m.I_C, + m.P, + m.F, + m.OUTPUT_KWH, + m.INPUT_KWH + FROM {table_name} m + WHERE m.PowerStationId = {entity.PowerStationId} + AND m.METERID IN ('{meterIds}') + {where_date} + ORDER BY m.TIMESTAMP"; + + sql_perSiteDB.Add(temp_sql); + } + sql = string.Join(" UNION ", sql_perSiteDB); + + result = (await conn.QueryAsync(sql)).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 4622774..32a55a8 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -557,5 +557,7 @@ namespace SolarPower.Repository.Interface 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); + + Task> GetMeterHistory(string date, byte searchType, List entities); } } diff --git a/SolarPower/Views/AnalysisInverter/Index.cshtml b/SolarPower/Views/AnalysisInverter/Index.cshtml index ef81084..312c60d 100644 --- a/SolarPower/Views/AnalysisInverter/Index.cshtml +++ b/SolarPower/Views/AnalysisInverter/Index.cshtml @@ -76,7 +76,7 @@ @@ -151,52 +151,51 @@ var analysisInverter; var myXAxis = []; var myYAxis = []; var mySeries = []; var chart; - var default_compare_row_data = ["ACKW"] - var compare_row_data = [ - { key: "Irradiance", title: "日照度"}, - { key: "DCKW", title: "直流功率 (KW)"}, - { key: "ACKW", title: "輸出功率 (KW)"}, - { key: "DC1V", title: "直流電壓1 (V)"}, - { key: "DC1A", title: "直流電流1 (A)"}, - { key: "DC1KW", title: "直流功率1 (KW)"}, - { key: "DC2V", title: "直流電壓2 (V)"}, - { key: "DC2A", title: "直流電流2 (A)"}, - { key: "DC2KW", title: "直流功率2 (KW)"}, - { key: "DC3V", title: "直流電壓3 (V)"}, - { key: "DC3A", title: "直流電流3 (A)"}, - { key: "DC3KW", title: "直流功率3 (KW)"}, - { key: "DC4V", title: "直流電壓4 (V)"}, - { key: "DC4A", title: "直流電流4 (A)"}, - { key: "DC4KW", title: "直流功率4 (KW)"}, - { key: "DC5V", title: "直流電壓5 (V)"}, - { key: "DC5A", title: "直流電流5 (A)"}, - { key: "DC5KW", title: "直流功率5 (KW)"}, - { key: "AC1V", title: "交流電壓A (V)"}, - { key: "AC2V", title: "交流電壓B (V)"}, - { key: "AC3V", title: "交流電壓C (V)"}, - { key: "AC1A", title: "交流電流A (A)"}, - { key: "AC2A", title: "交流電流B (A)"}, - { key: "AC3A", title: "交流電流C (A)"}, - { key: "PR", title: "PR"}, - { key: "RA1", title: "RA1 (%)"}, - { key: "RA2", title: "RA2 (%)"}, - { key: "RA3", title: "RA3 (%)"}, - { key: "RA4", title: "RA4 (%)"}, - { key: "RA5", title: "RA5 (%)"} + var default_compare_col = []; + var current_compare_col = []; + var Single_day_compare_col = [ + { key: "Irradiance", title: "日照度", default: true }, + { key: "DCKW", title: "直流功率 (KW)", default: true }, + { key: "ACKW", title: "輸出功率 (KW)", default: true }, + { key: "DC1V", title: "直流電壓1 (V)", default: false }, + { key: "DC1A", title: "直流電流1 (A)", default: false }, + { key: "DC1KW", title: "直流功率1 (KW)", default: false }, + { key: "DC2V", title: "直流電壓2 (V)", default: false }, + { key: "DC2A", title: "直流電流2 (A)", default: false }, + { key: "DC2KW", title: "直流功率2 (KW)", default: false }, + { key: "DC3V", title: "直流電壓3 (V)", default: false }, + { key: "DC3A", title: "直流電流3 (A)", default: false }, + { key: "DC3KW", title: "直流功率3 (KW)", default: false }, + { key: "DC4V", title: "直流電壓4 (V)", default: false }, + { key: "DC4A", title: "直流電流4 (A)", default: false }, + { key: "DC4KW", title: "直流功率4 (KW)", default: false }, + { key: "DC5V", title: "直流電壓5 (V)", default: false }, + { key: "DC5A", title: "直流電流5 (A)", default: false }, + { key: "DC5KW", title: "直流功率5 (KW)", default: false }, + { key: "AC1V", title: "交流電壓A (V)", default: false }, + { key: "AC2V", title: "交流電壓B (V)", default: false }, + { key: "AC3V", title: "交流電壓C (V)", default: false }, + { key: "AC1A", title: "交流電流A (A)", default: false }, + { key: "AC2A", title: "交流電流B (A)", default: false }, + { key: "AC3A", title: "交流電流C (A)", default: false }, + { key: "PR", title: "PR", default: false }, + { key: "RA1", title: "RA1 (%)", default: false }, + { key: "RA2", title: "RA2 (%)", default: false }, + { key: "RA3", title: "RA3 (%)", default: false }, + { key: "RA4", title: "RA4 (%)", default: false }, + { key: "RA5", title: "RA5 (%)", default: false } ] - - var default_compare_date = ["KWH"] - var compare_date = [ - { key: "Irradiance", title: "日照度"}, - { key: "KWH", title: "KWH"}, - { key: "TodayKWH", title: "TodayKWH"}, - { key: "TotalKWH", title: "TotalKWH"}, - { key: "PR", title: "PR"}, - { key: "RA1", title: "RA1 (%)"}, - { key: "RA2", title: "RA2 (%)"}, - { key: "RA3", title: "RA3 (%)"}, - { key: "RA4", title: "RA4 (%)"}, - { key: "RA5", title: "RA5 (%)"} + var Range_compare_col = [ + { key: "Irradiance", title: "日照度", default: true }, + { key: "KWH", title: "KWH", default: true }, + { key: "TodayKWH", title: "TodayKWH", default: false }, + { key: "TotalKWH", title: "TotalKWH", default: false }, + { key: "PR", title: "PR", default: false }, + { key: "RA1", title: "RA1 (%)", default: false }, + { key: "RA2", title: "RA2 (%)", default: false }, + { key: "RA3", title: "RA3 (%)", default: false }, + { key: "RA4", title: "RA4 (%)", default: false }, + { key: "RA5", title: "RA5 (%)", default: false } ] $(function () { @@ -215,6 +214,7 @@ //#endregion + PushSpecifyCurrentCompareCol(Single_day_compare_col); }) function myfunc(div) { @@ -243,12 +243,7 @@ var today = new Date().toISOString().substring(0, 10); $('#DateGet').val(today); - $("#compare-dropdown-menu").empty(); - var str = ""; - $.each(compare_row_data, function (index, item) { - str += '
  • ' + item.title + '
  • ' - }); - $("#compare-dropdown-menu").append(str); + PushSpecifyCurrentCompareCol(Single_day_compare_col); break; case 1: @@ -284,12 +279,7 @@ //#endregion $('#DateGettext').val(dateLimit_format + ' - ' + today_format); - $("#compare-dropdown-menu").empty(); - var str = ""; - $.each(compare_date, function (index, item) { - str += '
  • ' + item.title + '
  • ' - }); - $("#compare-dropdown-menu").append(str); + PushSpecifyCurrentCompareCol(Range_compare_col); break; case 2: $('#DateGet').prop({ 'type': 'month' }); @@ -298,12 +288,7 @@ var now_month = new Date().toISOString().substring(0, 7); $('#DateGet').val(now_month); - $("#compare-dropdown-menu").empty(); - var str = ""; - $.each(compare_date, function (index, item) { - str += '
  • ' + item.title + '
  • ' - }); - $("#compare-dropdown-menu").append(str); + PushSpecifyCurrentCompareCol(Range_compare_col); break; case 3: @@ -313,12 +298,7 @@ $('#DateGet').prop({ 'type': 'number', 'min': 1900, 'max': now_year, 'step': 1 }); $('#DateGet').val(now_year); - $("#compare-dropdown-menu").empty(); - var str = ""; - $.each(compare_date, function (index, item) { - str += '
  • ' + item.title + '
  • ' - }); - $("#compare-dropdown-menu").append(str); + PushSpecifyCurrentCompareCol(Range_compare_col); break; } @@ -416,7 +396,6 @@ selected_inverter.splice($.inArray({ powerStationId: powerStationId, InverterId: this.value }, selected_inverter), 1); } } - console.log(selected_inverter); }); $('#js_list_accordion').on("change", 'input[name="selectedInverterLayer2[]"]', function (event) { @@ -427,11 +406,15 @@ } }); - $('#compare-dropdown-menu').on('change','input[name="compare_col[]"]', function (e) { + $('#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); + } } ReloadHighCharts(); @@ -518,6 +501,48 @@ }, 'json'); } + //#region 加入已勾選的設備所要顯示得比較欄位 + function PushSpecifyCurrentCompareCol(compare_col) { + + default_compare_col = []; current_compare_col = []; + $.each(compare_col, function (index, item) { + if (!current_compare_col.some(x => x.key == item.key)) { + item.count = 1; + current_compare_col.push(item); + } else { + current_compare_col.find(function (obj, index) { + if (obj.key == item.key) { + current_compare_col[index].count += 1; + } + }); + } + + if (item.default) { + default_compare_col.push(item.key); + } + }); + + console.log("default_compare_col", default_compare_col); + + ChangeCompareSelectOption(); + } + //#endregion + + function ChangeCompareSelectOption() { + $("#compare-dropdown-menu").empty(); + var str = ""; + $.each(current_compare_col, function (index, item) { + 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 GetAnalysisInverter() { var date; @@ -543,20 +568,11 @@ analysisInverter = rel.data; - if (searchType != 0) { - $('input[name="compare_col[]"]').each(function () { - if ($.inArray(this.value, default_compare_date) > -1) { - $(this).prop('checked', true).trigger('change'); - } - }); - } - else { - $('input[name="compare_col[]"]').each(function () { - if ($.inArray(this.value, default_compare_row_data) > -1) { - $(this).prop('checked', true).trigger('change'); - } - }); - } + $('input[name="compare_col[]"]').each(function () { + if ($.inArray(this.value, default_compare_col) > -1) { + $(this).prop('checked', true).trigger('change'); + } + }); ReloadHighCharts(); }, 'json'); @@ -564,6 +580,13 @@ function ReloadHighCharts() { + if (analysisInverter == undefined) { + return; + } + + //彙整出 有被選擇的 要顯示的覽位 + selected_YAxis = default_compare_col.filter(obj1 => current_compare_col.some(obj2 => obj1 == obj2.key)); + myYAxis = []; mySeries = []; myXAxis = analysisInverter.xAxis @@ -601,67 +624,57 @@ 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, + if (myYAxis != undefined && myXAxis != undefined && mySeries != undefined) { + 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 () { - if (searchType == 0) { - var aa = this.value.substr(-2); - if (aa == "00") { - return '' + this.value + ''; + 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 + ''; + return this.value } - } else { - return this.value } } - } - }, - yAxis: myYAxis, + }, + yAxis: myYAxis, - series: mySeries, - }); - - @*$("#container").highcharts({ - chart: { - height: 600 - }, - xAxis: { - categories: myXAxis - }, - yAxis: myYAxis, - - series: mySeries, - });*@ + series: mySeries, + }); + } } } diff --git a/SolarPower/Views/AnalysisStationInfo/Index.cshtml b/SolarPower/Views/AnalysisStationInfo/Index.cshtml index 0de020c..7ae5a1b 100644 --- a/SolarPower/Views/AnalysisStationInfo/Index.cshtml +++ b/SolarPower/Views/AnalysisStationInfo/Index.cshtml @@ -119,19 +119,31 @@ var selected_device = []; var PWS_compare_col = [ { key: "KWH", title: "發電量", default: true }, - { key: "Irradiance", 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 PWR_compare_col = [ + { key: "OUTPUT_KWH", title: "輸出發電量(kWh)", default: true }, + { key: "Irradiance", title: "輸入發電量(kWh)", default: true }, + { key: "V_AB", title: "電壓 AB(V)", default: false }, + { key: "V_BC", title: "電壓 BC(V)", default: false }, + { key: "V_CA", title: "電壓 CA(V)", default: false }, + { key: "I_A", title: "電流 A(A)", default: false }, + { key: "I_B", title: "電流 B(A)", default: false }, + { key: "I_C", title: "電流 C(A)", default: false }, + { key: "P", title: "有效功率(kW)", default: false }, + { key: "F", title: "頻率(Hz)", 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 current_compare_col = []; var default_compare_col = []; var selected_YAxis = []; var analysisStationInfo; @@ -325,28 +337,28 @@ switch (type) { case 'PWS': - PushAllSelectedCompareCol(PWS_compare_col); + PushSpecifyCurrentCompareCol(PWS_compare_col); break; case 'PWR': //電錶 - + PushSpecifyCurrentCompareCol(PWR_compare_col); break; case 'PYR': //日照計 - PushAllSelectedCompareCol(PYR_compare_col); + PushSpecifyCurrentCompareCol(PYR_compare_col); break; case 'ETR': //環境溫度計 - PushAllSelectedCompareCol(ETR_compare_col); + PushSpecifyCurrentCompareCol(ETR_compare_col); break; case 'MTR': //模組溫度計 - PushAllSelectedCompareCol(MTR_compare_col); + PushSpecifyCurrentCompareCol(MTR_compare_col); break; case 'VAN': //風速計 - PushAllSelectedCompareCol(VAN_compare_col); + PushSpecifyCurrentCompareCol(VAN_compare_col); break; case 'FOM': //落塵計 - PushAllSelectedCompareCol(FOM_compare_col); + PushSpecifyCurrentCompareCol(FOM_compare_col); break; case 'EMM': //環境濕度計 - PushAllSelectedCompareCol(EMM_compare_col); + PushSpecifyCurrentCompareCol(EMM_compare_col); break; } } @@ -368,36 +380,35 @@ switch (type) { case 'PWS': - RemoveAllSelectedCompareCol(PWS_compare_col); + RemoveSpecifyCurrentCompareCol(PWS_compare_col); break; case 'PWR': //電錶 - + RemoveSpecifyCurrentCompareCol(PWR_compare_col); break; case 'PYR': //日照計 - RemoveAllSelectedCompareCol(PYR_compare_col); + RemoveSpecifyCurrentCompareCol(PYR_compare_col); break; case 'ETR': //環境溫度計 - RemoveAllSelectedCompareCol(ETR_compare_col); + RemoveSpecifyCurrentCompareCol(ETR_compare_col); break; case 'MTR': //模組溫度計 - RemoveAllSelectedCompareCol(MTR_compare_col); + RemoveSpecifyCurrentCompareCol(MTR_compare_col); break; case 'VAN': //風速計 - RemoveAllSelectedCompareCol(VAN_compare_col); + RemoveSpecifyCurrentCompareCol(VAN_compare_col); break; case 'FOM': //落塵計 - RemoveAllSelectedCompareCol(VAN_compare_col); + RemoveSpecifyCurrentCompareCol(VAN_compare_col); break; case 'EMM': //環境濕度計 - RemoveAllSelectedCompareCol(EMM_compare_col); + RemoveSpecifyCurrentCompareCol(EMM_compare_col); break; } - all_selected_compare_col = all_selected_compare_col.filter(x => x.count > 0); + current_compare_col = current_compare_col.filter(x => x.count > 0); } } - console.log("all_selected_compare_col", all_selected_compare_col); ChangeCompareSelectOption() }); @@ -411,21 +422,15 @@ $('#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) { + 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(); }); @@ -539,16 +544,16 @@ }, 'json'); } - //#region 將設備欄位加入要顯示得比較欄位 - function PushAllSelectedCompareCol(compare_col) { + //#region 加入已勾選的設備所要顯示得比較欄位 + function PushSpecifyCurrentCompareCol(compare_col) { $.each(compare_col, function (index, item) { - if (!all_selected_compare_col.some(x => x.key == item.key)) { + if (!current_compare_col.some(x => x.key == item.key)) { item.count = 1; - all_selected_compare_col.push(item); + current_compare_col.push(item); } else { - all_selected_compare_col.find(function (obj, index) { + current_compare_col.find(function (obj, index) { if (obj.key == item.key) { - all_selected_compare_col[index].count += 1; + current_compare_col[index].count += 1; } }); } @@ -558,35 +563,33 @@ } }); - console.log("default_compare_col", default_compare_col); } //#endregion //#region 將設備欄位移除要顯示得比較欄位 - function RemoveAllSelectedCompareCol(compare_col) { + function RemoveSpecifyCurrentCompareCol(compare_col) { $.each(compare_col, function (index, item) { - all_selected_compare_col.find(function (obj, index) { + current_compare_col.find(function (obj, index) { if (obj.key == item.key) { - all_selected_compare_col[index].count -= 1; + current_compare_col[index].count -= 1; } }); }); - $.each(all_selected_compare_col, function (index, item) { + $.each(current_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); + default_compare_col.splice($.inArray(item.key, default_compare_col), 1); } }); - console.log("default_compare_col", default_compare_col); } //#endregion function ChangeCompareSelectOption() { $("#compare-dropdown-menu").empty(); var str = ""; - $.each(all_selected_compare_col, function (index, item) { + $.each(current_compare_col, function (index, item) { str += '
  • ' + item.title + '
  • ' }); $("#compare-dropdown-menu").append(str); @@ -622,30 +625,30 @@ analysisStationInfo = rel.data; - if (searchType != 0) { - $('input[name="compare_col[]"]').each(function () { - 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_col) > -1) { - $(this).prop('checked', true).trigger('change'); - } - }); - } + $('input[name="compare_col[]"]').each(function () { + if ($.inArray(this.value, default_compare_col) > -1) { + $(this).prop('checked', true).trigger('change'); + } + }); }, 'json'); } function ReloadHighCharts() { + if (analysisStationInfo == undefined) { + return; + } + + //彙整出 有被選擇的 要顯示的覽位 + selected_YAxis = default_compare_col.filter(obj1 => current_compare_col.some(obj2 => obj1 == obj2.key)); + myYAxis = []; mySeries = []; + myXAxis = analysisStationInfo.xAxis + Object.keys(analysisStationInfo.multipleYaxes).map(function (key, index) { if (selected_YAxis.indexOf(key) > -1) { @@ -679,55 +682,57 @@ 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, + if (myYAxis != undefined && myXAxis != undefined && mySeries != undefined) { + 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 () { - if (searchType == 0) { - var aa = this.value.substr(-2); - if (aa == "00") { - return '' + this.value + ''; + 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 + ''; + return this.value } - } else { - return this.value } } - } - }, - yAxis: myYAxis, + }, + yAxis: myYAxis, - series: mySeries, - }); + series: mySeries, + }); + } } } \ No newline at end of file diff --git a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml index 8d9b906..43c1c55 100644 --- a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml +++ b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml @@ -3,11 +3,13 @@ ViewData["SubNum"] = "1"; ViewData["Title"] = "電站管理"; } +@using SolarPower.Models.Role +@model RoleLayerEnum @@ -97,6 +99,25 @@ var url = new URL(location.href); stationId = url.searchParams.get('stationId'); + //#region 預先載入公司下拉式選單select_option + var url_company_select_option = "/Company/GetCompanySelectOptionList"; + $.get(url_company_select_option, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + $("#select_power_station_company").empty(); + + $.each(rel.data, function (index, val) { + $("#select_power_station_company").append($("