This commit is contained in:
Kai 2021-07-12 16:52:10 +08:00
commit 0e15d5cfe4
12 changed files with 215 additions and 56 deletions

View File

@ -523,7 +523,7 @@ namespace SolarPower.Controllers
a.TIMESTAMP = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy-MM");
break;
case 3:
a.TOTALTIME = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy");
a.TOTALTIME = "";
a.TIMESTAMP = Convert.ToDateTime(a.TIMESTAMP).ToString("yyyy");
break;
}

View File

@ -984,7 +984,7 @@ ALTER TABLE `power_station`
ADD COLUMN `HealthStatus` TINYINT(4) UNSIGNED NOT NULL DEFAULT '1' COMMENT '1:設備正常 2:設備斷線 3:設備異常' AFTER `AreaId`;
-- 各電站每天日照度的平均值 20210708
CREATE TABLE `pyrheliometer_history_day` (
CREATE TABLE `sensor_history_day` (
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
`TIMESTAMP` TIMESTAMP NULL DEFAULT NULL,
@ -998,7 +998,7 @@ ENGINE=InnoDB
;
-- 各電站每小時日照度的平均值 20210708
CREATE TABLE `pyrheliometer_history_hour` (
CREATE TABLE `sensor_history_hour` (
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
`TIMESTAMP` TIMESTAMP NULL DEFAULT NULL,
@ -1012,7 +1012,7 @@ ENGINE=InnoDB
;
-- 各電站每月日照度的平均值 20210708
CREATE TABLE `pyrheliometer_history_month` (
CREATE TABLE `sensor_history_month` (
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
`TIMESTAMP` TIMESTAMP NULL DEFAULT NULL,
@ -1095,6 +1095,16 @@ ENGINE=InnoDB
-- 新增模組溫度計溫度 20210712
ALTER TABLE `sensor_history_day`
ADD COLUMN `Temperature` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '每日平均模組溫度計溫度' AFTER `Irradiance`;
ALTER TABLE `sensor_history_hour`
ADD COLUMN `Temperature` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '即時模組溫度計溫度' AFTER `Irradiance`;
ALTER TABLE `sensor_history_month`
ADD COLUMN `Temperature` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '每月平均模組溫度計溫度' AFTER `Irradiance`;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;

View File

@ -626,12 +626,14 @@ namespace SolarPower.Models.PowerStation
public int PowerStationId { get; set; }
public string Timestamp { get; set; }
public double Irradiance { get; set; }
public double Temperature { get; set; }
}
public class AvgPyrheliometerHistory
{
public int PowerStationId { get; set; }
public double AvgIrradiance { get; set; }
public double AvgTemperature { get; set; }
}
public class PyrheliometerHistoryDay

View File

@ -259,7 +259,8 @@ namespace SolarPower.Quartz.Jobs
{
"PowerStationId",
"Timestamp",
"Irradiance"
"Irradiance",
"Temperature"
};
//每日
await powerStationRepository.AddPyrheliometerHistoryDayList(pyrheliometerHistoryDays, pyrheliometer_history_properties);

View File

@ -33,6 +33,7 @@ namespace SolarPower.Quartz.Jobs
List<PowerStationHistory> powerStationHistoriesHour = new List<PowerStationHistory>();
List<PyrheliometerHistory> pyrheliometerHistoriesHour = new List<PyrheliometerHistory>();
List<PyrheliometerHistory> TempHistoriesHour = new List<PyrheliometerHistory>();
List<InverterHistory> inverterHistories = new List<InverterHistory>();
List<PowerStation> calcPowerStations = new List<PowerStation>();
@ -140,12 +141,14 @@ namespace SolarPower.Quartz.Jobs
#endregion
#region step2-2.
//1. 找出該電站所有日照計設備(包共享
//1. 找出該電站所有日照計設備(包共享
var deviceInfos = await powerStationRepository.GetListPyrheliometerByPowerStationId(powerStation.Id, powerStation.SiteDB);
// 找出該電站所有溫度計設備(包含共享
var tempdeviceInfos = await powerStationRepository.GetListTempByPowerStationId(powerStation.Id, powerStation.SiteDB);
if (deviceInfos != null)
{
//2. 計算該電站所有日照計設的每小時的平均在依照日照計數量平均
var pyrheliometerHistory = await powerStationRepository.GetPyrheliometerHistoryPerHour(dateTime, deviceInfos);
var pyrheliometerHistory = await powerStationRepository.GetPyrheliometerHistoryPerHour(dateTime, deviceInfos,0);
if (pyrheliometerHistory != null)
{
@ -156,6 +159,19 @@ namespace SolarPower.Quartz.Jobs
pyrheliometerHistoriesHour.Add(pyrheliometerHistory);
}
}
//2. 計算該電站所有溫度計設的每小時的平均在依照溫度計數量平均
if (tempdeviceInfos != null)
{
var tempHistory = await powerStationRepository.GetPyrheliometerHistoryPerHour(dateTime, tempdeviceInfos, 1);
if (tempHistory != null)
{
tempHistory.Timestamp = Convert.ToDateTime(tempHistory.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
tempHistory.PowerStationId = powerStation.Id;
TempHistoriesHour.Add(tempHistory);
}
}
#endregion
#region step2-3.
@ -195,7 +211,7 @@ namespace SolarPower.Quartz.Jobs
await powerStationRepository.AddPowerStationHistory(powerStationHistoriesHour, history_properties);
#endregion
#region step4. Pyrheliometer History INSERT pyrheliometer_history_hour
#region step4. Pyrheliometer History INSERT sensor_history_hour
List<string> pyrheliometer_history_properties = new List<string>()
{
"PowerStationId",
@ -204,6 +220,15 @@ namespace SolarPower.Quartz.Jobs
};
await powerStationRepository.AddPyrheliometerHistory(pyrheliometerHistoriesHour, pyrheliometer_history_properties);
List<string> Temp_history_properties = new List<string>()
{
"PowerStationId",
"TIMESTAMP",
"Temperature"
};
await powerStationRepository.AddTempHistory(TempHistoriesHour, Temp_history_properties);
#endregion
#region step5. calcPowerStations UPDATE power_station

View File

@ -200,7 +200,7 @@ namespace SolarPower.Repository.Implement
{
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d %H') AS Label, ps.KWH AS PowerData, pyr.Irradiance AS IrradianceData
FROM power_station_history_hour ps
LEFT JOIN pyrheliometer_history_hour pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d %H') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d %H')
LEFT JOIN sensor_history_hour pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d %H') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d %H')
WHERE ps.PowerStationId = @PowerStationId
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = @NowDay";
@ -224,7 +224,7 @@ namespace SolarPower.Repository.Implement
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d') AS Label, ps.TODAYKWH AS PowerData, pyr.Irradiance AS IrradianceData
FROM power_station_history_day ps
LEFT JOIN pyrheliometer_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m-%d')
LEFT JOIN sensor_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m-%d')
WHERE ps.PowerStationId = @PowerStationId
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay";
@ -248,7 +248,7 @@ namespace SolarPower.Repository.Implement
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m-%d') AS Label, ps.TODAYKWH AS PowerData, pyr.Irradiance AS IrradianceData
FROM power_station_history_day ps
LEFT JOIN pyrheliometer_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m-%d')
LEFT JOIN sensor_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m-%d')
WHERE ps.PowerStationId = @PowerStationId
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay";
@ -273,7 +273,7 @@ namespace SolarPower.Repository.Implement
var sql_power = @$"SELECT DATE_FORMAT(ps.timestamp, '%Y-%m') AS Label, ps.MONTHKWH AS PowerData, pyr.Irradiance AS IrradianceData
FROM power_station_history_month ps
LEFT JOIN pyrheliometer_history_month pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m')
LEFT JOIN sensor_history_month pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m') = DATE_FORMAT(FROM_UNIXTIME(pyr.timestamp), '%Y-%m')
WHERE ps.PowerStationId = @PowerStationId
AND DATE_FORMAT(ps.timestamp, '%Y') = @Year";
@ -490,28 +490,28 @@ namespace SolarPower.Repository.Implement
case 0:
kwh = "C.KWH";
usedb = "power_station_history_hour";
pyrdb = "pyrheliometer_history_hour";
pyrdb = "sensor_history_hour";
timeGroup = "%Y-%m-%d %H:%M:%S";
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y-%m-%d') = '{post.HistoryRange}'";
break;
case 1:
kwh = "C.TODAYKWH";
usedb = "power_station_history_day";
pyrdb = "pyrheliometer_history_day";
pyrdb = "sensor_history_day";
timeGroup = "%Y-%m-%d";
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y-%m') = '{post.HistoryRange}'";
break;
case 2:
kwh = "C.MONTHKWH";
usedb = "power_station_history_month";
pyrdb = "pyrheliometer_history_month";
pyrdb = "sensor_history_month";
timeGroup = "%Y-%m";
range = $" WHERE DATE_FORMAT(V.TIMESTAMP,'%Y') = '{post.HistoryRange}'";
break;
case 3:
kwh = "C.TOTALKWH";
usedb = "power_station_history_month";
pyrdb = "pyrheliometer_history_month";
pyrdb = "sensor_history_month";
timeGroup = "%Y-%m";
range = "";
break;
@ -527,17 +527,19 @@ namespace SolarPower.Repository.Implement
(
SELECT DENSE_RANK() OVER(ORDER BY C.TIMESTAMP) AS ROWID
, (DENSE_RANK() OVER(ORDER BY C.TIMESTAMP)) - 1 AS PreROWID,
C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance
C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance,P.Temperature AS Temp
FROM {usedb} C
LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}') WHERE C.PowerStationId = {post.PowerstationId} GROUP BY C.TIMESTAMP ORDER BY C.TIMESTAMP
LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}')
WHERE C.PowerStationId = {post.PowerstationId} GROUP BY C.TIMESTAMP ORDER BY C.TIMESTAMP
) A
RIGHT OUTER JOIN
(
SELECT DENSE_RANK() OVER(ORDER BY C.TIMESTAMP) AS ROWID
, (DENSE_RANK() OVER(ORDER BY C.TIMESTAMP)) - 1 AS PreROWID,
C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance
C.TIMESTAMP,{kwh} AS KWH,C.SOLARHOUR,C.PR,P.Irradiance,P.Temperature AS Temp
FROM {usedb} C
LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}') WHERE C.PowerStationId = {post.PowerstationId} GROUP BY C.TIMESTAMP ORDER BY C.TIMESTAMP
LEFT JOIN {pyrdb} P ON DATE_FORMAT(P.TIMESTAMP,'{timeGroup}') = DATE_FORMAT(C.TIMESTAMP,'{timeGroup}')
WHERE C.PowerStationId = {post.PowerstationId} GROUP BY C.TIMESTAMP ORDER BY C.TIMESTAMP
) B
ON A.ROWID = B.PreROWID
) V {range}" ;

View File

@ -2177,7 +2177,6 @@ namespace SolarPower.Repository.Implement
return count;
}
}
public async Task<List<DeviceInfo>> GetListPyrheliometerByPowerStationId(int powerStationId, string db_name)
{
List<DeviceInfo> result;
@ -2204,6 +2203,7 @@ namespace SolarPower.Repository.Implement
return result;
}
}
//(有新增)
public async Task<List<DeviceInfo>> GetListTempByPowerStationId(int powerStationId, string db_name)
{
List<DeviceInfo> result;
@ -2213,12 +2213,12 @@ namespace SolarPower.Repository.Implement
{
var sql = $@"SELECT *
FROM {db_name}.device d
WHERE d.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0
WHERE d.PowerStationId = @PowerStationId AND d.`Type` = 'MTR' AND d.Deleted = 0
UNION
SELECT d.*
FROM {db_name}.sharedevice sd
LEFT JOIN {db_name}.device d ON sd.DeviceId = d.Id
WHERE sd.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0
WHERE sd.PowerStationId = @PowerStationId AND d.`Type` = 'MTR' AND d.Deleted = 0
";
result = (await conn.QueryAsync<DeviceInfo>(sql, new { PowerStationId = powerStationId })).ToList();
@ -2230,9 +2230,18 @@ namespace SolarPower.Repository.Implement
return result;
}
}
public async Task<PyrheliometerHistory> GetPyrheliometerHistoryPerHour(string dateTime, List<DeviceInfo> deviceInfos)
//(有修改)
public async Task<PyrheliometerHistory> GetPyrheliometerHistoryPerHour(string dateTime, List<DeviceInfo> deviceInfos,int type)
{
var typename = "";
if(type == 1)
{
typename = "Temperature";//1為溫度計
}
else if (type == 0)
{
typename = "Irradiance";//0為日照計
}
PyrheliometerHistory result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
@ -2250,7 +2259,7 @@ namespace SolarPower.Repository.Implement
sql_per_device.Add(str);
}
var sql = @"SELECT a.TIMESTAMP, AVG(a.SENSOR) AS Irradiance FROM(" + string.Join(" UNION ", sql_per_device) + @") a GROUP BY TIMESTAMP";
var sql = @$"SELECT a.TIMESTAMP, AVG(a.SENSOR) AS {typename} FROM(" + string.Join(" UNION ", sql_per_device) + @") a GROUP BY TIMESTAMP";
result = await conn.QueryFirstOrDefaultAsync<PyrheliometerHistory>(sql, new { DateTime = dateTime });
}
@ -2272,7 +2281,38 @@ namespace SolarPower.Repository.Implement
{
try
{
string sql = GenerateInsertQueryWithCustomTable(properties, "pyrheliometer_history_hour");
string sql = GenerateInsertQueryWithCustomTable(properties, "sensor_history_hour");
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> AddTempHistory(List<PyrheliometerHistory> entity, List<string> properties)
{
int count;
using (IDbConnection conn = _databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
string sql = GenerateUpdateQueryWithCustomTableAndWHERE(properties, "sensor_history_hour", "PowerStationId = @PowerStationId AND TIMESTAMP = @Timestamp");
count = await conn.ExecuteAsync(sql, entity, trans);
@ -2303,7 +2343,7 @@ namespace SolarPower.Repository.Implement
var startDay = Convert.ToDateTime(nowDay).AddDays(-30).ToString("yyyy-MM-dd");
var sql = $@"SELECT AVG(p.Irradiance) AS AvgIrradiance
FROM pyrheliometer_history_hour p
FROM sensor_history_hour p
WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') BETWEEN @StartDay AND @EndDay
AND p.Irradiance != 0
AND PowerStationId = @PowerStationId
@ -2330,8 +2370,9 @@ namespace SolarPower.Repository.Implement
var sql = $@"SELECT
PowerStationId,
DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP,
AVG(p.Irradiance) AS AvgIrradiance
FROM pyrheliometer_history_hour p
AVG(p.Irradiance) AS Irradiance,
AVG(p.Temperature) AS Temperature
FROM sensor_history_hour p
WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') = @NowDay
AND p.Irradiance != 0
AND PowerStationId = @PowerStationId
@ -2358,7 +2399,7 @@ namespace SolarPower.Repository.Implement
{
try
{
string sql = GenerateInsertQueryWithCustomTable(properties, "pyrheliometer_history_day");
string sql = GenerateInsertQueryWithCustomTable(properties, "sensor_history_day");
count = await conn.ExecuteAsync(sql, entity, trans);
@ -2389,8 +2430,9 @@ namespace SolarPower.Repository.Implement
var sql = $@"SELECT
PowerStationId,
DATE_FORMAT(p.TIMESTAMP, '%Y-%m') AS TIMESTAMP,
AVG(p.Irradiance) AS Irradiance
FROM pyrheliometer_history_hour p
AVG(p.Irradiance) AS Irradiance,
AVG(p.Temperature) AS Temperature
FROM sensor_history_hour p
WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m') = @Month
AND p.Irradiance != 0
AND PowerStationId = @PowerStationId
@ -2414,7 +2456,7 @@ namespace SolarPower.Repository.Implement
{
try
{
var sql = $@"SELECT * FROM pyrheliometer_history_month WHERE DATE_FORMAT(TIMESTAMP, '%Y-%m') = @Month AND PowerStationId = @PowerStationId";
var sql = $@"SELECT * FROM sensor_history_month WHERE DATE_FORMAT(TIMESTAMP, '%Y-%m') = @Month AND PowerStationId = @PowerStationId";
result = await conn.QueryFirstOrDefaultAsync<PyrheliometerHistory>(sql, new { Month = month, PowerStationId = powerStationId });
}
@ -2436,7 +2478,7 @@ namespace SolarPower.Repository.Implement
{
try
{
string sql = GenerateInsertQueryWithCustomTable(properties, "pyrheliometer_history_month");
string sql = GenerateInsertQueryWithCustomTable(properties, "sensor_history_month");
count = await conn.ExecuteAsync(sql, entity, trans);
@ -2467,11 +2509,12 @@ namespace SolarPower.Repository.Implement
{
try
{
string sql = @"UPDATE pyrheliometer_history_month SET
Irradiance=@Irradiance
string sql = @"UPDATE sensor_history_month SET
Irradiance=@Irradiance,
Temperature=@Temperature
WHERE PowerStationId = @PowerStationId
AND TIMESTAMP LIKE CONCAT(@TIMESTAMP, '%')
";
";
count = await conn.ExecuteAsync(sql, entity, trans);

View File

@ -555,6 +555,30 @@ namespace SolarPower.Repository.Implement
return updateQuery.ToString();
}
/// <summary>
/// 產生Update語句可選擇自己要加入資料表填入想要的WHERE條件
/// </summary>
/// <param name="properties"></param>
/// <param name="table_name"></param>
/// <param name="WHERE"></param>
/// <returns></returns>
protected string GenerateUpdateQueryWithCustomTableAndWHERE(List<string> properties, string table_name,string WHERE)
{
var updateQuery = new StringBuilder($"UPDATE {table_name} SET ");
properties.ForEach(property =>
{
if (!property.Equals("Id"))
{
updateQuery.Append($"{property}=@{property},");
}
});
updateQuery.Remove(updateQuery.Length - 1, 1); //remove last comma
updateQuery.Append($" WHERE {WHERE}");
return updateQuery.ToString();
}
protected string GenerateUpdateQueryWithCustomDBNameAndTable(List<string> properties, string db_name, string table_name)
{

View File

@ -494,7 +494,9 @@ namespace SolarPower.Repository.Interface
Task<List<PowerstationOption>> GetPowerstationPyrheliometerAsync(string db_name, int stationId);
Task<List<DeviceInfo>> GetListPyrheliometerByPowerStationId(int powerStationId, string db_name);
Task<PyrheliometerHistory> GetPyrheliometerHistoryPerHour(string dateTime, List<DeviceInfo> deviceInfos);
Task<List<DeviceInfo>> GetListTempByPowerStationId(int powerStationId, string db_name);
Task<PyrheliometerHistory> GetPyrheliometerHistoryPerHour(string dateTime, List<DeviceInfo> deviceInfos,int Type);
Task<int> AddTempHistory(List<PyrheliometerHistory> entity, List<string> properties);
Task<int> AddPyrheliometerHistory(List<PyrheliometerHistory> entity, List<string> properties);
Task<AvgPyrheliometerHistory> CalcAvgPyrheliometerHistory30day(string nowDay, int powerStationId);
Task<PyrheliometerHistory> CalcPyrheliometerHistoryDayDataByPowerStationId(string nowDay, int powerStationId);

View File

@ -2007,14 +2007,19 @@
var diffSOLARHOURALL = 0;
var irradianceALL = 0;
var prALL;
var tempALL;
var tempALL = 0;
var listmonth = new Array(0);
var listkwh = new Array(0);
var listcolor = new Array(0);
var listirradiance = new Array(0);
var color = rgba(1);
$.each(rel.data, function (index, val) {
TimestampALL = val.totaltime;
kwhALL += val.kwh;
diffSOLARHOURALL += val.diffSOLARHOUR;
irradianceALL += val.irradiance;
prALL = val.pr;
tempALL = val.temp;
tempALL += val.temp;
if (val.length != 0) {
$('#HistoryDetailTable').append('<tr>' +
'<td>' + val.timestamp + '</td>' +
@ -2024,8 +2029,49 @@
'<td>' + val.pr + '</td>' +
'<td>' + val.temp + '</td>' +
'</tr>');
listmonth.push(val.timestamp);
listkwh.push(val.kwh);
listcolor.push(color);
listirradiance.push(val.irradiance);
}
})
tempALL = tempALL / rel.data.length;
$('#history-kWh-convas-div').empty();
$('#history-kWh-convas-div').append('<canvas id="history-kWh"></canvas>');
var ctx_history_kWh = document.getElementById('history-kWh').getContext('2d');
var myhistorykwh = new Chart(ctx_history_kWh, {
type: 'bar',
data: {
labels: listmonth,
datasets: [{
backgroundColor: listcolor,
borderColor: listcolor,
borderWidth: 1,
label: '發電量(kWh)',
data: listkwh
}, {
type: 'line',
label: '日照度(kWh/m2)',
fill: false,
data: listirradiance
}]
},
options: {
title: {
display: true,
text: '發電量(kWh)'
},
legend: {
display: true,
position: 'bottom'
}
}
});
if (rel.data.length == 0) {
$('#HistoryTotalTable').append('<tr>' + '<td colspan="6" style="text-align:center;">' + '無資料' + '</td>' + '</tr>');
$('#HistoryDetailTable').append('<tr>' + '<td colspan="6" style="text-align:center;">' + '無資料' + '</td>' + '</tr>');

View File

@ -34,11 +34,11 @@
</div>
<button type="button" class="btn btn-secondary waves-effect waves-themed"> &gt; </button>*@
<input type="date" class="form-control" id="DateGet"/>
<input type="date" class="form-control" id="DateGet" />
<input type="month" class="form-control" id="MonthGet" style="display:none"/>
<input type="month" class="form-control" id="MonthGet" style="display:none" />
<input type="number" class="form-control" min="1900" max="2099" step="1" id="YearGet" style="display:none"/>
<input type="number" class="form-control" min="1900" max="2099" step="1" id="YearGet" style="display:none" />
</div>
</div>
@ -50,6 +50,8 @@
</div>
<div class="row mb-5">
<div class="card p-3 w-100">
<h5 class="font-weight-bold mb-3 pl-5 pb-3">總結</h5>
@ -65,12 +67,15 @@
</tr>
</thead>
<tbody id="HistoryTotalTable">
</tbody>
</table>
</div>
</div>
<div id="history-kWh-convas-div">
<canvas id="history-kWh"></canvas>
</div>
<div class="row mb-5">
<div class="card p-3 w-100">
<h5 class="font-weight-bold mb-3 pl-5 pb-3">詳細資訊</h5>
@ -86,7 +91,6 @@
</tr>
</thead>
<tbody id="HistoryDetailTable">
</tbody>
</table>
</div>