修正累計日照相減
This commit is contained in:
parent
cb772ef326
commit
3b83eff95f
@ -182,10 +182,12 @@ namespace solarApp.Service
|
|||||||
else result = "0";
|
else result = "0";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool insert_sensor()
|
bool insert_sensor()
|
||||||
{
|
{
|
||||||
procArchiveLog arclog = new procArchiveLog();
|
procArchiveLog arclog = new procArchiveLog();
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
bool isFirst = true;
|
||||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||||
{
|
{
|
||||||
conn.Open();
|
conn.Open();
|
||||||
@ -271,21 +273,21 @@ namespace solarApp.Service
|
|||||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 " + irrNot0 + @" #需要過濾 0 的數值
|
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 " + irrNot0 + @" #需要過濾 0 的數值
|
||||||
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H')
|
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H')
|
||||||
)b on a.reportdate = b.reportdate";
|
)b on a.reportdate = b.reportdate";
|
||||||
//MySqlCommand cmd = new MySqlCommand(sql, conn);
|
//MySqlCommand cmd = new MySqlCommand(sql, conn);
|
||||||
//cmd.Parameters()
|
//cmd.Parameters()
|
||||||
//cmd.ExecuteNonQuery();
|
//cmd.ExecuteNonQuery();
|
||||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||||
MySqlCommand cmd = new MySqlCommand();
|
MySqlCommand cmd = new MySqlCommand();
|
||||||
cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
cmd.CommandTimeout = 720;
|
cmd.CommandTimeout = 720;
|
||||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||||
cmd.CommandText = sql;
|
cmd.CommandText = sql;
|
||||||
int rowCT = cmd.ExecuteNonQuery();
|
int rowCT = cmd.ExecuteNonQuery();
|
||||||
cmd.Parameters.Clear();
|
cmd.Parameters.Clear();
|
||||||
DateTime dt_start2 = DateTime.Now;
|
DateTime dt_start2 = DateTime.Now;
|
||||||
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 (
|
||||||
@ -296,16 +298,28 @@ namespace solarApp.Service
|
|||||||
// )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}";
|
||||||
sql = $@"DROP TEMPORARY TABLE IF EXISTS `temp_s1`;
|
if (isFirst)
|
||||||
create TEMPORARY TABLE temp_s1
|
{
|
||||||
select `TIMESTAMP`, irrday
|
sql = $@"DROP TEMPORARY TABLE IF EXISTS `temp_s1`;
|
||||||
|
create TEMPORARY TABLE temp_s1
|
||||||
|
select powerstationID, `TIMESTAMP`, irrday
|
||||||
from sensor_history_hour a
|
from sensor_history_hour a
|
||||||
where powerstationID = {_powerStationID} and LEFT(a.TIMESTAMP, 10 ) = '{_date1}';
|
where LEFT(a.TIMESTAMP, 10 ) = '{_date1}';
|
||||||
|
ALTER TABLE `temp_s1` ADD INDEX `temp_indexs1` (powerstationID, `TIMESTAMP`);";
|
||||||
update sensor_history_hour a join temp_s1 b on LEFT(a.`TIMESTAMP`, 13) = LEFT(b.`TIMESTAMP`, 13)
|
dt_start2 = DateTime.Now;
|
||||||
Set irrDayhour = case when a.`irrday` - b.`irrday` < 0 then 0 else a.`irrday` - b.`irrday` end
|
cmd.CommandText = sql;
|
||||||
where LEFT(a.TIMESTAMP, 10 ) = '{_date1}' and a.powerstationID = {_powerStationID}";
|
int updateCT = cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.Clear();
|
||||||
|
duration = DateTime.Now - dt_start2;
|
||||||
|
arclog.insert_log(_powerStationID, "sensor step0 irrDayHour init", duration.TotalSeconds, "sensor_history_hour", "update sensor hour", "0", "", updateCT.ToString(), conn, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
sql = $@" update sensor_history_hour a join
|
||||||
|
(select powerstationID, LEFT(DATE_ADD(`TIMESTAMP`, INTERVAL +1 hour), 13) hour_1, irrday from temp_s1 ) b
|
||||||
|
on LEFT(a.`TIMESTAMP`, 13) = hour_1 and a.powerstationID = b.powerstationID
|
||||||
|
Set irrDayhour = case when a.`irrday` - b.`irrday` < 0 then 0 else a.`irrday` - b.`irrday` end
|
||||||
|
where LEFT(a.TIMESTAMP, 10 ) = '{_date1}'
|
||||||
|
and a.powerstationID = {_powerStationID} ";
|
||||||
dt_start2 = DateTime.Now;
|
dt_start2 = DateTime.Now;
|
||||||
cmd.CommandText = sql;
|
cmd.CommandText = sql;
|
||||||
int rowCT2 = cmd.ExecuteNonQuery();
|
int rowCT2 = cmd.ExecuteNonQuery();
|
||||||
@ -336,7 +350,7 @@ namespace solarApp.Service
|
|||||||
select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust, a.WingDirection, a.irrDay, a.irrDayHour from
|
select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust, a.WingDirection, a.irrDay, a.irrDayHour from
|
||||||
(
|
(
|
||||||
select powerStationID , concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00') reportdate, round(avg(Temperature), 6) Temperature,
|
select powerStationID , concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00') reportdate, round(avg(Temperature), 6) Temperature,
|
||||||
envTemperature, humidity, Vane, Dust, avg(WingDirection) WingDirection, max(irrDay) irrDay, sum(irrDayHour) irrDayHour
|
envTemperature, humidity, Vane, Dust, avg(WingDirection) WingDirection, max(irrDay) irrDay, max(irrDay) irrDayHour
|
||||||
from solar_master.sensor_history_hour
|
from solar_master.sensor_history_hour
|
||||||
where powerstationID = @powerstationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1
|
where powerstationID = @powerstationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1
|
||||||
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d')
|
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d')
|
||||||
@ -661,5 +675,323 @@ namespace solarApp.Service
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool insert_sensor_irrdayHour()
|
||||||
|
{
|
||||||
|
procArchiveLog arclog = new procArchiveLog();
|
||||||
|
bool result = false;
|
||||||
|
bool isFirst = true;
|
||||||
|
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
string sql;
|
||||||
|
// init 關閉 group full column
|
||||||
|
sql = @"SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY,',''));";
|
||||||
|
conn.Execute(sql);
|
||||||
|
|
||||||
|
#region 獲取 Sensor 類別
|
||||||
|
//沒有被刪除、啟用中、狀態正常的 才可列入計算
|
||||||
|
//sql = @"select a.id, CONCAT( left(UID, 9) ,'01') SiteID, a.`name` sensorName, type, DBName, TableName, colname
|
||||||
|
// from " + _siteDB + @".device a
|
||||||
|
// where left(UID, 11) = @siteID and deleted = 0 and enabled = 1 and `status` = 1 ";
|
||||||
|
sql = @$"select a.id, CONCAT( {_siteID} ,'01') SiteID, a.`name` sensorName, type, DBName, TableName, colname
|
||||||
|
from {_siteDB}.device a left join {_siteDB}.sharedevice b on a.id = b.deviceID
|
||||||
|
where (left(UID, 11) = @siteID or b.PowerStationID = {_powerStationID}) and deleted = 0 and enabled = 1 and `status` = 1 ";
|
||||||
|
List<sensor_model> ds_sensor = conn.Query<sensor_model>(sql, new { siteID = _siteID01 }).AsList<sensor_model>();
|
||||||
|
|
||||||
|
//欄位處理
|
||||||
|
// { "Type":[
|
||||||
|
// { "Name":"日照計","EName":"PYR"},
|
||||||
|
// { "Name":"模組溫度計","EName":"MTR"},
|
||||||
|
// { "Name":"環境溫度計","EName":"ETR"},
|
||||||
|
// { "Name":"環境濕度計","EName":"EMM"},
|
||||||
|
// { "Name":"風速計","EName":"VAN"},
|
||||||
|
// { "Name":" 電表","EName":"PWR"}]}
|
||||||
|
// { "Name":"風向計","EName":"WIN"}]}
|
||||||
|
// { "Name":" 累計日照計","EName":"TPY"}]}
|
||||||
|
var irrlst = ds_sensor.FindAll(x => x.type.Contains("PYR"));
|
||||||
|
var modelTemplst = ds_sensor.FindAll(x => x.type.Contains("MTR"));
|
||||||
|
var envTemplst = ds_sensor.FindAll(x => x.type.Contains("ETR"));
|
||||||
|
var humlst = ds_sensor.FindAll(x => x.type.Contains("EMM"));
|
||||||
|
var vandlst = ds_sensor.FindAll(x => x.type.Contains("VAN"));
|
||||||
|
var dustlst = ds_sensor.FindAll(x => x.type.Contains("DST")); //落塵計 add @ 2021-12-12
|
||||||
|
var winlst = ds_sensor.FindAll(x => x.type.Contains("WIN")); //風向計 add @ 2021-12-12
|
||||||
|
var irrDaylst = ds_sensor.FindAll(x => x.type.Contains("TPY")); //累計日照計 add @ 2021-12-12
|
||||||
|
//var meterlst = ds_sensor.FindAll(x => x.type.Contains("PWR")); 電錶暫不處理
|
||||||
|
string irrCol = string.Empty; string modelTempCol = string.Empty; string evnTempCol = string.Empty; string humCol = string.Empty; string vanCol = string.Empty; string meterCol = string.Empty; string dustCol = string.Empty; string winCol = string.Empty; string irrDayCol = string.Empty;
|
||||||
|
irrCol = ConcatColumn(irrlst);//日照計
|
||||||
|
modelTempCol = ConcatColumn(modelTemplst);
|
||||||
|
evnTempCol = ConcatColumn(envTemplst);
|
||||||
|
humCol = ConcatColumn(humlst);
|
||||||
|
vanCol = ConcatColumn(vandlst);
|
||||||
|
dustCol = ConcatColumn(dustlst);
|
||||||
|
winCol = ConcatColumn(winlst);
|
||||||
|
irrDayCol = ConcatColumn(irrDaylst);
|
||||||
|
|
||||||
|
string irrNot0 = string.Empty; // and 日照1 <> 0 and 日照2 <> 0
|
||||||
|
# region 日照計需要過濾 0
|
||||||
|
if (irrlst.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var item in irrlst)
|
||||||
|
irrNot0 += " and " + item.colname + " <> 0 "; // and S1 <> 0 and S2 <> 0
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//電表
|
||||||
|
DateTime dt_start = DateTime.Now;
|
||||||
|
#endregion 獲取 Sensor 類別
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#region hour
|
||||||
|
// 暫時解法 儘針對整個 Device 都是共享的情況 ---------------
|
||||||
|
string tableName = "s" + _siteID01 + "_sensorAvg";
|
||||||
|
foreach (var item in ds_sensor)
|
||||||
|
{
|
||||||
|
tableName = item.TableName;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sql = @"insert into sensor_history_hour( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust, WingDirection, irrDay, irrDayHour)
|
||||||
|
select a.powerstationID, a.reportdate, ifnull(b.irrAvg, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust, WingDirection, irrDay, 0 from
|
||||||
|
(
|
||||||
|
select @powerStationID powerstationID, concat(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00') reportdate, round(avg(" + modelTempCol + @"), 4) Temperature,
|
||||||
|
avg(" + evnTempCol + @") envTemperature, avg(" + humCol + @") humidity, avg(" + vanCol + @") Vane, avg(" + dustCol + @") Dust, avg(" + winCol + @") WingDirection, max(" + irrDayCol + @") irrDay
|
||||||
|
from " + _siteDB + "." + tableName + @"
|
||||||
|
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1
|
||||||
|
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H')
|
||||||
|
) a left join
|
||||||
|
(
|
||||||
|
select concat(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00') reportdate, round(avg(" + irrCol + @"), 6) irrAvg
|
||||||
|
from " + _siteDB + "." + tableName + @"
|
||||||
|
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 " + irrNot0 + @" #需要過濾 0 的數值
|
||||||
|
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H')
|
||||||
|
)b on a.reportdate = b.reportdate";
|
||||||
|
//MySqlCommand cmd = new MySqlCommand(sql, conn);
|
||||||
|
//cmd.Parameters()
|
||||||
|
//cmd.ExecuteNonQuery();
|
||||||
|
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||||
|
MySqlCommand cmd = new MySqlCommand();
|
||||||
|
cmd.Connection = conn;
|
||||||
|
cmd.CommandTimeout = 720;
|
||||||
|
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||||
|
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||||
|
cmd.CommandText = sql;
|
||||||
|
int rowCT = cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.Clear();
|
||||||
|
DateTime dt_start2 = DateTime.Now;
|
||||||
|
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}'
|
||||||
|
|
||||||
|
// )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}";
|
||||||
|
if (isFirst)
|
||||||
|
{
|
||||||
|
sql = $@"DROP TEMPORARY TABLE IF EXISTS `temp_s1`;
|
||||||
|
create TEMPORARY TABLE temp_s1
|
||||||
|
select powerstationID, `TIMESTAMP`, irrday
|
||||||
|
from sensor_history_hour a
|
||||||
|
where LEFT(a.TIMESTAMP, 10 ) = '{_date1}';
|
||||||
|
ALTER TABLE `temp_s1` ADD INDEX `temp_indexs1` (powerstationID, `TIMESTAMP`);";
|
||||||
|
dt_start2 = DateTime.Now;
|
||||||
|
cmd.CommandText = sql;
|
||||||
|
int updateCT = cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.Clear();
|
||||||
|
duration = DateTime.Now - dt_start2;
|
||||||
|
arclog.insert_log(_powerStationID, "sensor step0 irrDayHour init", duration.TotalSeconds, "sensor_history_hour", "update sensor hour", "0", "", updateCT.ToString(), conn, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
sql = $@" update sensor_history_hour a join
|
||||||
|
(select LEFT(DATE_ADD(`TIMESTAMP`, INTERVAL +1 hour), 13) hour_1, irrday from temp_s1 ) b
|
||||||
|
on LEFT(a.`TIMESTAMP`, 13) = hour_1 and a.powerstationID = {_powerStationID}
|
||||||
|
Set irrDayhour = case when a.`irrday` - b.`irrday` < 0 then 0 else a.`irrday` - b.`irrday` end
|
||||||
|
where LEFT(a.TIMESTAMP, 10 ) = '{_date1}'
|
||||||
|
and 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;
|
||||||
|
//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
|
||||||
|
sql = @"insert into sensor_history_day( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust, WingDirection, irrDay, irrDayHour)
|
||||||
|
select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust, a.WingDirection, a.irrDay, a.irrDayHour from
|
||||||
|
(
|
||||||
|
select powerStationID , concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00') reportdate, round(avg(Temperature), 6) Temperature,
|
||||||
|
envTemperature, humidity, Vane, Dust, avg(WingDirection) WingDirection, max(irrDay) irrDay, max(irrDay) irrDayHour
|
||||||
|
from solar_master.sensor_history_hour
|
||||||
|
where powerstationID = @powerstationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1
|
||||||
|
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d')
|
||||||
|
) a left join
|
||||||
|
(
|
||||||
|
select concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00') reportdate, round(avg(Irradiance), 6) Irradiance
|
||||||
|
from solar_master.sensor_history_hour
|
||||||
|
where powerstationID = @powerstationID
|
||||||
|
and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1 and Irradiance <> 0 #需要過濾 0 的數值
|
||||||
|
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d')
|
||||||
|
)b on a.reportdate = b.reportdate";
|
||||||
|
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||||
|
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||||
|
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||||
|
cmd.CommandText = sql;
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.Clear();
|
||||||
|
#endregion day
|
||||||
|
|
||||||
|
#region month 如果跨月 會有2筆資料
|
||||||
|
|
||||||
|
sql = @"
|
||||||
|
delete from sensor_history_month where left(`TIMESTAMP`, 7) = @date1 and PowerStationID = @powerStationID;
|
||||||
|
|
||||||
|
insert into sensor_history_month( `PowerStationId`, `TIMESTAMP`, `Irradiance`, Temperature, EnvTemperature, Humidity, Vane, Dust, WingDirection, irrDay, irrDayHour)
|
||||||
|
select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust, WingDirection, irrDay, irrDayHour from
|
||||||
|
(
|
||||||
|
select powerStationID , concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m'), '-01 00:00') reportdate, round(avg(Temperature), 6) Temperature,
|
||||||
|
avg(envTemperature) envTemperature, avg(humidity) humidity, avg(Vane) Vane, avg(Dust) Dust, avg(WingDirection) WingDirection, max(irrDay) irrDay, sum(irrDay) irrDayHour
|
||||||
|
from solar_master.sensor_history_day
|
||||||
|
where powerstationID = @powerstationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = @date1
|
||||||
|
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m')
|
||||||
|
) a left join
|
||||||
|
(
|
||||||
|
select concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m'), '-01 00:00') reportdate, round(avg(Irradiance), 6) Irradiance
|
||||||
|
from solar_master.sensor_history_day
|
||||||
|
where powerstationID = @powerstationID
|
||||||
|
and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = @date1 and Irradiance <> 0 #需要過濾 0 的數值
|
||||||
|
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m')
|
||||||
|
)b on a.reportdate = b.reportdate";
|
||||||
|
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1.Substring(0,7) });
|
||||||
|
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||||
|
cmd.Parameters.AddWithValue("@date1", _date1.Substring(0, 7));
|
||||||
|
cmd.CommandText = sql;
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.Clear();
|
||||||
|
#endregion month
|
||||||
|
|
||||||
|
#region Sensor 1~50 hour
|
||||||
|
sql = @"
|
||||||
|
INSERT INTO solar_master.sensoravg_history_hour(PowerStationId, `TIMESTAMP`, SENSORAVG01, SENSORAVG02, SENSORAVG03, SENSORAVG04, SENSORAVG05, SENSORAVG06, SENSORAVG07, SENSORAVG08, SENSORAVG09, SENSORAVG10, SENSORAVG11, SENSORAVG12, SENSORAVG13, SENSORAVG14, SENSORAVG15, SENSORAVG16, SENSORAVG17, SENSORAVG18, SENSORAVG19, SENSORAVG20, SENSORAVG21, SENSORAVG22, SENSORAVG23, SENSORAVG24, SENSORAVG25, SENSORAVG26, SENSORAVG27, SENSORAVG28, SENSORAVG29, SENSORAVG30, SENSORAVG31, SENSORAVG32, SENSORAVG33, SENSORAVG34, SENSORAVG35, SENSORAVG36, SENSORAVG37, SENSORAVG38, SENSORAVG39, SENSORAVG40, SENSORAVG41, SENSORAVG42, SENSORAVG43, SENSORAVG44, SENSORAVG45, SENSORAVG46, SENSORAVG47, SENSORAVG48, SENSORAVG49, SENSORAVG50)
|
||||||
|
select @powerStationID powerstationID, FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, avg(sensorAvg01), avg(sensorAvg02),
|
||||||
|
avg(sensorAvg03), avg(sensorAvg04), avg(sensorAvg05), avg(sensorAvg06), avg(sensorAvg07), avg(sensorAvg08), avg(sensorAvg09),
|
||||||
|
avg(sensorAvg10), avg(sensorAvg11), avg(sensorAvg12), avg(sensorAvg13), avg(sensorAvg14), avg(sensorAvg15), avg(sensorAvg16),
|
||||||
|
avg(sensorAvg17), avg(sensorAvg18), avg(sensorAvg19), avg(sensorAvg20), avg(sensorAvg21), avg(sensorAvg22), avg(sensorAvg23),
|
||||||
|
avg(sensorAvg24), avg(sensorAvg25), avg(sensorAvg26), avg(sensorAvg27), avg(sensorAvg28), avg(sensorAvg29), avg(sensorAvg30),
|
||||||
|
avg(sensorAvg31), avg(sensorAvg32), avg(sensorAvg33), avg(sensorAvg34), avg(sensorAvg35), avg(sensorAvg36), avg(sensorAvg37),
|
||||||
|
avg(sensorAvg38), avg(sensorAvg39), avg(sensorAvg40), avg(sensorAvg41), avg(sensorAvg42), avg(sensorAvg43), avg(sensorAvg44),
|
||||||
|
avg(sensorAvg45), avg(sensorAvg46), avg(sensorAvg47), avg(sensorAvg48), avg(sensorAvg49), avg(sensorAvg50)
|
||||||
|
from " + _siteDB + ".s" + _siteID01 + @"_sensorAvg
|
||||||
|
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1
|
||||||
|
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H');";
|
||||||
|
// conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||||
|
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||||
|
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||||
|
cmd.CommandText = sql;
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.Clear();
|
||||||
|
|
||||||
|
//日照計 update
|
||||||
|
sql = string.Empty;
|
||||||
|
foreach (var item in irrlst)
|
||||||
|
{
|
||||||
|
sql += @" update sensoravg_history_hour a join
|
||||||
|
(
|
||||||
|
select @powerstationID powerstationID, concat(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00') reportdate, round(avg(" + item.colname + @"), 6) irrAvg
|
||||||
|
from " + _siteDB + ".s" + _siteID01 + @"_sensorAvg
|
||||||
|
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and " + item.colname + @" <> 0 #需要過濾 0 的數值
|
||||||
|
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H')
|
||||||
|
)b on a.powerStationID = b.powerStationID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d %H:%i') = b.reportdate
|
||||||
|
set a." + item.colname + " = b.irrAvg;";
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(sql))
|
||||||
|
{
|
||||||
|
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||||
|
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||||
|
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||||
|
cmd.CommandText = sql;
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Sensor 1~50 day
|
||||||
|
sql = @"
|
||||||
|
INSERT INTO solar_master.sensoravg_history_day(PowerStationId, `TIMESTAMP`, SENSORAVG01, SENSORAVG02, SENSORAVG03, SENSORAVG04, SENSORAVG05, SENSORAVG06, SENSORAVG07, SENSORAVG08, SENSORAVG09, SENSORAVG10, SENSORAVG11, SENSORAVG12, SENSORAVG13, SENSORAVG14, SENSORAVG15, SENSORAVG16, SENSORAVG17, SENSORAVG18, SENSORAVG19, SENSORAVG20, SENSORAVG21, SENSORAVG22, SENSORAVG23, SENSORAVG24, SENSORAVG25, SENSORAVG26, SENSORAVG27, SENSORAVG28, SENSORAVG29, SENSORAVG30, SENSORAVG31, SENSORAVG32, SENSORAVG33, SENSORAVG34, SENSORAVG35, SENSORAVG36, SENSORAVG37, SENSORAVG38, SENSORAVG39, SENSORAVG40, SENSORAVG41, SENSORAVG42, SENSORAVG43, SENSORAVG44, SENSORAVG45, SENSORAVG46, SENSORAVG47, SENSORAVG48, SENSORAVG49, SENSORAVG50)
|
||||||
|
select @powerStationID powerstationID, DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') reportdate, avg(sensorAvg01), avg(sensorAvg02),
|
||||||
|
avg(sensorAvg03), avg(sensorAvg04), avg(sensorAvg05), avg(sensorAvg06), avg(sensorAvg07), avg(sensorAvg08), avg(sensorAvg09),
|
||||||
|
avg(sensorAvg10), avg(sensorAvg11), avg(sensorAvg12), avg(sensorAvg13), avg(sensorAvg14), avg(sensorAvg15), avg(sensorAvg16),
|
||||||
|
avg(sensorAvg17), avg(sensorAvg18), avg(sensorAvg19), avg(sensorAvg20), avg(sensorAvg21), avg(sensorAvg22), avg(sensorAvg23),
|
||||||
|
avg(sensorAvg24), avg(sensorAvg25), avg(sensorAvg26), avg(sensorAvg27), avg(sensorAvg28), avg(sensorAvg29), avg(sensorAvg30),
|
||||||
|
avg(sensorAvg31), avg(sensorAvg32), avg(sensorAvg33), avg(sensorAvg34), avg(sensorAvg35), avg(sensorAvg36), avg(sensorAvg37),
|
||||||
|
avg(sensorAvg38), avg(sensorAvg39), avg(sensorAvg40), avg(sensorAvg41), avg(sensorAvg42), avg(sensorAvg43), avg(sensorAvg44),
|
||||||
|
avg(sensorAvg45), avg(sensorAvg46), avg(sensorAvg47), avg(sensorAvg48), avg(sensorAvg49), avg(sensorAvg50)
|
||||||
|
from solar_master.sensoravg_history_hour
|
||||||
|
where powerStationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1
|
||||||
|
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d');";
|
||||||
|
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||||
|
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||||
|
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||||
|
cmd.CommandText = sql;
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.Clear();
|
||||||
|
|
||||||
|
//日照計 update
|
||||||
|
sql = string.Empty;
|
||||||
|
foreach (var item in irrlst)
|
||||||
|
{
|
||||||
|
sql += @" update solar_master.sensoravg_history_day a join
|
||||||
|
(
|
||||||
|
select @powerstationID powerstationID, concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00') reportdate, round(avg(" + item.colname + @"), 6) irrAvg
|
||||||
|
from solar_master.sensoravg_history_hour
|
||||||
|
where powerStationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1 and " + item.colname + @" <> 0 #需要過濾 0 的數值
|
||||||
|
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d')
|
||||||
|
)b on a.powerStationID = b.powerStationID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = b.reportdate
|
||||||
|
set a." + item.colname + " = b.irrAvg;";
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(sql))
|
||||||
|
{
|
||||||
|
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||||
|
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||||
|
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||||
|
cmd.CommandText = sql;
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
conn.Close();
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,15 +112,15 @@ namespace solarApp
|
|||||||
}
|
}
|
||||||
|
|
||||||
//臨時的 累計日照
|
//臨時的 累計日照
|
||||||
if (DateTime.Now.Minute == 30 && (DateTime.Now.Second >= 0 && DateTime.Now.Second <= 10) && autoTask == false)
|
//if (DateTime.Now.Minute == 30 && (DateTime.Now.Second >= 0 && DateTime.Now.Second <= 10) && autoTask == false)
|
||||||
{
|
//{
|
||||||
//MessageBox.Show("ok");
|
// //MessageBox.Show("ok");
|
||||||
autoTask = true;
|
// autoTask = true;
|
||||||
lbMsgTitle.Text = DateTime.Now.ToString() + " 臨時的 累計日照 start";
|
// lbMsgTitle.Text = DateTime.Now.ToString() + " 臨時的 累計日照 start";
|
||||||
|
|
||||||
button2.PerformClick();
|
// button2.PerformClick();
|
||||||
//bt_archive_Click.PerformClick();
|
// //bt_archive_Click.PerformClick();
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//水位管理
|
//水位管理
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user