修正歸檔中的 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/wwwroot/upload/report/20220227
*.diagsession
/SolarPower/wwwroot/upload/report/20220520

View File

@ -36,12 +36,18 @@ namespace SolarPower.Helper
var databaseStr = ed.AESDecrypt(dbConfig.Database);
var rootStr = ed.AESDecrypt(dbConfig.Root);
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;";
this._connectionString = connStr;
}
public IDbConnection GetConnection()
{
var conn = new MySqlConnection(this._connectionString);

View File

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

View File

@ -43,26 +43,34 @@ namespace solarApp.Model
{
public string SiteID { get; set; }
public string reportdate { get; set; }
public double irrAvg { get; set; }
public double modelTempAvg { get; set; }
/// <summary>
/// 累計日照量
/// </summary>
public double irrSumAvg { get; set; }
public double envTempAvg { get; set; }
public double humidityAvg { get; set; }
public double windAvg { get; set; }
public double dustAvg { get; set; }
public double irrAvg { get; set; }
public int count { get; set; }
}
public class sensor_hour
{
public string SiteID { get; set; }
public string reportdate { get; set; }
public double irrAvg { get; set; }
public string reportdate { get; set; }
public double modelTempAvg { get; set; }
/// <summary>
/// 累計日照量
/// </summary>
public double irrSumAvg { get; set; }
public double envTempAvg { get; set; }
public double humidityAvg { get; set; }
public double windAvg { get; set; }
public double dustAvg { get; set; }
public double irrAvg { get; set; }
public int count { get; set; }
}
}

View File

@ -137,9 +137,9 @@ namespace solarApp.Service
//電表
#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
from " + siteDB + ".s" + siteID + @"_sensorAvg
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @reportDate
@ -167,7 +167,7 @@ namespace solarApp.Service
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
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
where left(`TIMESTAMP`, 10) = '" + reportDate + "' and b.`code` = @siteID";
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
// 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";
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
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
@ -203,7 +203,7 @@ namespace solarApp.Service
using (MySqlConnection conn = new MySqlConnection(Connection1))
{
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
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>();

View File

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

View File

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

View File

@ -215,19 +215,19 @@ namespace solarApp.Service
cmd.Parameters.Clear();
#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,
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,
/*CASE
WHEN b.SolarType = 1 THEN a.KWH * PowerRate * c.LeaseRate
ELSE a.KWH * PowerRate
END MONEY,
CASE
WHEN b.SolarType = 1 THEN a.TOTALKWH * PowerRate * c.LeaseRate
ELSE a.TOTALKWH * PowerRate
END TOTALMONEY,*/
select b.id PowerStationId, a.reportdate, b.siteID, a.siteType, a.TODAYKWH, a.TOTALKWH, a.KWHKWP,
a1.PR, -- (todayKWH/Capacity)*1000/b.IrrDay as PR, -- PR
a.MP, a.SOLARHOUR,
(a.TODAYKWH * PowerRate) MONEY,
(a.TOTALKWH * PowerRate) TOTALMONEY,
(KWH * CarbonRate) CARBON, round((a.TOTALKWH * CarbonRate), 4) TOTALCARBON
@ -235,32 +235,68 @@ namespace solarApp.Service
(
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((avg(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
(
)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 });
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 a join sensor_history_day b on a.id = b.PowerStationID
where `code` = @siteID and left(`TIMESTAMP`, 10) = @date1
) b on a.siteID = b.siteID ";
// sql = @" INSERT INTO solar_master.power_station_history_day( PowerStationId, `TIMESTAMP`, SITEID, SITETYPE, TODAYKWH, TOTALKWH, KWHKWP,
// 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,
// /*CASE
// WHEN b.SolarType = 1 THEN a.KWH * PowerRate * c.LeaseRate
// 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.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 });
cmd.Parameters.AddWithValue("@date1", _date1);
cmd.Parameters.AddWithValue("@siteID", _siteID);
cmd.CommandText = sql;

View File

@ -186,9 +186,34 @@ namespace solarApp
private void bt_archive_Click(object sender, EventArgs e)
{
bt_Sensor.PerformClick();
bt_Inv.PerformClick();
bt_site.PerformClick();
int i = 0;
var site_list = stationSvc.get_station_list();
//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)