測試累計日照量相減

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;
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}'
// 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}";
//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}";
)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;
@ -320,6 +303,23 @@ namespace solarApp.Service
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;
//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
#region day
@ -616,6 +616,7 @@ namespace solarApp.Service
bool result = false;
try
{
MySqlCommand cmd = new MySqlCommand();
procArchiveLog arclog = new procArchiveLog();
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
@ -627,8 +628,8 @@ namespace solarApp.Service
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();
Set a.irrdayhour = case when b.irrdayhour < 0 then 0 else b.irrdayhour end
where a.powerstationID = {_powerStationID}";
cmd.Connection = conn;
cmd.CommandTimeout = 720;
DateTime dt_start2 = DateTime.Now;

View File

@ -35,6 +35,8 @@ namespace solarApp
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
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.bt_archive_One = 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.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();
@ -168,15 +168,34 @@ namespace solarApp
this.splitContainer1.SplitterWidth = 10;
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
//
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.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.Text = "Sensor 歸檔";
this.button2.Text = "測試當下 irrdayHour";
this.button2.UseVisualStyleBackColor = true;
this.button2.Visible = false;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// bt_archive_One
@ -699,23 +718,7 @@ namespace solarApp
//
// timer1
//
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 = "小時:";
this.timer1.Interval = 1000;
//
// fmArchive
//

View File

@ -16,6 +16,7 @@ namespace solarApp
{
getStationSvc stationSvc = new getStationSvc();
System.Timers.Timer _timer;
bool autoTask = false; //測試自動跑 irrDayHour 累計日照小時差異
public fmArchive()
{
InitializeComponent();
@ -98,9 +99,10 @@ namespace solarApp
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");
autoTask = true;
lbMsgTitle.Text = DateTime.Now.ToString() + " timer start";
dtSelect1.Value = System.DateTime.Now.AddDays(-1);
dtSelect2.Value = System.DateTime.Now.AddDays(-1);
@ -108,20 +110,35 @@ namespace solarApp
//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;
var site_list = stationSvc.get_station_list();
archiveLowData archiveData = new archiveLowData();
autoTask = true;
foreach (var item in site_list)
{
archiveData.archiveData(item.SiteID.Substring(0, 9));
i++;
}
autoTask = false;
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 水位管理 - 資料搬移完成!";
}
}
@ -271,6 +288,7 @@ namespace solarApp
}
i++;
}
autoTask = true;
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 完成!";
}
@ -663,17 +681,22 @@ 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"));
// string date1 = dtSelect1.Value.ToString("yyyy-MM-dd") + " "+System.DateTime.Now.AddHours(-2) + ":00:00";
string date1 = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd HH") + ":00:00";
if (textBox1.Text.Trim().Length > 0)
{
date1 = dtSelect1.Value.ToString("yyyy-MM-dd ") + textBox1.Text + ":00:00";
}
var site_list = stationSvc.get_station_list();
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 - 完成!";
}
}
}