Skip to content

Commit d3c1260

Browse files
committed
Implemented: Counters in P1 Electra/Gas month reports per day
1 parent fc16243 commit d3c1260

File tree

6 files changed

+73
-22
lines changed

6 files changed

+73
-22
lines changed

History.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Version 2.0.xxxx (xxxx 2015)
7777
- Changed: General Graph, min value is now calculated dynamically
7878
- Implemented: CORS browser support
7979
- Implemented: Settings, Battery Low check
80+
- Implemented: Counters in P1 Electra/Gas month reports per day
8081

8182
Version 2.0.2284 (February 22th 2015)
8283
- Fixed: Firefox, RGBW/Setpoint popup

main/WebServer.cpp

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15896,7 +15896,7 @@ namespace http {
1589615896
if (dType == pTypeP1Power)
1589715897
{
1589815898
//Actual Year
15899-
szQuery << "SELECT Value1,Value2,Value5,Value6, Date FROM " << dbasetable << " WHERE (DeviceRowID==" << idx << " AND Date>='" << szDateStart << "' AND Date<='" << szDateEnd << "') ORDER BY Date ASC";
15899+
szQuery << "SELECT Value1,Value2,Value5,Value6, Date, Counter1, Counter2, Counter3, Counter4 FROM " << dbasetable << " WHERE (DeviceRowID==" << idx << " AND Date>='" << szDateStart << "' AND Date<='" << szDateEnd << "') ORDER BY Date ASC";
1590015900
result = m_sql.query(szQuery.str());
1590115901
if (result.size() > 0)
1590215902
{
@@ -15908,6 +15908,11 @@ namespace http {
1590815908

1590915909
root["result"][ii]["d"] = sd[4].substr(0, 16);
1591015910

15911+
double counter_1 = atof(sd[5].c_str());
15912+
double counter_2 = atof(sd[6].c_str());
15913+
double counter_3 = atof(sd[7].c_str());
15914+
double counter_4 = atof(sd[8].c_str());
15915+
1591115916
std::string szUsage1 = sd[0];
1591215917
std::string szDeliv1 = sd[1];
1591315918
std::string szUsage2 = sd[2];
@@ -15928,6 +15933,25 @@ namespace http {
1592815933
root["result"][ii]["r1"] = szTmp;
1592915934
sprintf(szTmp, "%.3f", fDeliv_2 / EnergyDivider);
1593015935
root["result"][ii]["r2"] = szTmp;
15936+
15937+
if (counter_1 != 0)
15938+
{
15939+
sprintf(szTmp, "%.3f", (counter_1 - fUsage_1) / EnergyDivider);
15940+
}
15941+
else
15942+
{
15943+
strcpy(szTmp, "0");
15944+
}
15945+
root["result"][ii]["c1"] = szTmp;
15946+
if (counter_3 != 0)
15947+
{
15948+
sprintf(szTmp, "%.3f", (counter_3 - fUsage_2) / EnergyDivider);
15949+
}
15950+
else
15951+
{
15952+
strcpy(szTmp, "0");
15953+
}
15954+
root["result"][ii]["c3"] = szTmp;
1593115955
ii++;
1593215956
}
1593315957
if (bHaveDeliverd)
@@ -16381,7 +16405,7 @@ namespace http {
1638116405
}
1638216406
}
1638316407
//Actual Year
16384-
szQuery << "SELECT Value, Date FROM " << dbasetable << " WHERE (DeviceRowID==" << idx << " AND Date>='" << szDateStart << "' AND Date<='" << szDateEnd << "') ORDER BY Date ASC";
16408+
szQuery << "SELECT Value, Date, Counter FROM " << dbasetable << " WHERE (DeviceRowID==" << idx << " AND Date>='" << szDateStart << "' AND Date<='" << szDateEnd << "') ORDER BY Date ASC";
1638516409
result = m_sql.query(szQuery.str());
1638616410
if (result.size() > 0)
1638716411
{
@@ -16390,31 +16414,49 @@ namespace http {
1639016414
{
1639116415
std::vector<std::string> sd = *itt;
1639216416

16417+
root["result"][ii]["d"] = sd[1].substr(0, 16);
16418+
1639316419
std::string szValue = sd[0];
16420+
16421+
double fcounter = atof(sd[2].c_str());
16422+
1639416423
switch (metertype)
1639516424
{
1639616425
case MTYPE_ENERGY:
1639716426
sprintf(szTmp, "%.3f", atof(szValue.c_str()) / EnergyDivider);
16398-
szValue = szTmp;
16427+
root["result"][ii]["v"] = szTmp;
16428+
if (fcounter != 0)
16429+
sprintf(szTmp, "%.3f", (fcounter - atof(szValue.c_str())) / EnergyDivider);
16430+
else
16431+
strcpy(szTmp, "0");
16432+
root["result"][ii]["c"] = szTmp;
1639916433
break;
1640016434
case MTYPE_GAS:
1640116435
sprintf(szTmp, "%.2f", atof(szValue.c_str()) / GasDivider);
16402-
szValue = szTmp;
16436+
root["result"][ii]["v"] = szTmp;
16437+
if (fcounter != 0)
16438+
sprintf(szTmp, "%.2f", (fcounter - atof(szValue.c_str())) / GasDivider);
16439+
else
16440+
strcpy(szTmp, "0");
16441+
root["result"][ii]["c"] = szTmp;
1640316442
break;
1640416443
case MTYPE_WATER:
1640516444
sprintf(szTmp, "%.2f", atof(szValue.c_str()) / WaterDivider);
16406-
szValue = szTmp;
16445+
root["result"][ii]["v"] = szTmp;
16446+
if (fcounter != 0)
16447+
sprintf(szTmp, "%.2f", (fcounter - atof(szValue.c_str())) / WaterDivider);
16448+
else
16449+
strcpy(szTmp, "0");
16450+
root["result"][ii]["c"] = szTmp;
1640716451
break;
1640816452
}
16409-
root["result"][ii]["d"] = sd[1].substr(0, 16);
16410-
root["result"][ii]["v"] = szValue;
1641116453
ii++;
1641216454
}
1641316455
}
1641416456
//Past Year
1641516457
szQuery.clear();
1641616458
szQuery.str("");
16417-
szQuery << "SELECT Value, Date FROM " << dbasetable << " WHERE (DeviceRowID==" << idx << " AND Date>='" << szDateStartPrev << "' AND Date<='" << szDateEndPrev << "') ORDER BY Date ASC";
16459+
szQuery << "SELECT Value, Date, Counter FROM " << dbasetable << " WHERE (DeviceRowID==" << idx << " AND Date>='" << szDateStartPrev << "' AND Date<='" << szDateEndPrev << "') ORDER BY Date ASC";
1641816460
result = m_sql.query(szQuery.str());
1641916461
if (result.size() > 0)
1642016462
{
@@ -16423,24 +16465,24 @@ namespace http {
1642316465
{
1642416466
std::vector<std::string> sd = *itt;
1642516467

16468+
root["resultprev"][iPrev]["d"] = sd[1].substr(0, 16);
16469+
1642616470
std::string szValue = sd[0];
1642716471
switch (metertype)
1642816472
{
1642916473
case MTYPE_ENERGY:
1643016474
sprintf(szTmp, "%.3f", atof(szValue.c_str()) / EnergyDivider);
16431-
szValue = szTmp;
16475+
root["resultprev"][iPrev]["v"] = szTmp;
1643216476
break;
1643316477
case MTYPE_GAS:
1643416478
sprintf(szTmp, "%.2f", atof(szValue.c_str()) / GasDivider);
16435-
szValue = szTmp;
16479+
root["resultprev"][iPrev]["v"] = szTmp;
1643616480
break;
1643716481
case MTYPE_WATER:
1643816482
sprintf(szTmp, "%.2f", atof(szValue.c_str()) / WaterDivider);
16439-
szValue = szTmp;
16483+
root["resultprev"][iPrev]["v"] = szTmp;
1644016484
break;
1644116485
}
16442-
root["resultprev"][iPrev]["d"] = sd[1].substr(0, 16);
16443-
root["resultprev"][iPrev]["v"] = szValue;
1644416486
iPrev++;
1644516487
}
1644616488
}
@@ -16670,25 +16712,30 @@ namespace http {
1667016712
total_real = total_max - total_min;
1667116713
sprintf(szTmp, "%llu", total_real);
1667216714

16715+
root["result"][ii]["d"] = szDateEnd;
16716+
1667316717
std::string szValue = szTmp;
1667416718
switch (metertype)
1667516719
{
1667616720
case MTYPE_ENERGY:
1667716721
sprintf(szTmp, "%.3f", atof(szValue.c_str()) / EnergyDivider);
16678-
szValue = szTmp;
16722+
root["result"][ii]["v"] = szTmp;
16723+
sprintf(szTmp, "%.3f", (atof(sValue.c_str()) - atof(szValue.c_str())) / EnergyDivider);
16724+
root["result"][ii]["c"] = szTmp;
1667916725
break;
1668016726
case MTYPE_GAS:
1668116727
sprintf(szTmp, "%.2f", atof(szValue.c_str()) / GasDivider);
16682-
szValue = szTmp;
16728+
root["result"][ii]["v"] = szTmp;
16729+
sprintf(szTmp, "%.2f", (atof(sValue.c_str()) - atof(szValue.c_str())) / GasDivider);
16730+
root["result"][ii]["c"] = szTmp;
1668316731
break;
1668416732
case MTYPE_WATER:
1668516733
sprintf(szTmp, "%.2f", atof(szValue.c_str()) / WaterDivider);
16686-
szValue = szTmp;
16734+
root["result"][ii]["v"] = szTmp;
16735+
sprintf(szTmp, "%.2f", (atof(sValue.c_str()) - atof(szValue.c_str())) / WaterDivider);
16736+
root["result"][ii]["c"] = szTmp;
1668716737
break;
1668816738
}
16689-
16690-
root["result"][ii]["d"] = szDateEnd;
16691-
root["result"][ii]["v"] = szValue;
1669216739
ii++;
1669316740
}
1669416741
}

www/html5.appcache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CACHE MANIFEST
2-
# ref 868
2+
# ref 870
33

44
CACHE:
55
# CSS

www/i18n/domoticz-en.json.gz

522 Bytes
Binary file not shown.

www/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,9 @@ <h1 id="theader" data-i18n="Usage this Year">Usage this Year</h1>
591591
<thead>
592592
<tr valign="middle">
593593
<th width="30" align="right" data-i18n="Day">Day</th>
594-
<th width="60" align="right">Usage</th>
595-
<th width="60" align="right">Costs</th>
594+
<th width="60" align="right" data-i18n="Counter">Counter</th>
595+
<th width="60" align="right" data-i18n="Usage">Usage</th>
596+
<th width="60" align="right" data-i18n="Costs">Costs</th>
596597
<th width="40" align="right">&lt;&gt;</th>
597598
</tr>
598599
</thead>
@@ -659,8 +660,10 @@ <h1 id="theader" data-i18n="Usage this Year">Usage this Year</h1>
659660
<thead>
660661
<tr valign="middle">
661662
<th width="30" align="right" data-i18n="Day">Day</th>
663+
<th width="60" align="right" data-i18n="Counter T1">Counter T1</th>
662664
<th width="60" align="right" data-i18n="Usage T1">Usage T1</th>
663665
<th width="60" align="right" data-i18n="Costs">Costs</th>
666+
<th width="60" align="right" data-i18n="Counter T2">Counter T2</th>
664667
<th width="60" align="right" data-i18n="Usage T2">Usage T2</th>
665668
<th width="60" align="right" data-i18n="Costs">Costs</th>
666669
<th width="60" align="right" data-i18n="Return T1">Return T1</th>

www/js/domoticz.js.gz

48 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)