修正歸檔中的 PR 計算與累計日照計

This commit is contained in:
cesar liu 2022-05-21 14:24:17 +08:00
parent aa8edd8e8a
commit eb96541dd4
9 changed files with 124 additions and 48 deletions

1
.gitignore vendored
View File

@ -348,3 +348,4 @@ healthchecksdb
/SolarPower.zip /SolarPower.zip
/SolarPower/wwwroot/upload/report/20220227 /SolarPower/wwwroot/upload/report/20220227
*.diagsession *.diagsession
/SolarPower/wwwroot/upload/report/20220520

View File

@ -36,12 +36,18 @@ namespace SolarPower.Helper
var databaseStr = ed.AESDecrypt(dbConfig.Database); var databaseStr = ed.AESDecrypt(dbConfig.Database);
var rootStr = ed.AESDecrypt(dbConfig.Root); var rootStr = ed.AESDecrypt(dbConfig.Root);
var passwordStr = ed.AESDecrypt(dbConfig.Password); var passwordStr = ed.AESDecrypt(dbConfig.Password);
//var serverStr = ed.AESEncrypt("localhost");
//var portStr = ed.AESEncrypt("3306");
//var databaseStr = ed.AESEncrypt("solar_master");
//var rootStr = ed.AESEncrypt("webUser");
//var passwordStr = ed.AESEncrypt("ficAdmin99");
var connStr = $"server={serverStr};port={portStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;Allow User Variables=True;"; var connStr = $"server={serverStr};port={portStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;Allow User Variables=True;";
this._connectionString = connStr; this._connectionString = connStr;
} }
public IDbConnection GetConnection() public IDbConnection GetConnection()
{ {
var conn = new MySqlConnection(this._connectionString); var conn = new MySqlConnection(this._connectionString);

View File

@ -121,8 +121,8 @@ namespace SolarPower
#region PRkWP 30(2) #region PRkWP 30(2)
services.AddSingleton<CalcAvgPowerStationJob>(); services.AddSingleton<CalcAvgPowerStationJob>();
services.AddSingleton( services.AddSingleton(
new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcAvgPowerStationJob")) //new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcAvgPowerStationJob"))
//new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0/10 * * * * ?") new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0 03 7 ? * * *")
); );
#endregion #endregion

View File

@ -43,13 +43,17 @@ namespace solarApp.Model
{ {
public string SiteID { get; set; } public string SiteID { get; set; }
public string reportdate { get; set; } public string reportdate { get; set; }
public double irrAvg { get; set; }
public double modelTempAvg { get; set; } public double modelTempAvg { get; set; }
/// <summary>
/// 累計日照量
/// </summary>
public double irrSumAvg { get; set; }
public double envTempAvg { get; set; } public double envTempAvg { get; set; }
public double humidityAvg { get; set; } public double humidityAvg { get; set; }
public double windAvg { get; set; } public double windAvg { get; set; }
public double dustAvg { get; set; } public double dustAvg { get; set; }
public double irrAvg { get; set; }
public int count { get; set; } public int count { get; set; }
} }
@ -57,12 +61,16 @@ namespace solarApp.Model
{ {
public string SiteID { get; set; } public string SiteID { get; set; }
public string reportdate { get; set; } public string reportdate { get; set; }
public double irrAvg { get; set; }
public double modelTempAvg { get; set; } public double modelTempAvg { get; set; }
/// <summary>
/// 累計日照量
/// </summary>
public double irrSumAvg { get; set; }
public double envTempAvg { get; set; } public double envTempAvg { get; set; }
public double humidityAvg { get; set; } public double humidityAvg { get; set; }
public double windAvg { get; set; } public double windAvg { get; set; }
public double dustAvg { get; set; } public double dustAvg { get; set; }
public double irrAvg { get; set; }
public int count { get; set; } public int count { get; set; }
} }
} }

View File

