Add new dimension: solar_consumption, which is a percentage calculated from load.
Chris committed
Jan 28, 2018 at 15:27 UTC
b2ed2dc802cf9fd153d1449b0f57af53b05fd5e0
3 files changed
+37
-2
node.d/fronius.node.js
+10
-1
@@ -24,6 +24,7 @@ var fronius = {
24
consumptionLoadId: "p_load",
25
autonomyId: "rel_autonomy",
26
consumptionSelfId: "rel_selfconsumption",
27
+ solarConsumptionId: "solar_consumption",
28
energyTodayId: "e_day",
29
energyYearId: "e_year",
30
@@ -101,6 +102,7 @@ var fronius = {
102
var dim = {};
103
dim[fronius.autonomyId] = this.createBasicDimension(fronius.autonomyId, "autonomy", 1);
104
dim[fronius.consumptionSelfId] = this.createBasicDimension(fronius.consumptionSelfId, "self_consumption", 1);
105
+ dim[fronius.solarConsumptionId] = this.createBasicDimension(fronius.solarConsumptionId, "solar_consumption", 1);
106
107
chart = {
108
id: id, // the unique id of the chart
@@ -255,10 +257,17 @@ var fronius = {
257
258
parseAutonomyChart: function (service, site) {
259
var selfConsumption = site.rel_SelfConsumption;
260
+ var solarConsumption = 0;
261
+ var load = Math.abs(site.P_Load);
262
+ var power= Math.max(site.P_PV, 0);
263
+ if (load >= power) solarConsumption = 100;
264
+ else if (power <= 0) solarConsumption = 0;
265
+ else solarConsumption = 100 / power * load;
266
return this.getChart(this.getSiteAutonomyChart(service, "autonomy"),
267
[
268
this.getDimension(this.autonomyId, Math.round(site.rel_Autonomy)),
261
- this.getDimension(this.consumptionSelfId, Math.round(selfConsumption === null ? 100 : selfConsumption))
269
+ this.getDimension(this.consumptionSelfId, Math.round(selfConsumption === null ? 100 : selfConsumption)),
270
+ this.getDimension(this.solarConsumptionId, Math.round(solarConsumption))
271
]
272
);
273
},
tests/node.d/fronius.chart.spec.js
+1
-1
@@ -68,7 +68,7 @@ describe("fronius chart creation", function () {
68
expect(result.type).toBe(netdata.chartTypes.area);
69
expect(result.family).toBe("autonomy");
70
expect(result.context).toBe("fronius.autonomy");
71
- expect(Object.keys(result.dimensions).length).toBe(2);
71
+ expect(Object.keys(result.dimensions).length).toBe(3);
72
expect(result.dimensions[subject.autonomyId].name).toBe("autonomy");
73
expect(result.dimensions[subject.consumptionSelfId].name).toBe("self_consumption");
74
});
tests/node.d/fronius.parse.spec.js
+26
@@ -234,6 +234,32 @@ describe("fronius parsing for autonomy", function () {
234
expect(result.name).toBe(subject.consumptionSelfId);
235
expect(result.value).toBe(0);
236
});
237
+
238
+ it("should return 0 for solarConsumption if PV is null", function () {
239
+ site.P_PV = null;
240
+ var result = subject.parseAutonomyChart(service, site).dimensions[2];
241
+
242
+ expect(result.name).toBe(subject.solarConsumptionId);
243
+ expect(result.value).toBe(0);
244
+ });
245
+
246
+ it("should return 100 for solarConsumption if Load is higher than solar power", function () {
247
+ site.P_PV = 500;
248
+ site.P_Load = -1500;
249
+ var result = subject.parseAutonomyChart(service, site).dimensions[2];
250
+
251
+ expect(result.name).toBe(subject.solarConsumptionId);
252
+ expect(result.value).toBe(100);
253
+ });
254
+
255
+ it("should return 50 for solarConsumption if Load is half than solar power", function () {
256
+ site.P_PV = 3000;
257
+ site.P_Load = -1500;
258
+ var result = subject.parseAutonomyChart(service, site).dimensions[2];
259
+
260
+ expect(result.name).toBe(subject.solarConsumptionId);
261
+ expect(result.value).toBe(50);
262
+ });
263
});
264
265
describe("fronius parsing for energy", function () {