var countries = new Data.Collection(countries_data);
console.log('oh sweet, just made a collection:');
console.log(countries_data);
var population = countries.properties().get('population');
console.log('get returns a Data.Property: ');
console.log(population);
console.log('which supports aggregation: ');
var population_sum = population.aggregate(Data.Aggregators.SUM) // => Returns total population of all countries in the collection.
console.log(population_sum);
equals(population_sum, 310955497 + 82062200 + 8356700 + 82062200, 'We can aggregate a column');
This test fails, I think because Data.Property.aggregate is defined:
aggregate: function (fn) {
return fn(this.values("values"));
},
this.values produces a hash where each key is the value considered, so in this case it has three rather than 4 values do to the repeated value.
If you have a repeated value in a Data.Collection, the aggregation produces incorrect values:
Test data, note we have two german countries with the same population:
var countries_data = { "properties": { "name": {"name": "Country Name", "type": "string", "unique": true }, "official_language": {"name": "Official Language", "type": "string", "unique": false }, "population": { "name": "Population", "type": "number", "unique": false } }, "items": { 0: { "name": "Austria", "official_language": "German", "population": 8356700, },
}
var countries = new Data.Collection(countries_data); console.log('oh sweet, just made a collection:'); console.log(countries_data);
var population = countries.properties().get('population'); console.log('get returns a Data.Property: '); console.log(population);
console.log('which supports aggregation: '); var population_sum = population.aggregate(Data.Aggregators.SUM) // => Returns total population of all countries in the collection. console.log(population_sum);
equals(population_sum, 310955497 + 82062200 + 8356700 + 82062200, 'We can aggregate a column');
This test fails, I think because Data.Property.aggregate is defined:
this.values produces a hash where each key is the value considered, so in this case it has three rather than 4 values do to the repeated value.