From d22ca6f12d7452e2bbffd842aba81bab969ce316 Mon Sep 17 00:00:00 2001 From: "wanling040@gmail.com" Date: Thu, 4 Aug 2022 10:12:21 +0800 Subject: [PATCH] =?UTF-8?q?solar=5FApp:=20=E6=B8=AC=E8=A9=A6irrDayHour?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Views/StationReport/Index.cshtml | 20 +++-- solarApp/Service/procSensorSvc.cs | 91 +++++++++++++++++++-- solarApp/fmArchive.Designer.cs | 34 ++++++-- solarApp/fmArchive.cs | 12 ++- 4 files changed, 133 insertions(+), 24 deletions(-) diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index 3f2b927..8dede79 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -824,7 +824,7 @@ }) str += "小時
發電量
(kWh)"; str += "小時
發電量
百分比
(%)"; - str += "小時
累積
日照度
(W/㎡)"; + str += "累積
日照量
(W/㎡)"; str += "小時
平均
模組
溫度
(°C)"; if (rel.data.showMoney == 1) { str += "小時
售電
金額
(NTD)"; @@ -842,7 +842,7 @@ str += "日照小時(hr)"; str += "日均發電度數"; str += "PR%"; - str += "日
累積
日照度
(W/㎡)"; + str += "累積
日照量
(W/㎡)"; str += "日
平均
模組溫度
(°C)"; if (rel.data.showMoney == 1) { str += "日
售電金額
(NTD)"; @@ -860,7 +860,7 @@ str += "日照小時(hr)"; str += "日均發電度數"; str += "PR%"; - str += "日
累積
日照度
(W/㎡)"; + str += "累積
日照量
(W/㎡)"; str += "日
平均
模組溫度
(°C)"; if (rel.data.showMoney == 1) { str += "日
售電金額
(NTD)"; @@ -895,7 +895,7 @@ str += "日照小時(hr)"; str += "日均發電度數"; str += "PR%"; - str += "月
累積
日照度
(W/㎡)"; + str += "累積
日照量
(W/㎡)"; str += "月
平均
模組溫度
(°C)"; if (rel.data.showMoney == 1) { str += "月
售電金額
(NTD)"; @@ -1026,7 +1026,7 @@ }); sta += "" + toThousands(Number(inverter.hourKWH)) + ""; sta += "" + toThousands(Number(inverter.hourKWHp)) + ""; - sta += "" + toThousands(Number(inverter.irradiance)) + ""; // body 小時平均日照度 + sta += "" + toThousands(Number(inverter.irrDayHour)) + ""; // body 小時平均日照度 irradiance sta += "" + toThousands(Number(inverter.temperature)) + ""; //body 小時平均模組溫度 if (showmoney == 1) { sta += "" + toThousands(Math.round(Number(inverter.hourmoney))) + ""; @@ -1123,7 +1123,7 @@ GeneratingCapacity = inverter.GeneratingCapacity; averageDailyProfit = monthmoney / GeneratingCapacity ? Math.round(monthmoney / GeneratingCapacity * 10000) / 10000 : 0; }) - monthday = rel.data.length; + monthday = (rel.data.length - 1);//最後一筆是總計 var stc = ""; @@ -1537,6 +1537,7 @@ var powerStationTypeName = ""; var kwhkwp = 0; var kwp = 0; + var totalKwh = 0; var totalGeneratingCapacity = 0; $.post(url, send_data, function (rel) { if (rel.code != "0000") { @@ -1641,15 +1642,16 @@ StrInfoBody += ""; kwp += data.kwh; kwhkwp += data.avgKWHKWP; + //totalKwh += data.totalKWH; totalGeneratingCapacity += data.generatingCapacity; }) //中間 $.each(CityArray, function (index, data) { CityInfoBody += ""; CityInfoBody += "" + data.city + ""; - CityInfoBody += "" + data.generatingCapacity + ""; - CityInfoBody += "" + toThousands(data.totalKWH) + ""; - CityInfoBody += "" + toThousands((data.totalKWH / data.generatingCapacity).toFixed(2)) + ""; + CityInfoBody += "" + data.generatingCapacity.toFixed(2) + ""; + CityInfoBody += "" + toThousands(data.kwp.toFixed(2)) + ""; + CityInfoBody += "" + toThousands((data.kwp / data.generatingCapacity).toFixed(2)) + ""; CityInfoBody += ""; }) //上面 diff --git a/solarApp/Service/procSensorSvc.cs b/solarApp/Service/procSensorSvc.cs index 58ec3eb..37cf91b 100644 --- a/solarApp/Service/procSensorSvc.cs +++ b/solarApp/Service/procSensorSvc.cs @@ -73,6 +73,26 @@ namespace solarApp.Service return result; } + public bool archiveData_test(string siteID, string date1) + { + + bool result = false; + //try + //{ + _siteID = siteID; + _date1 = date1; + get_siteInfo(); + // clearData(); + update_invdayhour(); + result = true; + //} + //catch (Exception ex) + //{ + // throw ex; + //} + return result; + } + /// /// 清除指定期間、指定電站的 Sensor hour、day、month 資料 /// @@ -268,14 +288,31 @@ namespace solarApp.Service arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd); //irrDayHour計算 - sql = $@"update sensor_history_hour a join ( - select LEFT(DATE_ADD(`TIMESTAMP`, INTERVAL +1 hour), 13) hour_1, irrday - from sensor_history_hour a - where powerstationID = {_powerStationID} and LEFT(a.TIMESTAMP, 10 ) = '{_date1}' - - )b on LEFT(a.`TIMESTAMP`, 13) = hour_1 - Set irrDayhour = case when a.`irrday` - b.`irrday` < 0 then 0 else a.`irrday` - b.`irrday` end - where a.powerstationID = {_powerStationID}"; + //sql = $@"update sensor_history_hour a join ( + // select LEFT(DATE_ADD(`TIMESTAMP`, INTERVAL +1 hour), 13) hour_1, irrday + // from sensor_history_hour a + // where powerstationID = {_powerStationID} and LEFT(a.TIMESTAMP, 10 ) = '{_date1}' + + // )b on LEFT(a.`TIMESTAMP`, 13) = hour_1 + // Set irrDayhour = case when a.`irrday` - b.`irrday` < 0 then 0 else a.`irrday` - b.`irrday` end + // where a.powerstationID = {_powerStationID}"; + + //dt_start2 = DateTime.Now; + //cmd.CommandText = sql; + //int rowCT2 = cmd.ExecuteNonQuery(); + //cmd.Parameters.Clear(); + //duration = DateTime.Now - dt_start2; + //arclog.insert_log(_powerStationID, "sensor step1 for irrDayHour", duration.TotalSeconds, "sensor_history_hour", "update sensor hour", "0", "", rowCT2.ToString(), conn, cmd); + + + sql = $@"update sensor_history_hour a join + ( + select powerstationID, `TIMESTAMP`, irrday - + (select irrday from sensor_history_hour where powerstationID = {_powerStationID} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(_date1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour + from sensor_history_hour z + where powerstationID = {_powerStationID} and LEFT(z.`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(_date1).ToString("yyyy-MM-dd HH")}' + ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP` + Set a.irrdayhour = b.irrdayhour where a.powerstationID = {_powerStationID}"; dt_start2 = DateTime.Now; cmd.CommandText = sql; @@ -573,5 +610,43 @@ namespace solarApp.Service return result; } + + bool update_invdayhour() + { + bool result = false; + try + { + procArchiveLog arclog = new procArchiveLog(); + using (MySqlConnection conn = new MySqlConnection(Connection1)) + { + conn.Open(); + string sql = $@"update sensor_history_hour a join + ( + select powerstationID, `TIMESTAMP`, irrday - + (select irrday from sensor_history_hour where powerstationID = {_powerStationID} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(_date1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour + from sensor_history_hour z + where powerstationID = {_powerStationID} and LEFT(z.`TIMESTAMP`, 13 ) = '{(Convert.ToDateTime(_date1)).ToString("yyyy-MM-dd HH")}' + ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP` + Set a.irrdayhour = b.irrdayhour where a.powerstationID = {_powerStationID}"; + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + cmd.CommandTimeout = 720; + DateTime dt_start2 = DateTime.Now; + cmd.CommandText = sql; + int rowCT2 = cmd.ExecuteNonQuery(); + dt_start2 = DateTime.Now; + TimeSpan duration = DateTime.Now - dt_start2; + arclog.insert_log(_powerStationID, "sensor step1 for irrDayHour", duration.TotalSeconds, "sensor_history_hour", "update sensor hour", "0", "", rowCT2.ToString(), conn, cmd); + } + result = true; + } + catch (Exception ex) + { + throw ex; + } + return result; + + } + } } diff --git a/solarApp/fmArchive.Designer.cs b/solarApp/fmArchive.Designer.cs index 910b07a..f5ff187 100644 --- a/solarApp/fmArchive.Designer.cs +++ b/solarApp/fmArchive.Designer.cs @@ -30,8 +30,8 @@ namespace solarApp private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); @@ -84,6 +84,8 @@ namespace solarApp this.tabPage3 = new System.Windows.Forms.TabPage(); this.button1 = new System.Windows.Forms.Button(); this.timer1 = new System.Windows.Forms.Timer(this.components); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); @@ -135,6 +137,8 @@ namespace solarApp // splitContainer1.Panel1 // this.splitContainer1.Panel1.BackColor = System.Drawing.SystemColors.ActiveCaption; + this.splitContainer1.Panel1.Controls.Add(this.label2); + this.splitContainer1.Panel1.Controls.Add(this.textBox1); this.splitContainer1.Panel1.Controls.Add(this.button2); this.splitContainer1.Panel1.Controls.Add(this.bt_archive_One); this.splitContainer1.Panel1.Controls.Add(this.bt_lackStation); @@ -357,8 +361,8 @@ namespace solarApp // this.gv_inv_detail.AllowUserToAddRows = false; this.gv_inv_detail.AllowUserToDeleteRows = false; - dataGridViewCellStyle3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); - this.gv_inv_detail.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle3; + dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); + this.gv_inv_detail.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; this.gv_inv_detail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.gv_inv_detail.Dock = System.Windows.Forms.DockStyle.Fill; this.gv_inv_detail.Location = new System.Drawing.Point(768, 75); @@ -374,8 +378,8 @@ namespace solarApp // this.gv_rpt_invDay.AllowUserToAddRows = false; this.gv_rpt_invDay.AllowUserToDeleteRows = false; - dataGridViewCellStyle4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); - this.gv_rpt_invDay.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle4; + dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); + this.gv_rpt_invDay.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle2; this.gv_rpt_invDay.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.gv_rpt_invDay.Dock = System.Windows.Forms.DockStyle.Left; this.gv_rpt_invDay.Location = new System.Drawing.Point(0, 75); @@ -697,6 +701,22 @@ namespace solarApp // this.timer1.Interval = 10000; // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(244, 536); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(125, 27); + this.textBox1.TabIndex = 18; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(196, 539); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(42, 19); + this.label2.TabIndex = 19; + this.label2.Text = "小時:"; + // // fmArchive // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 19F); @@ -785,5 +805,7 @@ namespace solarApp private System.Windows.Forms.TabPage tabPage3; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox textBox1; } } \ No newline at end of file diff --git a/solarApp/fmArchive.cs b/solarApp/fmArchive.cs index a758674..03eb82f 100644 --- a/solarApp/fmArchive.cs +++ b/solarApp/fmArchive.cs @@ -663,7 +663,17 @@ namespace solarApp private void button2_Click(object sender, EventArgs e) { - + string date1 = dtSelect1.Value.ToString("yyyy-MM-dd") + " "+textBox1.Text + ":00:00"; + string date2 = dtSelect2.Value.ToString("yyyy-MM-dd") + " " +textBox1.Text + ":00:00"; + //foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) + //{ + //sensorSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); + //invSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); + //siteSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); + //invSvc.report_invDay(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); + procSensorSvc procSensor = new procSensorSvc(); + procSensor.archiveData_test(lbSiteID_sensor.Text.Substring(0, 9), date1); + //} } } }