-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data point): data point validation skeleton
Closes #26
- Loading branch information
Showing
13 changed files
with
233 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const registry = require('./registry'); | ||
const Issue = require('./issue'); | ||
const LINE_NUM_INCLUDING_HEADER = 2; | ||
|
||
module.exports = { | ||
[registry.DATA_POINT_VALUE_NOT_NUMERIC]: (ddfData, dataPointDetail) => { | ||
const result = []; | ||
|
||
dataPointDetail.fileDescriptor.details.measures.forEach(measure => { | ||
ddfData.getDataPoint().content.forEach((dataPointRecord, line) => { | ||
if (isNaN(dataPointRecord[measure]) === true) { | ||
result.push( | ||
new Issue( | ||
registry.DATA_POINT_VALUE_NOT_NUMERIC, | ||
dataPointDetail.fileDescriptor.fullPath, | ||
{ | ||
measure, | ||
line: line + LINE_NUM_INCLUDING_HEADER, | ||
value: dataPointRecord[measure] | ||
}) | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
return result; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
const chai = require('chai'); | ||
const sinonChai = require('sinon-chai'); | ||
const DdfData = require('../lib/ddf-definitions/ddf-data'); | ||
const rulesRegistry = require('../lib/ddf-rules/registry'); | ||
const dataPointsRules = require('../lib/ddf-rules/data-point-rules'); | ||
const expect = chai.expect; | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('rules for data points', () => { | ||
let ddfData = null; | ||
|
||
describe('when "DATA_POINT_VALUE_NOT_NUMERIC" rule', () => { | ||
afterEach(done => { | ||
ddfData.dismiss(() => { | ||
done(); | ||
}); | ||
}); | ||
|
||
it('any issue should NOT be found for folder without the problem (fixtures/good-folder)', done => { | ||
ddfData = new DdfData('./test/fixtures/good-folder'); | ||
ddfData.load(() => { | ||
const dataPointValueNotNumRule = dataPointsRules[rulesRegistry.DATA_POINT_VALUE_NOT_NUMERIC]; | ||
const expectedDataPointDetail = ddfData.getDataPoint().details[0]; | ||
|
||
ddfData.getDataPoint().loadDetail(expectedDataPointDetail, () => { | ||
expect(dataPointValueNotNumRule(ddfData, expectedDataPointDetail).length).to.equal(0); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it(`an issue should be found for folder with the problem | ||
(fixtures/rules-cases/data-point-value-not-num)`, done => { | ||
ddfData = new DdfData('./test/fixtures/rules-cases/data-point-value-not-num'); | ||
ddfData.load(() => { | ||
const dataPointValueNotNumRule = dataPointsRules[rulesRegistry.DATA_POINT_VALUE_NOT_NUMERIC]; | ||
const expectedDataPointDetail = ddfData.getDataPoint().details[0]; | ||
const expectedFileName = 'ddf--datapoints--pop--by--country--year.csv'; | ||
const expectedMeasure = 'pop'; | ||
const expectedLine = 2; | ||
const expectedValue = 'huge'; | ||
|
||
ddfData.getDataPoint().loadDetail(expectedDataPointDetail, () => { | ||
const issues = dataPointValueNotNumRule(ddfData, expectedDataPointDetail); | ||
|
||
expect(issues.length).to.equal(1); | ||
expect(issues[0].type).to.equal(rulesRegistry.DATA_POINT_VALUE_NOT_NUMERIC); | ||
expect(issues[0].path.endsWith(expectedFileName)).to.be.true; | ||
expect(!!issues[0].data).to.be.true; | ||
expect(issues[0].data.measure).to.equal(expectedMeasure); | ||
expect(issues[0].data.line).to.equal(expectedLine); | ||
expect(issues[0].data.value).to.equal(expectedValue); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
2 changes: 2 additions & 0 deletions
2
test/fixtures/good-folder/ddf--datapoints--pop--by--country--year.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
country,year,pop | ||
usa,1960,100000 |
3 changes: 3 additions & 0 deletions
3
test/fixtures/rules-cases/data-point-value-not-num/ddf--concepts--measures.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
concept,type,domain,name | ||
lat,measure,,Latitude | ||
lng,measure,,Longitude |
7 changes: 7 additions & 0 deletions
7
test/fixtures/rules-cases/data-point-value-not-num/ddf--concepts.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
concept,type,domain,name | ||
name,string,, | ||
geo,entity domain,, | ||
region,entity set,geo,Region | ||
country,entity set,geoCountry | ||
capital,entity set,geo,Capital | ||
pop,measure,geo,Population |
2 changes: 2 additions & 0 deletions
2
...fixtures/rules-cases/data-point-value-not-num/ddf--datapoints--pop--by--country--year.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
country,year,pop | ||
usa,1960,huge |
9 changes: 9 additions & 0 deletions
9
test/fixtures/rules-cases/data-point-value-not-num/ddf--entities--geo--country.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
geo,name,lat,lng,is--region,is--country,is--capital | ||
and,Andorra,,,0,1,0 | ||
afg,Afghanistan,,,0,1,0 | ||
dza,Algeria,,,0,1,0 | ||
africa,Africa,,,1,0,0 | ||
europe,Europe,,,1,0,0 | ||
americas,Americas,,,1,0,0 | ||
asia,Asia,,,1,0,0 | ||
vat,Vatican,,,0,1,1 |