Skip to content

Commit 2353b74

Browse files
author
Tom Pearson
authored
Adjusted value return (#19)
* improve return object from adjustValue
1 parent 43977e8 commit 2353b74

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ __allowOverwrite__, optional. By default this is set to true ensuring that all c
7474

7575

7676
### indexCore.__adjustValue(_entityName:String_, _indicatorID:String_, _value:Number_)__
77-
A function that allows the user to adjust an entity's (_entityName_) indicator (_indicatorID_) score to a specified _value_. Calculated values for that entity are re-calculated using the new value. If the function is called without _value_ the indicator is reset to it's inital value. If the function is called without _indicatorId_ or _value_ all indicators on the entity are reset to their initial values.
77+
A function that allows the user to adjust an entity's (_entityName_) indicator (_indicatorID_) score to a specified _value_. Calculated values for that entity are re-calculated using the new value. If the function is called without _value_ the indicator is reset to it's inital value. If the function is called without _indicatorId_ or _value_ all indicators on the entity are reset to their initial values. As a convenience the function returns an object with all the recalculated values.
7878

7979
_NOTE: whislt the old value is retained there's currently no way to reset it._
8080

index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ const inclusiveInternetEntities = csvParse(fs.readFileSync(`${inclusiveIternetRo
1717
const inclusiveInternetIndex = indexCore(inclusiveInternetIndicators, inclusiveInternetEntities);
1818

1919

20-
console.log('value', inclusiveInternetIndex.indexedData['Singapore']['value'])
21-
console.log('1', inclusiveInternetIndex.indexedData['Singapore']['1'])
22-
console.log('1.2', inclusiveInternetIndex.indexedData['Singapore']['1.2'])
23-
console.log('1.2.1', inclusiveInternetIndex.getEntityIndicator('Singapore','1.2.1'))
24-
25-
inclusiveInternetIndex.adjustValue('Singapore','1.2.1',50);
26-
27-
console.log('adjusted')
28-
console.log('value', inclusiveInternetIndex.indexedData['Singapore']['value'])
29-
console.log('1', inclusiveInternetIndex.indexedData['Singapore']['1'])
30-
console.log('1.2', inclusiveInternetIndex.indexedData['Singapore']['1.2'])
31-
console.log('1.2.1', inclusiveInternetIndex.getEntityIndicator('Singapore','1.2.1'))
20+
// console.log('value', inclusiveInternetIndex.indexedData['Singapore']['value'])
21+
// console.log('1', inclusiveInternetIndex.indexedData['Singapore']['1'])
22+
// console.log('1.2', inclusiveInternetIndex.indexedData['Singapore']['1.2'])
23+
// console.log('1.2.1', inclusiveInternetIndex.getEntityIndicator('Singapore','1.2.1'))
24+
25+
console.log(inclusiveInternetIndex.adjustValue('Singapore','1.2.1',50));
26+
27+
// console.log('adjusted')
28+
// console.log('value', inclusiveInternetIndex.indexedData['Singapore']['value'])
29+
// console.log('1', inclusiveInternetIndex.indexedData['Singapore']['1'])
30+
// console.log('1.2', inclusiveInternetIndex.indexedData['Singapore']['1.2'])
31+
// console.log('1.2.1', inclusiveInternetIndex.getEntityIndicator('Singapore','1.2.1'))
3232

3333
// const simpleRootDir = 'data/simple-index-set';
3434

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@economist/index-core",
3-
"version": "1.5.0",
3+
"version": "1.5.2",
44
"description": "",
55
"main": "src/index-core.js",
66
"type": "module",

src/index-core.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ function indexCore(indicatorsData = [], entitiesData = [], indexMax = 100, allow
155155
const calculationList = getCalculationList(onlyIdIndicators);
156156

157157
indexedData[e.name] = indexEntity(e, calculationList, true);
158-
return indexedData[e.name];
158+
// console.log(indexedData[e.name])
159+
const adjustedEntity = Object.assign(clone(indexedData[e.name]),indexedData[e.name].user)
160+
delete adjustedEntity.user;
161+
delete adjustedEntity.data;
162+
return adjustedEntity;
159163
}
160164

161165
function createStructure(indicatorIds) {

test/index-core.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,12 @@ test('get the user set value for an indicator', ()=>{
8484
const simpleIndex = indexCore(simpleIndicators, simpleEntities);
8585
simpleIndex.adjustValue('Monopoly', '1.2', 3.142);
8686
expect(simpleIndex.getEntityIndicator('Monopoly','1.2')).toBe(3.142);
87+
})
88+
89+
test('check the return value from adjustValue', ()=>{
90+
const simpleIndex = indexCore(simpleIndicators, simpleEntities);
91+
const adjustedObject = simpleIndex.adjustValue('Monopoly', '1.2', 3.142);
92+
expect(adjustedObject['1.2']).toBe(3.142);
93+
expect(adjustedObject['user']).toBe(undefined);
94+
expect(adjustedObject['data']).toBe(undefined);
8795
})

0 commit comments

Comments
 (0)