每日歸檔 - 新增Sensor:1.累計日照量 2.風向計

This commit is contained in:
JiaHao Liu 2021-12-13 10:17:59 +08:00
parent 4e3e4e1217
commit 9e8771d781

View File

@ -180,20 +180,26 @@ namespace solarApp.Service
// { "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 windlst = ds_sensor.FindAll(x => x.type.Contains("VAN"));
var dustlst = ds_sensor.FindAll(x => x.type.Contains("DST")); //需要新增於DB
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 windCol = string.Empty; string meterCol = string.Empty; string dustCol = string.Empty;
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);
windCol = ConcatColumn(windlst);
vanCol = ConcatColumn(vandlst);
dustCol = ConcatColumn(dustlst);
winCol = ConcatColumn(winlst);
irrDayCol = ConcatColumn(irrDaylst);
string irrNot0 = string.Empty; // and 日照1 <> 0 and 日照2 <> 0
# region 0
@ -210,11 +216,11 @@ namespace solarApp.Service
try
{
#region hour
sql = @"insert into sensor_history_hour( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust)
select a.powerstationID, a.reportdate, ifnull(b.irrAvg, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust from
sql = @"insert into sensor_history_hour( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust, WingDirection, irrDay)
select a.powerstationID, a.reportdate, ifnull(b.irrAvg, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust, WingDirection, irrDay from
(
select @powerStationID powerstationID, FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, round(avg(" + modelTempCol + @"), 4) Temperature,
avg(" + evnTempCol + @") envTemperature, avg(" + humCol + @") humidity, avg(" + windCol + @") Vane, avg(" + dustCol + @") Dust
avg(" + evnTempCol + @") envTemperature, avg(" + humCol + @") humidity, avg(" + vanCol + @") Vane, avg(" + dustCol + @") Dust, avg(" + winCol + @") WingDirection, max(" + irrDayCol + @") irrDay
from " + _siteDB + ".s" + _siteID01 + @"_sensorAvg
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H')
@ -232,11 +238,11 @@ namespace solarApp.Service
#endregion hour
#region day
sql = @"insert into sensor_history_day( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust)
select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust from
sql = @"insert into sensor_history_day( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust, WingDirection, irrDay)
select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust, a.WingDirection, a.irrDay from
(
select powerStationID , concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00') reportdate, round(avg(Temperature), 6) Temperature,
envTemperature, humidity, Vane, Dust
envTemperature, humidity, Vane, Dust, WingDirection, irrDay
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')
@ -256,11 +262,11 @@ namespace solarApp.Service
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)
select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust from
insert into sensor_history_month( `PowerStationId`, `TIMESTAMP`, `Irradiance`, Temperature, EnvTemperature, Humidity, Vane, Dust, WingDirection, irrDay)
select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust, WingDirection, irrDay from
(
select powerStationID , concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m'), '-01 00:00') reportdate, round(avg(Temperature), 6) Temperature,
envTemperature, humidity, Vane, Dust
envTemperature, humidity, Vane, Dust, WingDirection, irrDay
from solar_master.sensor_history_day
where powerstationID = @powerstationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = @date1
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m')