Skip to content

Commit

Permalink
refactor: Balancing rules refactored to have more clearer statements/…
Browse files Browse the repository at this point in the history
…transaction in case of peer 2 peer trading of energy.
  • Loading branch information
zoernert committed Feb 10, 2024
1 parent 8449030 commit ab11bb3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
7 changes: 7 additions & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [0.6.12](https://github.com/energychain/ZSG_DynamischeStromtarife/compare/v0.6.11...v0.6.12) (2024-02-07)


### Bug Fixes

* Usage of empty query in find operation should act same for in-memory and mongoDB. ([8449030](https://github.com/energychain/ZSG_DynamischeStromtarife/commit/8449030e3f4abb41d5c49bfe0265e060cc41cad0))

## [0.6.11](https://github.com/energychain/ZSG_DynamischeStromtarife/compare/v0.6.10...v0.6.11) (2024-02-07)


Expand Down
4 changes: 2 additions & 2 deletions framework/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion framework/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stromdao-eaf",
"version": "0.6.11",
"version": "0.6.12",
"description": "STROMDAO Energy Application Framework - Referenzimplementierung für dynamische Stromtarife",
"scripts": {
"dev": "node ./run-eaf",
Expand Down
7 changes: 6 additions & 1 deletion framework/services/balancing.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,12 @@ module.exports = {
co2eq: intermediateBalance.clearing.co2eq,
label: ".end"
}
if(statement.energy < 0) {
const tmp_to = statement.to;
statement.to = statement.from;
statement.from = tmp_to;
statement.energy *= -1;
}
await ctx.call("balance_settlements_active_model.insert",{entity:statement});
intermediateBalance = await ctx.call("balancing.unsealedBalance",ctx.params); // Hier könnte man die MOL danach abrufen
// Fix who is upstream
Expand All @@ -623,7 +629,6 @@ module.exports = {
}
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 Down
1 change: 1 addition & 0 deletions framework/services/contract.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
* @return {Array} the result of the function
*/
async handler(ctx) {
console.log("*********** Process",ctx.params);
let findContract = await ctx.call("contract_model.find",{query:{contractId:ctx.params.contractId}});
if(findContract.length == 1) {
findContract[0].balanced += 1 * ctx.params.energy;
Expand Down
13 changes: 10 additions & 3 deletions framework/services/meritorder.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module.exports = {
let counterTransaction = {

}

if(
(energy_in > 0) &&
(mol[i].direction == "from")
Expand Down Expand Up @@ -162,9 +162,16 @@ module.exports = {
"contractId": mol[i].contractId
}
}
if((energy_out >0) &&
if(energy_in < 0) {
energy_out = Math.abs(energy_in);
}
energy_out = Math.abs(energy_out);

if((Math.abs(energy_out) >0) &&
(mol[i].direction == "to")
) {

// Da energy_out < 0 ist, wird dies hier fehlerhaft!
if(energy_out > mol[i].load_max) {
energy_out = mol[i].load_max;
}
Expand Down Expand Up @@ -195,7 +202,6 @@ module.exports = {
"contractId": mol[i].contractId
}
}

ctx.params.transactions.push(transaction);
ctx.params.transactions.push(counterTransaction);

Expand Down Expand Up @@ -226,6 +232,7 @@ module.exports = {
mol = mol[0].mol; // We only allow 1 mol per balancing point

for(let i=0;i<ctx.params.transactions.length;i++) {

// Identify relevant transactions and change balanced of contract
if(ctx.params.transactions[i].accounting == 'mol') {
ctx.params.transactions[i].assetId = ctx.params.assetId;
Expand Down

0 comments on commit ab11bb3

Please sign in to comment.