From d913798d5b3c6a416a0a8857f4a6103f2155b6dd Mon Sep 17 00:00:00 2001 From: David Hudson Date: Sun, 18 Sep 2016 22:52:41 +0900 Subject: [PATCH 1/5] [Timeline] Add battery starting state-of-charge Issue #1185 --- platform/features/timeline/bundle.js | 10 ++++++++++ .../timeline/src/capabilities/GraphCapability.js | 2 +- .../timeline/test/capabilities/GraphCapabilitySpec.js | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/platform/features/timeline/bundle.js b/platform/features/timeline/bundle.js index 12effc50a3..145a496f08 100644 --- a/platform/features/timeline/bundle.js +++ b/platform/features/timeline/bundle.js @@ -182,6 +182,16 @@ define([ "capacity" ], "pattern": "^-?\\d+(\\.\\d*)?$" + }, + { + "name": "Battery Starting SOC", + "control": "textfield", + "required": false, + "conversion": "number", + "property": [ + "startingSOC" + ], + "pattern": "^-?\\d+(\\.\\d*)?$" } ], "model": { diff --git a/platform/features/timeline/src/capabilities/GraphCapability.js b/platform/features/timeline/src/capabilities/GraphCapability.js index d9810005a3..c4e5166f0e 100644 --- a/platform/features/timeline/src/capabilities/GraphCapability.js +++ b/platform/features/timeline/src/capabilities/GraphCapability.js @@ -60,7 +60,7 @@ define( result.power, 0, domainObject.getModel().capacity, // Watts - domainObject.getModel().capacity, + domainObject.getModel().startingSOC, 1 / 3600000 // millis-to-hour (since units are watt-hours) ); } diff --git a/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js b/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js index 71a6de2ade..e36724dbcb 100644 --- a/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js +++ b/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js @@ -101,6 +101,7 @@ define( it("provides a battery graph for timelines with capacity", function () { var mockCallback = jasmine.createSpy('callback'); testModel.capacity = 1000; + testModel.startingSOC = 1000; testModel.type = "timeline"; mockDomainObject.useCapability.andReturn(asPromise([ { key: "power", start: 0, end: 15 } From 943e2ebe14fc076904ca2eb2832c08f8197efc1e Mon Sep 17 00:00:00 2001 From: David Hudson Date: Tue, 20 Sep 2016 17:40:08 +0900 Subject: [PATCH 2/5] [Timeline] Convert SOC to use percentages Also includes updated validation params which allow for floats to a maximum of 100 as well as a percentage sign which is later removed. --- platform/features/timeline/bundle.js | 4 ++-- .../features/timeline/src/capabilities/GraphCapability.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/platform/features/timeline/bundle.js b/platform/features/timeline/bundle.js index 145a496f08..42b3c948f9 100644 --- a/platform/features/timeline/bundle.js +++ b/platform/features/timeline/bundle.js @@ -184,14 +184,14 @@ define([ "pattern": "^-?\\d+(\\.\\d*)?$" }, { - "name": "Battery Starting SOC", + "name": "Battery starting SOC (%)", "control": "textfield", "required": false, "conversion": "number", "property": [ "startingSOC" ], - "pattern": "^-?\\d+(\\.\\d*)?$" + "pattern": "^([0-9](\\.\\d*)?|[1-9][0-9](\\.\\d*)?|100)%?$" } ], "model": { diff --git a/platform/features/timeline/src/capabilities/GraphCapability.js b/platform/features/timeline/src/capabilities/GraphCapability.js index c4e5166f0e..86095b13ab 100644 --- a/platform/features/timeline/src/capabilities/GraphCapability.js +++ b/platform/features/timeline/src/capabilities/GraphCapability.js @@ -55,12 +55,14 @@ define( if (domainObject.getModel().type === 'timeline' && result.power && domainObject.getModel().capacity > 0) { + domainObject.getModel().startingSOC = + parseFloat(domainObject.getModel().startingSOC) || 100; result.battery = new CumulativeGraph( result.power, 0, domainObject.getModel().capacity, // Watts - domainObject.getModel().startingSOC, + (domainObject.getModel().startingSOC/100)*domainObject.getModel().capacity, 1 / 3600000 // millis-to-hour (since units are watt-hours) ); } From f1852541141857aafbb97b6bc02d168ede8067ee Mon Sep 17 00:00:00 2001 From: David Hudson Date: Tue, 20 Sep 2016 17:41:45 +0900 Subject: [PATCH 3/5] [Formatting] Fix missing spaces --- platform/features/timeline/src/capabilities/GraphCapability.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/features/timeline/src/capabilities/GraphCapability.js b/platform/features/timeline/src/capabilities/GraphCapability.js index 86095b13ab..4e9cce0c8c 100644 --- a/platform/features/timeline/src/capabilities/GraphCapability.js +++ b/platform/features/timeline/src/capabilities/GraphCapability.js @@ -62,7 +62,7 @@ define( result.power, 0, domainObject.getModel().capacity, // Watts - (domainObject.getModel().startingSOC/100)*domainObject.getModel().capacity, + (domainObject.getModel().startingSOC / 100) * domainObject.getModel().capacity, 1 / 3600000 // millis-to-hour (since units are watt-hours) ); } From 3d17435438c0d1c5e8c7647a0218b7e0718adc79 Mon Sep 17 00:00:00 2001 From: David Hudson Date: Tue, 20 Sep 2016 17:42:34 +0900 Subject: [PATCH 4/5] [Test] Update spec to use SOC percentage --- .../features/timeline/test/capabilities/GraphCapabilitySpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js b/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js index e36724dbcb..e2ccd376e2 100644 --- a/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js +++ b/platform/features/timeline/test/capabilities/GraphCapabilitySpec.js @@ -101,7 +101,7 @@ define( it("provides a battery graph for timelines with capacity", function () { var mockCallback = jasmine.createSpy('callback'); testModel.capacity = 1000; - testModel.startingSOC = 1000; + testModel.startingSOC = 100; testModel.type = "timeline"; mockDomainObject.useCapability.andReturn(asPromise([ { key: "power", start: 0, end: 15 } From e077f9ee1845e1a551084e0239a65209ad395cae Mon Sep 17 00:00:00 2001 From: David Hudson Date: Fri, 30 Sep 2016 21:34:03 +0200 Subject: [PATCH 5/5] [Timeline] Fix logic error Issue #1185. Also removed direct modification of domain object. --- .../timeline/src/capabilities/GraphCapability.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/platform/features/timeline/src/capabilities/GraphCapability.js b/platform/features/timeline/src/capabilities/GraphCapability.js index 4e9cce0c8c..181c909f79 100644 --- a/platform/features/timeline/src/capabilities/GraphCapability.js +++ b/platform/features/timeline/src/capabilities/GraphCapability.js @@ -37,7 +37,8 @@ define( // Build graphs for this group of utilizations function buildGraphs(utilizations) { var utilizationMap = {}, - result = {}; + result = {}, + startingSOC; // Bucket utilizations by type utilizations.forEach(function (u) { @@ -55,14 +56,14 @@ define( if (domainObject.getModel().type === 'timeline' && result.power && domainObject.getModel().capacity > 0) { - domainObject.getModel().startingSOC = - parseFloat(domainObject.getModel().startingSOC) || 100; + startingSOC = isNaN(parseFloat(domainObject.getModel().startingSOC)) ? + 100 : parseFloat(domainObject.getModel().startingSOC); result.battery = new CumulativeGraph( result.power, 0, domainObject.getModel().capacity, // Watts - (domainObject.getModel().startingSOC / 100) * domainObject.getModel().capacity, + (startingSOC / 100) * domainObject.getModel().capacity, 1 / 3600000 // millis-to-hour (since units are watt-hours) ); }