From 873388eb4bd7a3e78152940bdf20ed4fc3877f0e Mon Sep 17 00:00:00 2001 From: Thorsten Zoerner Date: Fri, 19 Jan 2024 02:11:59 +0100 Subject: [PATCH] Patch: Added methods to be used via REST API to build UIs with more comfort (sealedBalance, balance and unsealedBalance) --- .../services/balances_sealed_model.service.js | 3 +- framework/services/balancing.service.js | 179 ++++++++++++------ 2 files changed, 118 insertions(+), 64 deletions(-) diff --git a/framework/services/balances_sealed_model.service.js b/framework/services/balances_sealed_model.service.js index 39bc32e..3dac455 100644 --- a/framework/services/balances_sealed_model.service.js +++ b/framework/services/balances_sealed_model.service.js @@ -24,9 +24,8 @@ module.exports = { * Settings */ settings: { - fields: ["_id", "assetId", "epoch","label","seal"] + fields: ["_id", "assetId", "epoch","in","out","energy","upstream","seal"] }, - /** * Dependencies */ diff --git a/framework/services/balancing.service.js b/framework/services/balancing.service.js index 50ec4a4..9b31de7 100644 --- a/framework/services/balancing.service.js +++ b/framework/services/balancing.service.js @@ -25,6 +25,7 @@ // * `statement_model`: The statement model "use strict"; +const ROOT_BALANCE_GROUP = "eaf_generic_balancegroup"; // Create a new Moleculer service module.exports = { @@ -33,51 +34,6 @@ module.exports = { // Define the actions of the service actions: { // Action to add a settlement from a meter to the energy balancing model - balance: { - rest: { - method: "GET", - path: "/balance" - }, - params: { - assetId: "string", - }, - async handler(ctx) { - const EPOCH_DURATION = process.env.EPOCH_DURATION; - if((typeof ctx.params.epoch == 'undefined')||(ctx.params.epoch == null)) { - ctx.params.epoch = Math.floor(new Date().getTime() / EPOCH_DURATION); - } else { - ctx.params.epoch = 1 * ctx.params.epoch; - } - - let res = await ctx.call("balancing_model.find",{ - query:{ - assetId: ctx.params.assetId, - epoch: {$lte: ctx.params.epoch * 1 } - }, - limit: 24, - sort: "-epoch" - }); - let cleaned = {}; - for(let i=0;i