Skip to content

Commit

Permalink
calculate costs in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Lutz Bender committed Jul 20, 2022
1 parent 068db51 commit 7ae887c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 4 additions & 2 deletions ladelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ processChargepoint(){
else
lademoduslogvalue=$lademodus
fi
openwbDebugLog "CHARGESTAT" 1 "start=$start; end=$jetzt; timeCharged=${ladedauer}m ($ladedauertext); energyCharged=${bishergeladen}kWh; rangeCharged=${gelr}km; averagePower=${ladegeschw}kW"
sed -i "1i$start,$jetzt,$gelr,$bishergeladen,$ladegeschw,$ladedauertext,$chargePointNumber,$lademoduslogvalue,$rfid" "$monthlyfile"
# calculate costs
kosten=$(echo "scale=2;$bishergeladen * $preisjekwh" |bc)
openwbDebugLog "CHARGESTAT" 1 "start=$start; end=$jetzt; timeCharged=${ladedauer}m ($ladedauertext); energyCharged=${bishergeladen}kWh; rangeCharged=${gelr}km; averagePower=${ladegeschw}kW; costs=${kosten}"
sed -i "1i$start,$jetzt,$gelr,$bishergeladen,$ladegeschw,$ladedauertext,$chargePointNumber,$lademoduslogvalue,$rfid,$kosten" "$monthlyfile"
# send push message if configured
if (( pushbenachrichtigung == 1 )) ; then
if (( pushbstopl == 1 )) ; then
Expand Down
15 changes: 9 additions & 6 deletions web/logging/chargelog/ladelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ function putladelogtogether() {
var totalprice=0;

testout.forEach(function(row) {
var price = "0"
rowcount+=1;
content += "<tr>";
var cellcount=0;
Expand All @@ -270,10 +269,9 @@ function putladelogtogether() {
content += "<td class=\"text-right\">" + km.toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 0}) + "</td>";
break;
case 4: // geladene kWh
totalkwh = parseFloat(totalkwh) + parseFloat(cell);
price = parseFloat(cell) * PriceForKWh;
totalprice = parseFloat(totalprice) + parseFloat(price);
content += "<td class=\"text-right\">" + parseFloat(cell).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}) + "</td>";
var kWh = parseFloat(cell);
totalkwh += kWh;
content += "<td class=\"text-right\">" + kWh.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}) + "</td>";
break;
case 5: // Ladeleistung kW
var kW = parseFloat(cell);
Expand Down Expand Up @@ -319,11 +317,16 @@ function putladelogtogether() {
}
content += "</td>";
break;
// 9: RFID-Tag
case 10:
var price = parseFloat(cell);
totalprice += price;
content += "<td class=\"text-right\">" + price.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}) + "€</td>" ;
break;
default:
content += "<td>" + cell + "</td>";
}
});
content += "<td class=\"text-right\">" + price.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}) + "€</td>" ;
content += "</tr>";
});

Expand Down
2 changes: 1 addition & 1 deletion web/logging/chargelog/ladelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<script src="js/bootstrap4-toggle/bootstrap4-toggle.min.js"></script>
<script src="js/mqttws31.js"></script>
<script src="logging/chargelog/helperFunctions.js?ver=20210202"></script>
<script src="logging/chargelog/ladelog.js?ver=20210202"></script>
<script src="logging/chargelog/ladelog.js?ver=20220720"></script>
<script>
function getCookie(cname) {
var name = cname + '=';
Expand Down

0 comments on commit 7ae887c

Please sign in to comment.