Skip to content

Commit

Permalink
add dataConfig.isFullEntitySet
Browse files Browse the repository at this point in the history
  • Loading branch information
dab2000 committed Aug 3, 2022
1 parent 6da06a2 commit 6fafe71
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/core/dataConfig/dataConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ dataConfig.nonObservable = function(config, parent, id) {
parent,
id,
type: 'dataConfig',
isFullEntitySet(domain, entitySetValues = []) {
return this.spaceCatalog.then(sc => {
if (!sc[domain]) return false;

const distinctValues = [...new Set(entitySetValues)];
const resultNames = [];
const properties = sc[domain].properties;
let inSetValuesCount;
for (const property in properties) {
if (properties[property].concept.concept_type == "entity_set") {
inSetValuesCount = 0;
for (const entityValue of properties[property].entities.keys()) {
if (distinctValues.includes(entityValue)) inSetValuesCount++;
}
if (inSetValuesCount == properties[property].entities.size) resultNames.push(property);
}
}

return resultNames.length ? resultNames.sort() : false;
});
},
get allow() {
return observable({
config: this.config.allow,
Expand Down
74 changes: 73 additions & 1 deletion test/core/dataConfig/dataConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ describe('create stand alone data configs', () => {
expect(Object.keys(response)).toEqual(data.space)
});
})


})


Expand Down Expand Up @@ -315,4 +317,74 @@ describe('create marker with encoding dataconfigs', () => {
expect(response.get(0).x).toBe(1)
});
})
})
})


describe('test isFullEntitySet', () => {

const data = dataConfig({
source: {
path: 'test/ddf--jheeffer--mdtest',
modelType: 'ddf'
},
concept: 'population_total',
space: ['geo', 'time']
});


it('test isFullEntitySet("geo", ["usa"]) => false', async () => {
const sc = await check(data, 'spaceCatalog');

const result = await data.isFullEntitySet("geo", ["usa"]);

expect(result).toEqual(false);
});

it('test isFullEntitySet("geo", ["asia", "coastline"]) => false', async () => {
const sc = await check(data, 'spaceCatalog');

const result = await data.isFullEntitySet("geo", ["asia", "coastline"]);

expect(result).toEqual(false);
});

it('test isFullEntitySet("geo", ["landlocked", "coastline"]) => ["landlocked"]', async () => {
const sc = await check(data, 'spaceCatalog');

const result = await data.isFullEntitySet("geo", ["landlocked", "coastline"]);

expect(result).toEqual(["landlocked"]);
});

it('test isFullEntitySet("geo", ["europe", "americas", "africa", "asia"]) => ["world_4region"]', async () => {
const sc = await check(data, 'spaceCatalog');

const result = await data.isFullEntitySet("geo", ["europe", "americas", "africa", "asia"]);

expect(result).toEqual(["world_4region"]);
});

it('test isFullEntitySet("geo", ["europe", "americas", "africa", "asia", "landlocked"]) => ["world_4region"]', async () => {
const sc = await check(data, 'spaceCatalog');

const result = await data.isFullEntitySet("geo", ["europe", "americas", "africa", "asia", "landlocked"]);

expect(result).toEqual(["world_4region"]);
});

it('test isFullEntitySet("geo", ["europe", "americas", "africa", "asia", "landlocked", "coastline"]) => ["world_4region", "landlocked"]', async () => {
const sc = await check(data, 'spaceCatalog');

const result = await data.isFullEntitySet("geo", ["europe", "americas", "africa", "asia", "landlocked", "coastline"]);

expect(result).toEqual(["landlocked", "world_4region"]);
});

it('test isFullEntitySet("geo", ["europe", "americas", "africa", "asia", "landlocked", "coastline", "usa"]) => ["world_4region", "landlocked"]', async () => {
const sc = await check(data, 'spaceCatalog');

const result = await data.isFullEntitySet("geo", ["europe", "americas", "africa", "asia", "landlocked", "coastline", "usa"]);

expect(result).toEqual(["landlocked", "world_4region"]);
});
})

0 comments on commit 6fafe71

Please sign in to comment.