solar_App: 測試irrDayHour更新

This commit is contained in:
wanling040@gmail.com 2022-08-04 10:12:21 +08:00
parent 41fac9bc24
commit d22ca6f12d
4 changed files with 133 additions and 24 deletions

View File

@ -824,7 +824,7 @@
})
str += "<th>小時<br />發電量<br />(kWh)</th>";
str += "<th>小時<br />發電量<br />百分比<br />(%)</th>";
str += "<th>小時<br />累積<br />日照度<br />(W/㎡)</th>";
str += "<th>累積<br />日照量<br />(W/㎡)</th>";
str += "<th>小時<br />平均<br />模組<br />溫度<br />(°C)</th>";
if (rel.data.showMoney == 1) {
str += "<th>小時<br />售電<br />金額<br />(NTD)</th>";
@ -842,7 +842,7 @@
str += "<th>日照小時(hr)</th>";
str += "<th>日均發電度數</th>";
str += "<th>PR%</th>";
str += "<th>日<br />累積<br />日照度<br />(W/㎡)</th>";
str += "<th>累積<br />日照量<br />(W/㎡)</th>";
str += "<th>日<br />平均<br />模組溫度<br />(°C)</th>";
if (rel.data.showMoney == 1) {
str += "<th>日<br />售電金額<br />(NTD)</th>";
@ -860,7 +860,7 @@
str += "<th>日照小時(hr)</th>";
str += "<th>日均發電度數</th>";
str += "<th>PR%</th>";
str += "<th>日<br />累積<br />日照度<br />(W/㎡)</th>";
str += "<th>累積<br />日照量<br />(W/㎡)</th>";
str += "<th>日<br />平均<br />模組溫度<br />(°C)</th>";
if (rel.data.showMoney == 1) {
str += "<th>日<br />售電金額<br />(NTD)</th>";
@ -895,7 +895,7 @@
str += "<th>日照小時(hr)</th>";
str += "<th>日均發電度數</th>";
str += "<th>PR%</th>";
str += "<th>月<br />累積<br />日照度<br />(W/㎡)</th>";
str += "<th>累積<br />日照量<br />(W/㎡)</th>";
str += "<th>月<br />平均<br />模組溫度<br />(°C)</th>";
if (rel.data.showMoney == 1) {
str += "<th>月<br />售電金額<br />(NTD)</th>";
@ -1026,7 +1026,7 @@
});
sta += "<td>" + toThousands(Number(inverter.hourKWH)) + "</td>";
sta += "<td>" + toThousands(Number(inverter.hourKWHp)) + "</td>";
sta += "<td>" + toThousands(Number(inverter.irradiance)) + "</td>"; // body 小時平均日照度
sta += "<td>" + toThousands(Number(inverter.irrDayHour)) + "</td>"; // body 小時平均日照度 irradiance
sta += "<td>" + toThousands(Number(inverter.temperature)) + "</td>"; //body 小時平均模組溫度
if (showmoney == 1) {
sta += "<td>" + toThousands(Math.round(Number(inverter.hourmoney))) + "</td>";
@ -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 = "<tr>";
@ -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 += "</tr>";
kwp += data.kwh;
kwhkwp += data.avgKWHKWP;
//totalKwh += data.totalKWH;
totalGeneratingCapacity += data.generatingCapacity;
})
//中間
$.each(CityArray, function (index, data) {
CityInfoBody += "<tr>";
CityInfoBody += "<td>" + data.city + "</td>";
CityInfoBody += "<td>" + data.generatingCapacity + "</td>";
CityInfoBody += "<td>" + toThousands(data.totalKWH) + "</td>";
CityInfoBody += "<td>" + toThousands((data.totalKWH / data.generatingCapacity).toFixed(2)) + "</td>";
CityInfoBody += "<td>" + data.generatingCapacity.toFixed(2) + "</td>";
CityInfoBody += "<td>" + toThousands(data.kwp.toFixed(2)) + "</td>";
CityInfoBody += "<td>" + toThousands((data.kwp / data.generatingCapacity).toFixed(2)) + "</td>";
CityInfoBody += "</tr>";
})
//上面

View File

@ -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;
}
/// <summary>
/// 清除指定期間、指定電站的 Sensor hour、day、month 資料
/// </summary>
@ -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;
}
}
}

View File

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

View File

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