測試累計日照量相減

This commit is contained in:
cesar liu 2022-08-04 16:02:14 +08:00
parent d22ca6f12d
commit 828492513c
3 changed files with 89 additions and 62 deletions

View File

@ -287,32 +287,15 @@ namespace solarApp.Service
TimeSpan duration = DateTime.Now - dt_start2; TimeSpan duration = DateTime.Now - dt_start2;
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd); arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd);
//irrDayHour計算 // irrDayHour計算
//sql = $@"update sensor_history_hour a join ( sql = $@"update sensor_history_hour a join (
// select LEFT(DATE_ADD(`TIMESTAMP`, INTERVAL +1 hour), 13) hour_1, irrday select LEFT(DATE_ADD(`TIMESTAMP`, INTERVAL +1 hour), 13) hour_1, irrday
// from sensor_history_hour a from sensor_history_hour a
// where powerstationID = {_powerStationID} and LEFT(a.TIMESTAMP, 10 ) = '{_date1}' where powerstationID = {_powerStationID} and LEFT(a.TIMESTAMP, 10 ) = '{_date1}'
// )b on LEFT(a.`TIMESTAMP`, 13) = hour_1 )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 Set irrDayhour = case when a.`irrday` - b.`irrday` < 0 then 0 else a.`irrday` - b.`irrday` end
// where a.powerstationID = {_powerStationID}"; 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; dt_start2 = DateTime.Now;
cmd.CommandText = sql; cmd.CommandText = sql;
@ -320,6 +303,23 @@ namespace solarApp.Service
cmd.Parameters.Clear(); cmd.Parameters.Clear();
duration = DateTime.Now - dt_start2; 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); 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;
//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);
#endregion hour #endregion hour
#region day #region day
@ -616,6 +616,7 @@ namespace solarApp.Service
bool result = false; bool result = false;
try try
{ {
MySqlCommand cmd = new MySqlCommand();
procArchiveLog arclog = new procArchiveLog(); procArchiveLog arclog = new procArchiveLog();
using (MySqlConnection conn = new MySqlConnection(Connection1)) using (MySqlConnection conn = new MySqlConnection(Connection1))
{ {
@ -627,8 +628,8 @@ namespace solarApp.Service
from sensor_history_hour z from sensor_history_hour z
where powerstationID = {_powerStationID} and LEFT(z.`TIMESTAMP`, 13 ) = '{(Convert.ToDateTime(_date1)).ToString("yyyy-MM-dd HH")}' 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` ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP`
Set a.irrdayhour = b.irrdayhour where a.powerstationID = {_powerStationID}"; Set a.irrdayhour = case when b.irrdayhour < 0 then 0 else b.irrdayhour end
MySqlCommand cmd = new MySqlCommand(); where a.powerstationID = {_powerStationID}";
cmd.Connection = conn; cmd.Connection = conn;
cmd.CommandTimeout = 720; cmd.CommandTimeout = 720;
DateTime dt_start2 = DateTime.Now; DateTime dt_start2 = DateTime.Now;

View File

@ -35,6 +35,8 @@ namespace solarApp
this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage1 = new System.Windows.Forms.TabPage();
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button();
this.bt_archive_One = new System.Windows.Forms.Button(); this.bt_archive_One = new System.Windows.Forms.Button();
this.bt_lackStation = new System.Windows.Forms.Button(); this.bt_lackStation = new System.Windows.Forms.Button();
@ -84,8 +86,6 @@ namespace solarApp
this.tabPage3 = new System.Windows.Forms.TabPage(); this.tabPage3 = new System.Windows.Forms.TabPage();
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components); 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.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout(); this.tabPage1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
@ -168,15 +168,34 @@ namespace solarApp
this.splitContainer1.SplitterWidth = 10; this.splitContainer1.SplitterWidth = 10;
this.splitContainer1.TabIndex = 0; this.splitContainer1.TabIndex = 0;
// //
// 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 = "小時:";
this.label2.Visible = false;
//
// 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;
this.textBox1.Visible = false;
//
// button2 // button2
// //
this.button2.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.button2.Font = new System.Drawing.Font("Microsoft JhengHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.button2.Location = new System.Drawing.Point(170, 576); this.button2.Location = new System.Drawing.Point(170, 576);
this.button2.Name = "button2"; this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(135, 44); this.button2.Size = new System.Drawing.Size(227, 44);
this.button2.TabIndex = 17; this.button2.TabIndex = 17;
this.button2.Text = "Sensor 歸檔"; this.button2.Text = "測試當下 irrdayHour";
this.button2.UseVisualStyleBackColor = true; this.button2.UseVisualStyleBackColor = true;
this.button2.Visible = false;
this.button2.Click += new System.EventHandler(this.button2_Click); this.button2.Click += new System.EventHandler(this.button2_Click);
// //
// bt_archive_One // bt_archive_One
@ -699,23 +718,7 @@ namespace solarApp
// //
// timer1 // timer1
// //
this.timer1.Interval = 10000; this.timer1.Interval = 1000;
//
// 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 // fmArchive
// //

View File

@ -16,6 +16,7 @@ namespace solarApp
{ {
getStationSvc stationSvc = new getStationSvc(); getStationSvc stationSvc = new getStationSvc();
System.Timers.Timer _timer; System.Timers.Timer _timer;
bool autoTask = false; //測試自動跑 irrDayHour 累計日照小時差異
public fmArchive() public fmArchive()
{ {
InitializeComponent(); InitializeComponent();
@ -98,9 +99,10 @@ namespace solarApp
private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
//每日歸檔 //每日歸檔
if (System.DateTime.Now.Hour == 00 && DateTime.Now.Minute == 15) if (System.DateTime.Now.Hour == 00 && DateTime.Now.Minute == 15 && autoTask == false)
{ {
//MessageBox.Show("ok"); //MessageBox.Show("ok");
autoTask = true;
lbMsgTitle.Text = DateTime.Now.ToString() + " timer start"; lbMsgTitle.Text = DateTime.Now.ToString() + " timer start";
dtSelect1.Value = System.DateTime.Now.AddDays(-1); dtSelect1.Value = System.DateTime.Now.AddDays(-1);
dtSelect2.Value = System.DateTime.Now.AddDays(-1); dtSelect2.Value = System.DateTime.Now.AddDays(-1);
@ -108,20 +110,35 @@ namespace solarApp
//bt_archive_Click.PerformClick(); //bt_archive_Click.PerformClick();
} }
//臨時的 累計日照
//if (DateTime.Now.Minute == 39 && (DateTime.Now.Second >= 0 && DateTime.Now.Second <= 10) && autoTask == false)
//{
// //MessageBox.Show("ok");
// autoTask = true;
// lbMsgTitle.Text = DateTime.Now.ToString() + " 臨時的 累計日照 start";
// button2.PerformClick();
// //bt_archive_Click.PerformClick();
//}
//水位管理 //水位管理
if (System.DateTime.Now.Hour == 03 && DateTime.Now.Minute == 30 && DateTime.Now.Second == 00) if (System.DateTime.Now.Hour == 03 && DateTime.Now.Minute == 30
&& (DateTime.Now.Second >= 0 && DateTime.Now.Second <= 10)
&& autoTask == false)
{ {
int i = 0; int i = 0;
var site_list = stationSvc.get_station_list(); var site_list = stationSvc.get_station_list();
archiveLowData archiveData = new archiveLowData(); archiveLowData archiveData = new archiveLowData();
autoTask = true;
foreach (var item in site_list) foreach (var item in site_list)
{ {
archiveData.archiveData(item.SiteID.Substring(0, 9)); archiveData.archiveData(item.SiteID.Substring(0, 9));
i++; i++;
} }
autoTask = false;
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 水位管理 - 資料搬移完成!"; lbMsgTitle.Text = System.DateTime.Now.ToString() + " 水位管理 - 資料搬移完成!";
} }
} }
@ -271,6 +288,7 @@ namespace solarApp
} }
i++; i++;
} }
autoTask = true;
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 完成!"; lbMsgTitle.Text = System.DateTime.Now.ToString() + " 完成!";
} }
@ -663,17 +681,22 @@ namespace solarApp
private void button2_Click(object sender, EventArgs e) private void button2_Click(object sender, EventArgs e)
{ {
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd") + " "+textBox1.Text + ":00:00"; // string date1 = dtSelect1.Value.ToString("yyyy-MM-dd") + " "+System.DateTime.Now.AddHours(-2) + ":00:00";
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd") + " " +textBox1.Text + ":00:00"; string date1 = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd HH") + ":00:00";
//foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2))) if (textBox1.Text.Trim().Length > 0)
//{ {
//sensorSvc.archiveData(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd")); date1 = dtSelect1.Value.ToString("yyyy-MM-dd ") + textBox1.Text + ":00:00";
//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")); var site_list = stationSvc.get_station_list();
procSensorSvc procSensor = new procSensorSvc(); procSensorSvc procSensor = new procSensorSvc();
procSensor.archiveData_test(lbSiteID_sensor.Text.Substring(0, 9), date1); foreach (var item in site_list)
//} {
procSensor.archiveData_test(item.SiteID.Substring(0, 9), date1);
}
autoTask = false;
lbMsgTitle.Text = System.DateTime.Now.ToString() + " invdayhour - 完成!";
} }
} }
} }