From 41fac9bc2477290cabb40187e675a1415d0bd31f Mon Sep 17 00:00:00 2001 From: "wanling040@gmail.com" Date: Thu, 4 Aug 2022 01:03:05 +0800 Subject: [PATCH] =?UTF-8?q?solar=5FApp:=20=E5=8A=A0=E5=85=A5irrDayHour?= =?UTF-8?q?=E8=A8=88=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarApp/Service/procInvSvc.cs | 6 +++--- solarApp/Service/procSensorSvc.cs | 32 +++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/solarApp/Service/procInvSvc.cs b/solarApp/Service/procInvSvc.cs index 6648938..7582b1c 100644 --- a/solarApp/Service/procInvSvc.cs +++ b/solarApp/Service/procInvSvc.cs @@ -623,12 +623,12 @@ ALTER TABLE `temp_invDay{_powerStationID}_s1` ADD INDEX `temp_indexs1` (report_d #region 先新增 inv_no01 string inv01 = _siteID01 + "0001"; sql = @$" -insert report_invday(`report_date`, `PowerStationID`, inv_01, `hourKWH`, `hourKWHp`, `irradiance`, `temperature`, `hourmoney`, `pr`, createTime) +insert report_invday(`report_date`, `PowerStationID`, inv_01, `hourKWH`, `hourKWHp`, `irradiance`, `temperature`, `hourmoney`, `pr`, createTime, IrrDay, IrrDayHour ) select a.report_date, a.powerstationId , ifnull(round(a.kwh, 6), 0) inv_01, ifnull(b.KWH, 0) hourKWH, ifnull(round((b.KWH / (SELECT MAX(TODAYKWH) FROM power_station_history_hour WHERE DATE_FORMAT(TIMESTAMP,'%Y-%m-%d') = '{_date1}' and powerstationid = {_powerStationID} ))*100,2) , 0) 'hourKWHp', ifnull(d.irradiance, 0) 'irradiance', ifnull(d.Temperature, 0) 'temperature', - ifnull(b.money, 0) 'hourmoney', ifnull(round(b.PR, 2), 0) as pr, now() createTime + ifnull(b.money, 0) 'hourmoney', ifnull(round(b.PR, 2), 0) as pr, now() createTime, ifnull(d.IrrDay, 0)IrrDay, ifnull(d.IrrDayHour, 0)IrrDayHour from temp_invDay{_powerStationID}_s1 a join ( # 每小時加總 inv select powerStationid, `TIMESTAMP` report_date, siteid, sitetype, round(KWH, 2) KWH, @@ -639,7 +639,7 @@ from temp_invDay{_powerStationID}_s1 a join left join ( - select powerStationID, `TIMESTAMP` report_date, irradiance, Temperature + select powerStationID, `TIMESTAMP` report_date, irradiance, Temperature, IrrDay, IrrDayHour from sensor_history_hour where powerstationid = {_powerStationID} and left(`TIMESTAMP`,10) = '{_date1}' ) d on a.powerStationid = d.powerStationid and a.`report_date` = d.report_date diff --git a/solarApp/Service/procSensorSvc.cs b/solarApp/Service/procSensorSvc.cs index 15f4fc0..58ec3eb 100644 --- a/solarApp/Service/procSensorSvc.cs +++ b/solarApp/Service/procSensorSvc.cs @@ -236,8 +236,8 @@ namespace solarApp.Service break; } - 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 + 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, FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') reportdate, round(avg(" + modelTempCol + @"), 4) Temperature, avg(" + evnTempCol + @") envTemperature, avg(" + humCol + @") humidity, avg(" + vanCol + @") Vane, avg(" + dustCol + @") Dust, avg(" + winCol + @") WingDirection, max(" + irrDayCol + @") irrDay @@ -267,14 +267,30 @@ 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}' + + )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); #endregion hour #region day - 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 + 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 + envTemperature, humidity, Vane, Dust, avg(WingDirection) WingDirection, max(irrDay) irrDay, sum(irrDayHour) 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') @@ -299,11 +315,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, 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 + 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 + avg(envTemperature) envTemperature, avg(humidity) humidity, avg(Vane) Vane, avg(Dust) Dust, avg(WingDirection) WingDirection, max(irrDay) irrDay, sum(irrDayHour) irrDayHour from solar_master.sensor_history_day where powerstationID = @powerstationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = @date1 group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m')