@ -137,9 +137,9 @@ namespace solarApp.Service
//電表 //電表
#endregion Sensor #endregion Sensor
sql = @"select a.siteID, a.reportdate, a.modelTempAvg, ifnull(b.irrAvg, 0) irrAvg, a.envTempAvg, humidityAvg, windAvg, dustAvg, count from sql = @"select a.siteID, a.reportdate, a.modelTempAvg, irrSumAvg, a.envTempAvg, humidityAvg, windAvg, dustAvg, ifnull(b.irrAvg, 0) irrAvg, count from
( (
select @siteID siteID, CONCAT( FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00') reportdate, " + modelTempCol+ @" modelTempAvg select @siteID siteID, CONCAT( FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00') reportdate, " + modelTempCol+ @" modelTempAvg , " + totIrrCol + @" irrSumAvg
," + evnTempCol + @" envTempAvg, " + humCol + @" humidityAvg, " + windCol + @" windAvg, " + dustCol + @" dustAvg, count(*) count ," + evnTempCol + @" envTempAvg, " + humCol + @" humidityAvg, " + windCol + @" windAvg, " + dustCol + @" dustAvg, count(*) count
from " + siteDB + ".s" + siteID + @"_sensorAvg from " + siteDB + ".s" + siteID + @"_sensorAvg
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @reportDate where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @reportDate
@ -167,7 +167,7 @@ namespace solarApp.Service
using (MySqlConnection conn = new MySqlConnection(Connection1)) using (MySqlConnection conn = new MySqlConnection(Connection1))
{ {
conn.Open(); conn.Open();
string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Temperature, 2) modelTempAvg, round(irrDay, 2) irrSumAvg, round(Irradiance, 2) irrAvg
from sensor_history_hour a join power_station b on a.PowerStationId = b.id from sensor_history_hour a join power_station b on a.PowerStationId = b.id
where left(`TIMESTAMP`, 10) = '" + reportDate + "' and b.`code` = @siteID"; where left(`TIMESTAMP`, 10) = '" + reportDate + "' and b.`code` = @siteID";
List<sensor_hour> ds = conn.Query<sensor_hour>(sql, new {siteID = siteID }).AsList<sensor_hour>(); List<sensor_hour> ds = conn.Query<sensor_hour>(sql, new {siteID = siteID }).AsList<sensor_hour>();
@ -184,7 +184,7 @@ namespace solarApp.Service
//string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg //string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg
// from sensor_history_day a join power_station b on a.PowerStationId = b.id // from sensor_history_day a join power_station b on a.PowerStationId = b.id
// where left(`TIMESTAMP`, 10) between '" + date1 + "' and '"+date2+"' and b.`code` = @siteID"; // where left(`TIMESTAMP`, 10) between '" + date1 + "' and '"+date2+"' and b.`code` = @siteID";
string sql = @"select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg, c.count string sql = @"select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Temperature, 2) modelTempAvg, round(irrDay, 2) irrSumAvg, round(Irradiance, 2) irrAvg, c.count
from sensor_history_day a join power_station b on a.PowerStationId = b.id from sensor_history_day a join power_station b on a.PowerStationId = b.id
left join ( left join (
select PowerStationId, left(a.`TIMESTAMP`, 10) reportDate, count(*) count from sensor_history_hour a join power_station b on a.PowerStationId = b.id select PowerStationId, left(a.`TIMESTAMP`, 10) reportDate, count(*) count from sensor_history_hour a join power_station b on a.PowerStationId = b.id
@ -203,7 +203,7 @@ namespace solarApp.Service
using (MySqlConnection conn = new MySqlConnection(Connection1)) using (MySqlConnection conn = new MySqlConnection(Connection1))
{ {
conn.Open(); conn.Open();
string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(Irradiance, 2) irrAvg, round(Temperature, 2) modelTempAvg string sql = @" select DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H') reportdate, b.`code` siteid, round(irrDay, 2) irrSumAvg , round(Temperature, 2) modelTempAvg, round(Irradiance, 2) irrAvg
from sensor_history_month a join power_station b on a.PowerStationId = b.id from sensor_history_month a join power_station b on a.PowerStationId = b.id
where left(`TIMESTAMP`, 7) between '" + date1 + "' and '" + date2 + "' and b.`code` = @siteID"; where left(`TIMESTAMP`, 7) between '" + date1 + "' and '" + date2 + "' and b.`code` = @siteID";
List<sensor_hour> ds = conn.Query<sensor_hour>(sql, new { siteID = siteID}).AsList<sensor_hour>(); List<sensor_hour> ds = conn.Query<sensor_hour>(sql, new { siteID = siteID}).AsList<sensor_hour>();

View File

@ -179,7 +179,7 @@ namespace solarApp.Service
conn.Open(); // 01 控制器編號 conn.Open(); // 01 控制器編號
string sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName string sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName
from power_station from power_station
where deleted = 0 "; where deleted = 0 and `status`= 1 ";
List<station_list> ds = conn.Query<station_list>(sql).AsList<station_list>(); List<station_list> ds = conn.Query<station_list>(sql).AsList<station_list>();
conn.Close(); conn.Close();
return ds; return ds;

View File

@ -57,19 +57,19 @@ namespace solarApp.Service
public bool archiveData(string siteID, string date1) { public bool archiveData(string siteID, string date1) {
bool result = false; bool result = false;
try //try
{ //{
_siteID = siteID; _siteID = siteID;
_date1 = date1; _date1 = date1;
get_siteInfo(); get_siteInfo();
clearData(); clearData();
insert_sensor(); insert_sensor();
result = true; result = true;
} //}
catch (Exception ex) //catch (Exception ex)
{ //{
throw ex; // throw ex;
} //}
return result; return result;
} }

View File

@ -215,19 +215,19 @@ namespace solarApp.Service
cmd.Parameters.Clear(); cmd.Parameters.Clear();
#endregion hour #endregion hour
#region day //#region 取累計日照量
//sql = $@"select a.TableName, a.ColName from solar_com0002.device a where `type` = 'TPY' and a.Deleted = 0 and a.`status` = 1 ";
//#endregion
#region day PR = (/)*1000/
sql = @" INSERT INTO solar_master.power_station_history_day( PowerStationId, `TIMESTAMP`, SITEID, SITETYPE, TODAYKWH, TOTALKWH, KWHKWP, sql = @" INSERT INTO solar_master.power_station_history_day( PowerStationId, `TIMESTAMP`, SITEID, SITETYPE, TODAYKWH, TOTALKWH, KWHKWP,
PR, MP, SOLARHOUR, MONEY, TOTALMONEY, CARBON, TOTALCARBON) PR, MP, SOLARHOUR, MONEY, TOTALMONEY, CARBON, TOTALCARBON)
select b.id PowerStationId, a.reportdate, b.siteID, a.siteType, a.TODAYKWH, a.TOTALKWH, a.KWHKWP, a1.PR, a.MP, a.SOLARHOUR, select b.id PowerStationId, a.reportdate, b.siteID, a.siteType, a.TODAYKWH, a.TOTALKWH, a.KWHKWP,
/*CASE a1.PR, -- (todayKWH/Capacity)*1000/b.IrrDay as PR, -- PR
WHEN b.SolarType = 1 THEN a.KWH * PowerRate * c.LeaseRate a.MP, a.SOLARHOUR,
ELSE a.KWH * PowerRate
END MONEY,
CASE
WHEN b.SolarType = 1 THEN a.TOTALKWH * PowerRate * c.LeaseRate
ELSE a.TOTALKWH * PowerRate
END TOTALMONEY,*/
(a.TODAYKWH * PowerRate) MONEY, (a.TODAYKWH * PowerRate) MONEY,
(a.TOTALKWH * PowerRate) TOTALMONEY, (a.TOTALKWH * PowerRate) TOTALMONEY,
(KWH * CarbonRate) CARBON, round((a.TOTALKWH * CarbonRate), 4) TOTALCARBON (KWH * CarbonRate) CARBON, round((a.TOTALKWH * CarbonRate), 4) TOTALCARBON
@ -235,7 +235,7 @@ namespace solarApp.Service
( (
select concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00:00') reportdate, siteid, siteType, round((sum(KWH)), 6) KWH, select concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00:00') reportdate, siteid, siteType, round((sum(KWH)), 6) KWH,
round((max(TODAYKWH)), 6) TODAYKWH, round((max(TOTALKWH)), 6) TOTALKWH, round((max(KWHKWP)), 6) KWHKWP, round((max(TODAYKWH)), 6) TODAYKWH, round((max(TOTALKWH)), 6) TOTALKWH, round((max(KWHKWP)), 6) KWHKWP,
#round((max(PR)), 6) PR, # round((avg(PR)), 6) PR,
round((max(MP)), 6) as MP, round((max(SOLARHOUR)), 6) SOLARHOUR round((max(MP)), 6) as MP, round((max(SOLARHOUR)), 6) SOLARHOUR
from solar_master.power_station_history_hour a from solar_master.power_station_history_hour a
where SITEID = @siteID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = @date1 where SITEID = @siteID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = @date1
@ -248,18 +248,54 @@ namespace solarApp.Service
order by 1 desc limit 1 order by 1 desc limit 1
)a1 on a.siteID = a1.siteID join )a1 on a.siteID = a1.siteID join
( (
select id, `code` siteID, PowerRate, (select `value` from solar_master.`variable` where `name` = 'CarbonRate') as CarbonRate, SolarType select a.id, `code` siteID, PowerRate, GeneratingCapacity Capacity, (select `value` from solar_master.`variable` where `name` = 'CarbonRate') as CarbonRate, SolarType, IrrDay
from solar_master.power_station from solar_master.power_station a join sensor_history_day b on a.id = b.PowerStationID
where `code` = @siteID where `code` = @siteID and left(`TIMESTAMP`, 10) = @date1
) b on a.siteID = b.siteID ) b on a.siteID = b.siteID ";
LEFT JOIN ( // sql = @" INSERT INTO solar_master.power_station_history_day( PowerStationId, `TIMESTAMP`, SITEID, SITETYPE, TODAYKWH, TOTALKWH, KWHKWP,
SELECT // PR, MP, SOLARHOUR, MONEY, TOTALMONEY, CARBON, TOTALCARBON)
SUM(lb.LeaseRate) LeaseRate,
ps.Code siteID FROM " + _siteDB + @".land_building lb // select b.id PowerStationId, a.reportdate, b.siteID, a.siteType, a.TODAYKWH, a.TOTALKWH, a.KWHKWP, a1.PR, a.MP, a.SOLARHOUR,
LEFT JOIN solar_master.power_station ps ON lb.PowerStationId = ps.Id // /*CASE
WHERE ps.Code = @siteID // WHEN b.SolarType = 1 THEN a.KWH * PowerRate * c.LeaseRate
GROUP BY lb.PowerStationId // ELSE a.KWH * PowerRate
) c ON a.siteID = c.siteID"; //END MONEY,
// CASE
// WHEN b.SolarType = 1 THEN a.TOTALKWH * PowerRate * c.LeaseRate
// ELSE a.TOTALKWH * PowerRate
//END TOTALMONEY,*/
// (a.TODAYKWH * PowerRate) MONEY,
// (a.TOTALKWH * PowerRate) TOTALMONEY,
// (KWH * CarbonRate) CARBON, round((a.TOTALKWH * CarbonRate), 4) TOTALCARBON
// from
// (
// select concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00:00') reportdate, siteid, siteType, round((sum(KWH)), 6) KWH,
// round((max(TODAYKWH)), 6) TODAYKWH, round((max(TOTALKWH)), 6) TOTALKWH, round((max(KWHKWP)), 6) KWHKWP,
// #round((max(PR)), 6) PR,
// round((max(MP)), 6) as MP, round((max(SOLARHOUR)), 6) SOLARHOUR
// from solar_master.power_station_history_hour a
// where SITEID = @siteID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = @date1
// group by a.siteid, DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d')
// )a join
// (
// select id, SITEID, round(PR, 4) PR
// from solar_master.power_station_history_hour a
// where SITEID = @siteID and DATE_FORMAT(a.`TIMESTAMP`,'%Y-%m-%d') = @date1
// order by 1 desc limit 1
// )a1 on a.siteID = a1.siteID join
// (
// select id, `code` siteID, PowerRate, (select `value` from solar_master.`variable` where `name` = 'CarbonRate') as CarbonRate, SolarType
// from solar_master.power_station
// where `code` = @siteID
// ) b on a.siteID = b.siteID
// LEFT JOIN (
// SELECT
// SUM(lb.LeaseRate) LeaseRate,
// ps.Code siteID FROM " + _siteDB + @".land_building lb
// LEFT JOIN solar_master.power_station ps ON lb.PowerStationId = ps.Id
// WHERE ps.Code = @siteID
// GROUP BY lb.PowerStationId
// ) c ON a.siteID = c.siteID";
// conn.Execute(sql, new { date1 = _date1, siteID = _siteID }); // conn.Execute(sql, new { date1 = _date1, siteID = _siteID });
cmd.Parameters.AddWithValue("@date1", _date1); cmd.Parameters.AddWithValue("@date1", _date1);
cmd.Parameters.AddWithValue("@siteID", _siteID); cmd.Parameters.AddWithValue("@siteID", _siteID);

View File

@ -186,9 +186,34 @@ namespace solarApp
private void bt_archive_Click(object sender, EventArgs e) private void bt_archive_Click(object sender, EventArgs e)
{ {
bt_Sensor.PerformClick(); int i = 0;
bt_Inv.PerformClick(); var site_list = stationSvc.get_station_list();
bt_site.PerformClick();
//bt_Sensor.PerformClick();
//bt_Inv.PerformClick();
//bt_site.PerformClick();
//bt_rpt_invDay.PerformClick();
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
procSensorSvc sensorSvc = new procSensorSvc();
procInvSvc invSvc = new procInvSvc();
procStationSvc siteSvc = new procStationSvc();
foreach (var item in site_list)
{
//RadioButton rb = new RadioButton();
//rb.Name = item.SiteID;
//rb.Text = item.SiteName;
//rb.Tag = item.SiteDB;
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
{
sensorSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
invSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
siteSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
}
i++;
}
} }
private void bt_clear_sensor_Click(object sender, EventArgs e) private void bt_clear_sensor_Click(object sender, EventArgs e)