1. 逆變器分析
This commit is contained in:
parent
6d6ddf6a98
commit
e6fc479efd
@ -260,7 +260,7 @@ namespace SolarPower.Controllers
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public async Task<ApiResult<InverterHeatMap>> GetInverterHeatMapAnalysis(PostInverterAnalysis post)
|
||||
public async Task<ApiResult<InverterHeatMap>> GetInverterHeatMapAnalysis(PostInverterHeatMapAnalysis post)
|
||||
{
|
||||
ApiResult<InverterHeatMap> apiResult = new ApiResult<InverterHeatMap>();
|
||||
|
||||
@ -276,8 +276,6 @@ namespace SolarPower.Controllers
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
post.SelectedDate = "2021-07-08";
|
||||
|
||||
var inverterHistories = await overviewRepository.GetListInverterByPowerStationIdAndDate(powerStation.Id, post.SelectedDate);
|
||||
|
||||
inverterHeatMap.XAxis = inverterHistories.Select(x => x.TIMESTAMP).Distinct().ToList();
|
||||
@ -358,5 +356,142 @@ namespace SolarPower.Controllers
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<ApiResult<InverterkwhBar>> GetInverterkwhBarAnalysis(PostInverterkwhBarAnalysis post)
|
||||
{
|
||||
ApiResult<InverterkwhBar> apiResult = new ApiResult<InverterkwhBar>();
|
||||
|
||||
InverterkwhBar inverterkwhBar = new InverterkwhBar();
|
||||
try
|
||||
{
|
||||
var powerStation = await powerStationRepository.GetOneAsync(post.PowerStationId);
|
||||
|
||||
if (powerStation == null)
|
||||
{
|
||||
apiResult.Code = "9992";
|
||||
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
switch (post.SelectedType)
|
||||
{
|
||||
case 0: //單日
|
||||
var inverterHistoriesDay = await overviewRepository.GetListInverterDayByPowerStationId(powerStation.Id, post.SelectedDate);
|
||||
|
||||
inverterkwhBar.Labels = inverterHistoriesDay.Select(x => x.TIMESTAMP).Distinct().ToList();
|
||||
inverterkwhBar.Datasets = new Dictionary<string, List<double>>();
|
||||
|
||||
var inverterHistory_group = inverterHistoriesDay.GroupBy(x => x.INVERTERID).ToList();
|
||||
foreach (var inverterHistory in inverterHistory_group)
|
||||
{
|
||||
List<double> values = new List<double>();
|
||||
foreach (var value in inverterHistory)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
}
|
||||
|
||||
inverterkwhBar.Datasets.Add(inverterHistory.Key, values);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: //單月
|
||||
var inverterHistoriesMonth = await overviewRepository.GetListInverterMonthByPowerStationId(powerStation.Id, post.SelectedDate);
|
||||
|
||||
inverterkwhBar.Labels = inverterHistoriesMonth.Select(x => x.TIMESTAMP).Distinct().ToList();
|
||||
inverterkwhBar.Datasets = new Dictionary<string, List<double>>();
|
||||
|
||||
var inverterHistoryMonth_group = inverterHistoriesMonth.GroupBy(x => x.INVERTERID).ToList();
|
||||
foreach (var inverterHistory in inverterHistoryMonth_group)
|
||||
{
|
||||
List<double> values = new List<double>();
|
||||
foreach (var value in inverterHistory)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
}
|
||||
|
||||
inverterkwhBar.Datasets.Add(inverterHistory.Key, values);
|
||||
}
|
||||
break;
|
||||
case 2: //單季
|
||||
var startMonth = ""; var endMonth = "";
|
||||
switch (post.SelectedQuaryerly)
|
||||
{
|
||||
case 0:
|
||||
startMonth = string.Format("{0}-01", post.SelectedDate);
|
||||
endMonth = string.Format("{0}-03", post.SelectedDate);
|
||||
break;
|
||||
case 1:
|
||||
startMonth = string.Format("{0}-04", post.SelectedDate);
|
||||
endMonth = string.Format("{0}-06", post.SelectedDate);
|
||||
break;
|
||||
case 2:
|
||||
startMonth = string.Format("{0}-07", post.SelectedDate);
|
||||
endMonth = string.Format("{0}-09", post.SelectedDate);
|
||||
break;
|
||||
case 3:
|
||||
startMonth = string.Format("{0}-10", post.SelectedDate);
|
||||
endMonth = string.Format("{0}-12", post.SelectedDate);
|
||||
break;
|
||||
}
|
||||
|
||||
var inverterHistoriesQuaryerly = await overviewRepository.GetListInverterQuaryerlyByPowerStationId(powerStation.Id, startMonth, endMonth);
|
||||
|
||||
|
||||
|
||||
inverterkwhBar.Labels = inverterHistoriesQuaryerly.Select(x => x.TIMESTAMP).Distinct().ToList();
|
||||
inverterkwhBar.Datasets = new Dictionary<string, List<double>>();
|
||||
|
||||
var inverterHistoryQuaryerly_group = inverterHistoriesQuaryerly.GroupBy(x => x.INVERTERID).ToList();
|
||||
foreach (var inverterHistory in inverterHistoryQuaryerly_group)
|
||||
{
|
||||
List<double> values = new List<double>();
|
||||
foreach (var value in inverterHistory)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
}
|
||||
|
||||
inverterkwhBar.Datasets.Add(inverterHistory.Key, values);
|
||||
}
|
||||
break;
|
||||
case 3: //單年
|
||||
var inverterHistoriesYear = await overviewRepository.GetListInverterYearByPowerStationId(powerStation.Id, post.SelectedDate);
|
||||
|
||||
inverterkwhBar.Labels = inverterHistoriesYear.Select(x => x.TIMESTAMP).Distinct().ToList();
|
||||
inverterkwhBar.Datasets = new Dictionary<string, List<double>>();
|
||||
|
||||
var inverterHistoryYear_group = inverterHistoriesYear.GroupBy(x => x.INVERTERID).ToList();
|
||||
foreach (var inverterHistory in inverterHistoryYear_group)
|
||||
{
|
||||
List<double> values = new List<double>();
|
||||
foreach (var value in inverterHistory)
|
||||
{
|
||||
values.Add(value.KWH);
|
||||
}
|
||||
|
||||
inverterkwhBar.Datasets.Add(inverterHistory.Key, values);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = inverterkwhBar;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】");
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
}
|
||||
|
||||
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ namespace SolarPower.Models
|
||||
public string FormId { get; set; }
|
||||
}
|
||||
|
||||
public class PostInverterAnalysis
|
||||
public class PostInverterHeatMapAnalysis
|
||||
{
|
||||
public int PowerStationId { get; set; }
|
||||
public List<int> CheckInverters { get; set; }
|
||||
@ -125,5 +125,18 @@ namespace SolarPower.Models
|
||||
public double Value { get; set; }
|
||||
}
|
||||
|
||||
public class PostInverterkwhBarAnalysis
|
||||
{
|
||||
public int PowerStationId { get; set; }
|
||||
public byte SelectedType { get; set; }
|
||||
public string SelectedDate { get; set; }
|
||||
public byte SelectedQuaryerly { get; set; }
|
||||
}
|
||||
|
||||
public class InverterkwhBar
|
||||
{
|
||||
public List<string> Labels { get; set; }
|
||||
public Dictionary<string, List<double>> Datasets { get; set; } //數組
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ namespace SolarPower.Quartz.Jobs
|
||||
List<PyrheliometerHistory> insertPyrheliometerHistoryMonths = new List<PyrheliometerHistory>();
|
||||
List<PyrheliometerHistory> updatePyrheliometerHistoryMonths = new List<PyrheliometerHistory>();
|
||||
|
||||
List<InverterHistory> inverterHistorDays = new List<InverterHistory>();
|
||||
List<InverterHistory> allofInverterHistorDays = new List<InverterHistory>();
|
||||
List<InverterHistory> insertInverterHistoryMonths = new List<InverterHistory>();
|
||||
List<InverterHistory> updateInverterHistoryMonths = new List<InverterHistory>();
|
||||
|
||||
@ -111,10 +111,13 @@ namespace SolarPower.Quartz.Jobs
|
||||
}
|
||||
|
||||
//逆變器
|
||||
var inverterHistorDay = await powerStationRepository.CalcPyrheliometerHistoryDayDataByPowerStationId(dateNowDay, powerStation.Id);
|
||||
if (inverterHistorDay != null)
|
||||
var inverterHistoriesDay = await powerStationRepository.CalcInverterHistoryDayDataByPowerStationId(dateNowDay, powerStation.SiteDB, powerStation.Id);
|
||||
if (inverterHistoriesDay != null)
|
||||
{
|
||||
inverterHistorDays.Add(inverterHistorDay);
|
||||
foreach(var inverterHistoryDay in inverterHistoriesDay)
|
||||
{
|
||||
allofInverterHistorDays.Add(inverterHistoryDay);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -162,6 +165,33 @@ namespace SolarPower.Quartz.Jobs
|
||||
updatePyrheliometerHistoryMonths.Add(pyrheliometerHistoryMonth);
|
||||
}
|
||||
}
|
||||
|
||||
//電站該月份的的逆變器歷史資料
|
||||
var exist_inverter_histories = await powerStationRepository.GetInverterHistoryByPowerStationIdAndMonth(dateNowMonth, powerStation.Id);
|
||||
if (exist_inverter_histories.Count == 0 )
|
||||
{ //新增
|
||||
var inverterHistoriesMonth = await powerStationRepository.CalcInverterHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.SiteDB, powerStation.Id);
|
||||
if (inverterHistoriesMonth.Count > 0)
|
||||
{
|
||||
foreach(var inverterHistoryMonth in inverterHistoriesMonth)
|
||||
{
|
||||
inverterHistoryMonth.TIMESTAMP = Convert.ToDateTime(inverterHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
|
||||
insertInverterHistoryMonths.Add(inverterHistoryMonth);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ //修改
|
||||
var inverterHistoriesMonth = await powerStationRepository.CalcInverterHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.SiteDB, powerStation.Id);
|
||||
if (inverterHistoriesMonth.Count > 0)
|
||||
{
|
||||
foreach (var inverterHistoryMonth in inverterHistoriesMonth)
|
||||
{
|
||||
inverterHistoryMonth.TIMESTAMP = Convert.ToDateTime(inverterHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
|
||||
updateInverterHistoryMonths.Add(inverterHistoryMonth);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
count++;
|
||||
@ -246,6 +276,31 @@ namespace SolarPower.Quartz.Jobs
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region step6. 將各電站的每日及月的逆變器資料insert or update 各資料表
|
||||
List<string> inverter_history_properties = new List<string>()
|
||||
{
|
||||
"PowerStationId",
|
||||
"TIMESTAMP",
|
||||
"INVERTERID",
|
||||
"KWH",
|
||||
"TODAYKWH",
|
||||
"KWHKWP",
|
||||
};
|
||||
//每日
|
||||
await powerStationRepository.AddInverterHistoryDayList(allofInverterHistorDays, inverter_history_properties);
|
||||
|
||||
//每月
|
||||
if (insertInverterHistoryMonths.Count > 0)
|
||||
{
|
||||
await powerStationRepository.AddInverterHistoryMonthList(insertInverterHistoryMonths, inverter_history_properties);
|
||||
}
|
||||
|
||||
if (updateInverterHistoryMonths.Count > 0)
|
||||
{
|
||||
await powerStationRepository.UpdateInverterHistoryMonthList(updateInverterHistoryMonths);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
@ -378,5 +378,101 @@ namespace SolarPower.Repository.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<InverterHistory>> GetListInverterDayByPowerStationId(int powerStationId, string day)
|
||||
{
|
||||
List<InverterHistory> result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var sql_power = @$"SELECT DATE_FORMAT(inv.TIMESTAMP, '%Y-%m-%d %H') AS TIMESTAMP,
|
||||
inv.INVERTERID,
|
||||
inv.KWH
|
||||
FROM inverter_history_hour inv
|
||||
WHERE inv.PowerStationId = @PowerStationId
|
||||
AND DATE_FORMAT(inv.timestamp, '%Y-%m-%d') = @Day";
|
||||
|
||||
result = (await conn.QueryAsync<InverterHistory>(sql_power, new { PowerStationId = powerStationId, Day = day })).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<InverterHistory>> GetListInverterMonthByPowerStationId(int powerStationId, string month)
|
||||
{
|
||||
List<InverterHistory> result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var sql_power = @$"SELECT DATE_FORMAT(inv.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP,
|
||||
inv.INVERTERID,
|
||||
inv.KWH
|
||||
FROM inverter_history_day inv
|
||||
WHERE inv.PowerStationId = @PowerStationId
|
||||
AND DATE_FORMAT(inv.timestamp, '%Y-%m') = @Month";
|
||||
|
||||
result = (await conn.QueryAsync<InverterHistory>(sql_power, new { PowerStationId = powerStationId, Month = month })).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<InverterHistory>> GetListInverterQuaryerlyByPowerStationId(int powerStationId, string startMonth, string endMonth)
|
||||
{
|
||||
List<InverterHistory> result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var sql_power = @$"SELECT DATE_FORMAT(inv.TIMESTAMP, '%Y-%m') AS TIMESTAMP,
|
||||
inv.INVERTERID,
|
||||
inv.KWH
|
||||
FROM inverter_history_month inv
|
||||
WHERE inv.PowerStationId = @PowerStationId
|
||||
AND DATE_FORMAT(inv.timestamp, '%Y-%m') BETWEEN @StartMonth AND @EndMonth";
|
||||
|
||||
result = (await conn.QueryAsync<InverterHistory>(sql_power, new { PowerStationId = powerStationId, StartMonth = startMonth, EndMonth = endMonth })).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<InverterHistory>> GetListInverterYearByPowerStationId(int powerStationId, string year)
|
||||
{
|
||||
List<InverterHistory> result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var sql_power = @$"SELECT DATE_FORMAT(inv.TIMESTAMP, '%Y-%m') AS TIMESTAMP,
|
||||
inv.INVERTERID,
|
||||
inv.KWH
|
||||
FROM inverter_history_month inv
|
||||
WHERE inv.PowerStationId = @PowerStationId
|
||||
AND DATE_FORMAT(inv.timestamp, '%Y') = @Year";
|
||||
|
||||
result = (await conn.QueryAsync<InverterHistory>(sql_power, new { PowerStationId = powerStationId, Year = year })).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -2495,6 +2495,114 @@ namespace SolarPower.Repository.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<InverterHistory>> CalcInverterHistoryDayDataByPowerStationId(string nowDay, string db_name, int powerStationId)
|
||||
{
|
||||
List<InverterHistory> result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var sql = $@"SELECT
|
||||
inv.PowerStationId,
|
||||
DATE_FORMAT(inv.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP,
|
||||
inv.INVERTERID,
|
||||
SUM(inv.KWH) AS KWH,
|
||||
MAX(inv.TODAYKWH) AS TODAYKWH,
|
||||
MAX(inv.TODAYKWH) / i.Capacity AS KWHKWP
|
||||
FROM inverter_history_hour inv
|
||||
LEFT JOIN {db_name}.inverter i ON CONCAT('s', inv.INVERTERID) = i.InverterId
|
||||
WHERE DATE_FORMAT(inv.TIMESTAMP, '%Y-%m-%d') = @NowDay
|
||||
AND PowerStationId = @PowerStationId
|
||||
GROUP BY DATE_FORMAT(inv.TIMESTAMP, '%Y-%m-%d'), inv.INVERTERID";
|
||||
|
||||
result = (await conn.QueryAsync<InverterHistory>(sql, new { NowDay = nowDay, PowerStationId = powerStationId })).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> AddInverterHistoryDayList(List<InverterHistory> entity, List<string> properties)
|
||||
{
|
||||
int count;
|
||||
using (IDbConnection conn = _databaseHelper.GetConnection())
|
||||
{
|
||||
conn.Open();
|
||||
using (var trans = conn.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = GenerateInsertQueryWithCustomTable(properties, "inverter_history_day");
|
||||
|
||||
count = await conn.ExecuteAsync(sql, entity, trans);
|
||||
|
||||
trans.Commit();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
trans.Rollback();
|
||||
throw exception;
|
||||
}
|
||||
finally
|
||||
{
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<InverterHistory>> GetInverterHistoryByPowerStationIdAndMonth(string month, int powerStationId)
|
||||
{
|
||||
List<InverterHistory> result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var sql = $@"SELECT * FROM inverter_history_month WHERE DATE_FORMAT(TIMESTAMP, '%Y-%m') = @Month AND PowerStationId = @PowerStationId";
|
||||
result = (await conn.QueryAsync<InverterHistory>(sql, new { Month = month, PowerStationId = powerStationId })).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<InverterHistory>> CalcInverterHistoryMonthDataByPowerStationId(string month, string db_name, int powerStationId)
|
||||
{
|
||||
List<InverterHistory> result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var sql = $@"SELECT
|
||||
inv.PowerStationId,
|
||||
DATE_FORMAT(inv.TIMESTAMP, '%Y-%m') AS TIMESTAMP,
|
||||
inv.INVERTERID,
|
||||
SUM(inv.KWH) AS KWH,
|
||||
SUM(inv.TODAYKWH) AS TODAYKWH,
|
||||
SUM(inv.TODAYKWH) / i.Capacity AS KWHKWP
|
||||
FROM inverter_history_day inv
|
||||
LEFT JOIN {db_name}.inverter i ON CONCAT('s', inv.INVERTERID) = i.InverterId
|
||||
WHERE DATE_FORMAT(inv.TIMESTAMP, '%Y-%m') = @Month
|
||||
AND inv.PowerStationId = @PowerStationId
|
||||
GROUP BY DATE_FORMAT(inv.TIMESTAMP, '%Y-%m'), inv.INVERTERID";
|
||||
result = (await conn.QueryAsync<InverterHistory>(sql, new { Month = month, PowerStationId = powerStationId })).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<A> Getonediv<A>(string where, string db_name, string table_name)
|
||||
{
|
||||
A result;
|
||||
@ -2544,5 +2652,73 @@ namespace SolarPower.Repository.Implement
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> AddInverterHistoryMonthList(List<InverterHistory> entity, List<string> properties)
|
||||
{
|
||||
int count;
|
||||
using (IDbConnection conn = _databaseHelper.GetConnection())
|
||||
{
|
||||
conn.Open();
|
||||
using (var trans = conn.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = GenerateInsertQueryWithCustomTable(properties, "inverter_history_month");
|
||||
|
||||
count = await conn.ExecuteAsync(sql, entity, trans);
|
||||
|
||||
trans.Commit();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
trans.Rollback();
|
||||
throw exception;
|
||||
}
|
||||
finally
|
||||
{
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> UpdateInverterHistoryMonthList(List<InverterHistory> entity)
|
||||
{
|
||||
int count;
|
||||
using (IDbConnection conn = _databaseHelper.GetConnection())
|
||||
{
|
||||
conn.Open();
|
||||
using (var trans = conn.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = @"UPDATE inverter_history_month SET
|
||||
KWH=@KWH,
|
||||
TODAYKWH=@TODAYKWH,
|
||||
KWHKWP=@KWHKWP
|
||||
WHERE PowerStationId = @PowerStationId
|
||||
AND TIMESTAMP LIKE CONCAT(@TIMESTAMP, '%')
|
||||
AND INVERTERID = @INVERTERID";
|
||||
|
||||
count = await conn.ExecuteAsync(sql, entity, trans);
|
||||
|
||||
trans.Commit();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
trans.Rollback();
|
||||
throw exception;
|
||||
}
|
||||
finally
|
||||
{
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,5 +24,10 @@ namespace SolarPower.Repository.Interface
|
||||
Task<List<CheckBox>> GetInvertCheckBoxByPowerStationId(int powerStationId, string db_name);
|
||||
|
||||
Task<List<InverterHistory>> GetListInverterByPowerStationIdAndDate(int powerStationId, string nowDay);
|
||||
|
||||
Task<List<InverterHistory>> GetListInverterDayByPowerStationId(int powerStationId, string day);
|
||||
Task<List<InverterHistory>> GetListInverterMonthByPowerStationId(int powerStationId, string month);
|
||||
Task<List<InverterHistory>> GetListInverterQuaryerlyByPowerStationId(int powerStationId, string startMonth, string endMonth);
|
||||
Task<List<InverterHistory>> GetListInverterYearByPowerStationId(int powerStationId, string year);
|
||||
}
|
||||
}
|
||||
|
||||
@ -511,5 +511,12 @@ namespace SolarPower.Repository.Interface
|
||||
|
||||
Task<List<InverterHistory>> CalcInverterHisyortHourData(string dateTime, string db_name, string table_name);
|
||||
Task<int> AddInverterHisyort(List<InverterHistory> entity, List<string> properties);
|
||||
Task<List<InverterHistory>> CalcInverterHistoryDayDataByPowerStationId(string nowDay, string db_name, int powerStationId);
|
||||
Task<int> AddInverterHistoryDayList(List<InverterHistory> entity, List<string> properties);
|
||||
Task<List<InverterHistory>> GetInverterHistoryByPowerStationIdAndMonth(string month, int powerStationId);
|
||||
Task<List<InverterHistory>> CalcInverterHistoryMonthDataByPowerStationId(string month, string db_name, int powerStationId);
|
||||
Task<int> AddInverterHistoryMonthList(List<InverterHistory> entity, List<string> properties);
|
||||
Task<int> UpdateInverterHistoryMonthList(List<InverterHistory> entity);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ namespace SolarPower
|
||||
#region 計算電站發電量等資訊(每整點5分執行)
|
||||
services.AddSingleton<CalcPowerStationJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0 5 * * * ?")
|
||||
new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0 5 * * * ?")
|
||||
//new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0/10 * * * * ?")
|
||||
);
|
||||
#endregion
|
||||
@ -110,7 +110,7 @@ namespace SolarPower
|
||||
services.AddSingleton<CalcAvgPowerStationJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0 0 2 * * ?")
|
||||
//new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0/10 * * * * ?")
|
||||
//new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0/10 * * * * ?")
|
||||
);
|
||||
#endregion
|
||||
services.AddHostedService<QuartzHostedService>();
|
||||
|
||||
@ -111,6 +111,7 @@
|
||||
var err_status = 0;//異常紀錄,0:為解決 1:已解決
|
||||
var groupType = 0; //0:日 1:月 2:年 3:歷年
|
||||
var historyRange = "";
|
||||
var selectInverterkwhBarType = 0;
|
||||
|
||||
$(function () {
|
||||
var url = new URL(location.href);
|
||||
@ -699,7 +700,7 @@
|
||||
}
|
||||
|
||||
$("#work_person_select_modal").empty();
|
||||
|
||||
|
||||
if (rel.data.length > 0) {
|
||||
|
||||
$.each(rel.data, function (index, val) {
|
||||
@ -714,7 +715,9 @@
|
||||
});
|
||||
//#endregion
|
||||
|
||||
//#region 基本資料tab
|
||||
//#region 逆變器分析 tab
|
||||
|
||||
ChangeInverterkwhBarDaily();
|
||||
|
||||
//#region 載入電站逆變器資料
|
||||
var url = "/StationOverview/GetInverterCheckBox";
|
||||
@ -742,7 +745,6 @@
|
||||
}, 'json');
|
||||
//#endregion
|
||||
//#endregion
|
||||
});
|
||||
|
||||
//#region 維修單運維人員(異常紀錄)
|
||||
var url_power_station_operation_personnel = "/PowerStation/GetOperationPersonnelSelectOptionList";
|
||||
@ -1594,8 +1596,8 @@
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//#region 載入逆便器分析資料
|
||||
function LoadInvertAnalysis() {
|
||||
//#region 載入逆便器分析HeatMap資料
|
||||
function LoadInvertAnalysisHeatMap() {
|
||||
|
||||
var checkInverts = $("input[name='selectedInvert[]']:checked").map(function () {
|
||||
return $(this).val();
|
||||
@ -1673,23 +1675,7 @@
|
||||
}, 'json');
|
||||
//#endregion
|
||||
|
||||
//#region 逆變器柱狀圖
|
||||
//#region HeatMap
|
||||
var url = "/StationOverview/GetInverterkwhAnalysis";
|
||||
var send_data = {
|
||||
PowerStationId: stationId,
|
||||
SelectedDate: $("#inverter-selected-heatmap-date").val()
|
||||
}
|
||||
$.post(url, send_data, function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
HeatMap = rel.data;
|
||||
|
||||
}, 'json');
|
||||
//#endregion
|
||||
}
|
||||
//#endregion
|
||||
|
||||
@ -1707,10 +1693,13 @@
|
||||
}
|
||||
$(e).removeClass("btn-secondary").addClass("btn-success");
|
||||
|
||||
selectInverterkwhBarType = 0;
|
||||
|
||||
$('#inverter-selected-kwhbar-date').prop('type', 'date');
|
||||
|
||||
var today = new Date().toISOString().substring(0, 10);
|
||||
$('#inverter-selected-kwhbar-date').val(today);
|
||||
$('#inverter-selected-kwhbar-date').val(today).trigger('change');
|
||||
$('#inverter-selected-kwhbar-quaryerly').hide().val(0);
|
||||
}
|
||||
|
||||
function ChangeInverterkwhBarMonthly(e) {
|
||||
@ -1719,10 +1708,13 @@
|
||||
}
|
||||
$(e).removeClass("btn-secondary").addClass("btn-success");
|
||||
|
||||
selectInverterkwhBarType = 1;
|
||||
|
||||
$('#inverter-selected-kwhbar-date').prop('type', 'month');
|
||||
|
||||
var now_month = new Date().toISOString().substring(0, 7);
|
||||
$('#inverter-selected-kwhbar-date').val(now_month);
|
||||
$('#inverter-selected-kwhbar-date').val(now_month).trigger('change');
|
||||
$('#inverter-selected-kwhbar-quaryerly').hide().val(0).trigger('change');
|
||||
}
|
||||
|
||||
function ChangeInverterkwhBarQuaryerly(e) {
|
||||
@ -1731,19 +1723,100 @@
|
||||
}
|
||||
$(e).removeClass("btn-secondary").addClass("btn-success");
|
||||
|
||||
selectInverterkwhBarType = 2;
|
||||
|
||||
$('#inverter-selected-kwhbar-date').prop({ 'type': 'number', 'min': 1900, 'max': now_year, 'step': 1 });
|
||||
|
||||
var now_year = new Date().toISOString().substring(0, 4);
|
||||
|
||||
$('#inverter-selected-kwhbar-date').val(now_year);
|
||||
$('#inverter-selected-kwhbar-quaryerly').show().val(0);
|
||||
}
|
||||
|
||||
function ChangeInverterkwhBarAnnual(e) {
|
||||
var now_year = new Date().toISOString().substring(0, 4);
|
||||
|
||||
if ($(".btn-change-inverter-kwhbar").hasClass("btn-success")) {
|
||||
$(".btn-change-inverter-kwhbar").removeClass("btn-success").addClass("btn-secondary");
|
||||
}
|
||||
$(e).removeClass("btn-secondary").addClass("btn-success");
|
||||
|
||||
selectInverterkwhBarType = 3;
|
||||
|
||||
$('#inverter-selected-kwhbar-date').prop({ 'type': 'number', 'min': 1900, 'max': now_year, 'step': 1 });
|
||||
|
||||
var now_year = new Date().toISOString().substring(0, 4);
|
||||
$('#inverter-selected-kwhbar-date').val(now_year);
|
||||
$('#inverter-selected-kwhbar-quaryerly').hide().val(0).trigger('change');
|
||||
}
|
||||
|
||||
function LoadInvertAnalysiskwhBar() {
|
||||
var url = "/StationOverview/GetInverterkwhBarAnalysis";
|
||||
var send_data = {
|
||||
PowerStationId: stationId,
|
||||
SelectedType: selectInverterkwhBarType,
|
||||
SelectedDate: $("#inverter-selected-kwhbar-date").val(),
|
||||
SelectedQuaryerly: $('#inverter-selected-kwhbar-quaryerly').val()
|
||||
}
|
||||
$.post(url, send_data, function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
kwhBar = rel.data;
|
||||
|
||||
var bgColorlist = [];
|
||||
for (let i = 0; i < Object.keys(kwhBar.datasets).length; i++) {
|
||||
var bgColorlist = bgColorlist.concat(rgba(0.4));
|
||||
}
|
||||
|
||||
mydatasets = Object.keys(kwhBar.datasets).map(function (key, index) {
|
||||
var dataset = {
|
||||
label: key,
|
||||
borderWidth: 1,
|
||||
data: kwhBar.datasets[key],
|
||||
backgroundColor: bgColorlist[index],
|
||||
}
|
||||
|
||||
return dataset;
|
||||
});
|
||||
|
||||
$('#inverter-kWh-convas-div').empty();
|
||||
$('#inverter-kWh-convas-div').append('<canvas id="inverter-kWh"></canvas>');
|
||||
|
||||
var ctx_inverter_kWh = document.getElementById('inverter-kWh').getContext('2d');
|
||||
var myInverterkwh = new Chart(ctx_inverter_kWh, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: kwhBar.labels,
|
||||
datasets: mydatasets
|
||||
},
|
||||
options: {
|
||||
title: {
|
||||
display: true,
|
||||
text: '逆變器發電量'
|
||||
},
|
||||
legend: {
|
||||
display: true,
|
||||
position: 'bottom'
|
||||
}
|
||||
}
|
||||
});
|
||||
//#endregion
|
||||
|
||||
}, 'json');
|
||||
|
||||
}
|
||||
|
||||
//rgb颜色随机
|
||||
function rgba(a) {
|
||||
var r = Math.floor(Math.random() * 256);
|
||||
var g = Math.floor(Math.random() * 256);
|
||||
var b = Math.floor(Math.random() * 256);
|
||||
var rgba = 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
|
||||
return rgba;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//#region 歷史
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button type="button" class="btn btn-success waves-effect waves-themed" onclick="LoadInvertAnalysis()">查詢</button>
|
||||
<button type="button" class="btn btn-success waves-effect waves-themed" onclick="LoadInvertAnalysisHeatMap()">查詢</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-5 d-flex justify-content-start">
|
||||
@ -40,17 +40,22 @@
|
||||
<button type="button" class="btn btn-secondary waves-effect waves-themed btn-change-inverter-kwhbar" onclick="ChangeInverterkwhBarAnnual(this)">年</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="form-group">
|
||||
<input class="form-control" id="inverter-selected-kwhbar-date" type="date">
|
||||
<select class="form-control" id="inverter-selected-kwhbar-date">
|
||||
<option value="1">1 ~ 3 月</option>
|
||||
<option value="2">4 ~ 6 月</option>
|
||||
<option value="3">7 ~ 9 月</option>
|
||||
<option value="4">9 ~ 12 月</option>
|
||||
<div class="form-group row">
|
||||
<input class="form-control col" id="inverter-selected-kwhbar-date" type="date">
|
||||
<select class="form-control col" id="inverter-selected-kwhbar-quaryerly" style="display: none">
|
||||
<option value="0">1 ~ 3 月</option>
|
||||
<option value="1">4 ~ 6 月</option>
|
||||
<option value="2">7 ~ 9 月</option>
|
||||
<option value="3">9 ~ 12 月</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button type="button" class="btn btn-success waves-effect waves-themed" onclick="LoadInvertAnalysiskwhBar()">查詢</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="inverter-kWh-convas-div">
|
||||
<canvas id="inverter-kWh"></canvas>
|
||||
</div>
|
||||
<canvas id="inverter-kWh"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Reference in New Issue
Block a user