From 9e8771d7810388e68962c227ce6c41848b887361 Mon Sep 17 00:00:00 2001 From: JiaHao Liu Date: Mon, 13 Dec 2021 10:17:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F=E6=97=A5=E6=AD=B8=E6=AA=94=20-=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9ESensor=EF=BC=9A1.=E7=B4=AF=E8=A8=88=E6=97=A5?= =?UTF-8?q?=E7=85=A7=E9=87=8F=202.=E9=A2=A8=E5=90=91=E8=A8=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Service/procSensorSvc.cs | 32 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/solarApp/Service/procSensorSvc.cs b/solarApp/Service/procSensorSvc.cs index e4c307d..3a3e660 100644 --- a/solarApp/Service/procSensorSvc.cs +++ b/solarApp/Service/procSensorSvc.cs @@ -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')