Skip to content

Commit

Permalink
Fix: Handling of internal balance sum now in homogenized field `balan…
Browse files Browse the repository at this point in the history
…cesum` allowing to calculate internal energy exchange of a balancing point.
  • Loading branch information
zoernert committed Jan 30, 2024
1 parent 8ac0986 commit 93e52e5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
48 changes: 29 additions & 19 deletions framework/public/devUI/assets/js/uc_balancing.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,40 @@ $(document).ready(function() {
let html = '';
html += '<table class="table table-condensed table-striped">';
html += '<thead>';
html += '<tr><th>Von</th><th>Nach</th><th class="text-end">Treibhausgasemission</th><th class="text-end">Energie</th></tr>';
html += '<tr><th>Von</th><th>Nach</th><th class="text-end">Treibhausgasemission</th><th class="text-end">Energie</th><th class="text-end">Saldo</th></tr>';
html += '</thead>';
html += '<tbody>';
let co2eq = 0;
let energy = 0;
let absenergy = 0;

for(let i=0;i<data.transactions.length;i++) {
html += '<tr>';
let highlight = '';
if(data.transactions[i].from == data.upstream) highlight='fw-bold';
if(data.transactions[i].to == data.upstream) highlight='fw-bold';
html += '<td class="'+highlight+'"><button class="btn btn-light btn-sm openBalance" data-assetId="'+data.transactions[i].from+'" data-epoch="'+data.epoch+'" type="button">'+data.transactions[i].from+'</button></td>';
html += '<td class="'+highlight+'"><button class="btn btn-light btn-sm openBalance" data-assetId="'+data.transactions[i].to+'" data-epoch="'+data.epoch+'" type="button">'+data.transactions[i].to+'</button></td>';
html += '<td class="text-end '+highlight+'">'+(data.transactions[i].co2eq/1000).toFixed(0).replace('.',',')+'eq</td>';
html += '<td class="text-end '+highlight+'">'+(data.transactions[i].energy/1000).toFixed(3).replace('.',',')+'kWh</td>';
html += '</tr>';
if(data.transactions[i].from == window.assetId) {
co2eq += data.transactions[i].co2eq;
energy += data.transactions[i].energy;
}
if(data.transactions[i].to == window.assetId) {
co2eq -= data.transactions[i].co2eq;
energy -= data.transactions[i].energy;
if(data.transactions[i].energy !== 0) {
html += '<tr>';
let highlight = '';
if(data.transactions[i].from == data.upstream) highlight='fw-bold';
if(data.transactions[i].to == data.upstream) highlight='fw-bold';
html += '<td class="'+highlight+'"><button class="btn btn-light btn-sm openBalance" data-assetId="'+data.transactions[i].from+'" data-epoch="'+data.epoch+'" type="button">'+data.transactions[i].from+'</button></td>';
html += '<td class="'+highlight+'"><button class="btn btn-light btn-sm openBalance" data-assetId="'+data.transactions[i].to+'" data-epoch="'+data.epoch+'" type="button">'+data.transactions[i].to+'</button></td>';
html += '<td class="text-end '+highlight+'">'+(data.transactions[i].co2eq/1000).toFixed(0).replace('.',',')+'eq</td>';
absenergy += Math.abs(data.transactions[i].energy);

if(data.transactions[i].from == window.assetId) {
co2eq += data.transactions[i].co2eq;
energy += data.transactions[i].energy;
}
if(data.transactions[i].to == window.assetId) {
co2eq -= data.transactions[i].co2eq;
energy -= data.transactions[i].energy;
}
html += '<td class="text-end '+highlight+'">'+(data.transactions[i].energy/1000).toFixed(3).replace('.',',')+'kWh</td>';
html += '<td class="text-end '+highlight+'">'+(energy/-1000).toFixed(3).replace('.',',')+'kWh</td>';
html += '</tr>';
}
}
html += '</tbody>';
html += '<tfoot>';
html += '<tr><th></th><th></th><th class="text-end">'+(co2eq/1000).toFixed(3).replace('.',',')+'eq</th><th class="text-end">'+(energy/1000).toFixed(3).replace('.',',')+'kWh</th></tr>';
html += '<tr><th></th><th></th><th class="text-end">'+(co2eq/1000).toFixed(0).replace('.',',')+'eq</th><th class="text-end">'+(data.energy/1000).toFixed(3).replace('.',',')+'kWh</th><th class="text-end">'+( (data.balancesum - data.energy) /1000).toFixed(3).replace('.',',')+'kWh</th></tr>';
html += '</tfoot>';
html += '</table>';
$('#txTable').html(html);
Expand Down Expand Up @@ -80,6 +86,7 @@ $(document).ready(function() {
html += '<th>Stromprodukt</th>';
html += '<th>Zeitfenster</th>';
html += '<th class="text-end">Treibhausgasemission</th>';
html += '<th class="text-end">Direktlieferung</th>';
html += '<th class="text-end">Saldo</th>';
html += '<th>Zertifikat</th>';
html += '</tr>';
Expand All @@ -96,7 +103,7 @@ $(document).ready(function() {
html += '<tr>';
let bgclass = '';
if(data[i].epoch == highlight) {
bgclass = 'bg-success';
bgclass = 'bg-secondary';
}
if(typeof data[i].seal == 'undefined') {
html += '<td class="'+bgclass+' text-center"><button class="btn btn-xs btn-light btnClear" data-epoch="'+data[i].epoch+'"><i class="fa fa-unlock-alt text-warning"></i></td>';
Expand All @@ -112,7 +119,10 @@ $(document).ready(function() {
}
chartDataCO2.push(Math.round(data[i].co2eq/1000));
chartDataEnergy.push(data[i].energy/1000);
if(typeof data[i].sum == 'undefined') { data[i].sum=0; }

html += '<td class="'+color+' text-end '+bgclass+' ">'+(data[i].co2eq/1000).toFixed(0).replace('.',',')+'eq</td>';
html += '<td class="'+color+' text-end '+bgclass+' ">'+(Math.abs((data[i].balancesum-data[i].energy))/1000).toFixed(3).replace('.',',')+'kWh</td>';
html += '<td class="'+color+' text-end '+bgclass+' ">'+(data[i].energy/1000).toFixed(3).replace('.',',')+'kWh</td>';
if(typeof data[i].seal == 'undefined') {
html += '<td class="'+bgclass+'">&nbsp;</td>';
Expand Down
2 changes: 1 addition & 1 deletion framework/public/devUI/uc_balancing.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h4 class="modal-title">Zertifikat</h4><button class="btn-close" type="button" a
<script src="assets/js/3party/qrcode.js?h=517b55d3688ce9ef1085a3d9632bcb97"></script>
<script src="assets/js/utils.js?h=b6a1e690b2a987d9af7e9692dff15273"></script>
<script src="assets/js/3party/marked.min.js?h=26085551a49dd1635b48b42f08c3d583"></script>
<script src="assets/js/uc_balancing.js?h=e4e74120e2a34b992e8745be07a4cdb4"></script>
<script src="assets/js/uc_balancing.js?h=33f43be161006fc68b4653a53469113b"></script>
<script src="assets/js/uc_contract.js?h=f3ad95a4c2133df734c874a6d3bbef70"></script>
</body>

Expand Down
2 changes: 1 addition & 1 deletion framework/services/balances_sealed_model.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
* Settings
*/
settings: {
fields: ["_id", "assetId", "epoch","in","out","energy","upstream","seal","transactions","co2eq","out_co2eq","in_co2eq","auditId"]
fields: ["_id", "assetId", "epoch","in","out","energy","upstream","seal","transactions","co2eq","out_co2eq","in_co2eq","auditId","balance","balancesum"]
},
/**
* Dependencies
Expand Down
15 changes: 14 additions & 1 deletion framework/services/balancing.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ module.exports = {

balance.upstream = await ctx.call("balancing.getUpstream", {assetId: ctx.params.assetId});

let absenergy = 0;
for(let i=0;i<settlements.length;i++) {
if(settlements[i].from == ctx.params.assetId) {
balance.out += settlements[i].energy * 1;
Expand All @@ -485,6 +486,14 @@ module.exports = {
balance.co2eq = balance.out_co2eq - balance.in_co2eq;
balance.transactions.push(settlements[i]);
}
if(balance.out > balance.in) {
absenergy += 1 * Math.abs(balance.out);
} else {
absenergy += 1 * Math.abs(balance.in);
}

balance.balancesum = absenergy;

const energybalance = balance.energy + balance.upstreamenergy;
const co2eqbalance = balance.co2eq + balance.upstreamco2eq;
balance.clearing = {
Expand Down Expand Up @@ -524,6 +533,8 @@ module.exports = {
}

let intermediateBalance = await ctx.call("balancing.unsealedBalance",ctx.params);
const _balance = intermediateBalance.balancesum;

if((intermediateBalance.energy !== 0)&&(intermediateBalance.clearing.energy !== 0)){
let statement = {
from: intermediateBalance.clearing.from,
Expand All @@ -540,6 +551,8 @@ module.exports = {
intermediateBalance.seal = true;
}
if((intermediateBalance.energy == 0)||(intermediateBalance.clearing.energy == 0)) {
intermediateBalance.balancesum = Math.round(intermediateBalance.balancesum/2);

const audit = await ctx.call("audit.requestApproval",intermediateBalance);
if( (audit).success ) {
intermediateBalance.auditId = audit.auditId;
Expand All @@ -548,7 +561,7 @@ module.exports = {
assetId: ctx.params.assetId,
epoch: ctx.params.epoch * 1,
upstream: intermediateBalance.upstream,
balance: intermediateBalance.in,
balancesum: _balance * 1,
energy: intermediateBalance.upstreamenergy,
co2eq: intermediateBalance.upstreamco2eq,
auditId: audit.auditId
Expand Down

0 comments on commit 93e52e5

Please sign in to comment.