Created
October 27, 2012 21:10
-
-
Save iros/3966277 to your computer and use it in GitHub Desktop.
Dataset 0.3 Release
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
var data = [ | |
{ age : 23, weight : 140, height : 65 }, | |
{ age : 40, weight : 290, height : 72 }, | |
{ age : 13, weight : 110, height : 60 } | |
]; | |
var healthData = new Miso.Dataset({ | |
data: data | |
}); | |
healthData.fetch().then(function() { | |
// Let's add a BMI Column | |
healthData.addComputedColumn("BMI", "number", function(row) { | |
return [row.weight / Math.pow(row.height, 2)] * 703; | |
}); | |
console.log(healthData.column("BMI").data); | |
// => [23.294674556213018, 39.326774691358025, 21.480555555555554] | |
// If we add a row: | |
healthData.add({ | |
age : 30, | |
weight : 180, | |
height: 68 | |
}); | |
// the computed column will add the correct value at the | |
// correct place: | |
console.log(healthData.column("BMI").data); | |
// => [23.294674556213018, 39.326774691358025, 21.480555555555554, 27.3659169550173] | |
// if we update a row: | |
var firstRow = healthData.rowByPosition(0); | |
healthData.update({ | |
_id : firstRow._id, | |
weight: 120 | |
}); | |
// Our computed column will recompute the appropriate | |
// cell: | |
console.log(healthData.column("BMI").data); | |
// => [19.966863905325443, 39.326774691358025, 21.480555555555554, 27.3659169550173] | |
}); | |
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
var data = [ | |
{ userId : 1, age : 23, weight : 140, height : 65 }, | |
{ userId : 2, age : 40, weight : 290, height : 72 }, | |
{ userId : 3, age : 13, weight : 110, height : 60 } | |
]; | |
var healthData = new Miso.Dataset({ | |
data: data, | |
idAttribute : 'userId' | |
}); | |
healthData.fetch().then(function() { | |
// Will return our first row | |
// => {"userId":1,"age":23,"weight":140,"height":65} | |
console.log(JSON.Stringify(healthData.rowById(1))); | |
}); |
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
var data = [ | |
{ userId : 1, age : 23, weight : 140, height : 65 }, | |
{ userId : 2, age : 40, weight : 290, height : 72 }, | |
{ userId : 3, age : 13, weight : 110, height : 60 } | |
]; | |
var healthData = new Miso.Dataset({ | |
data : data, | |
idAttribute : 'userId' | |
}); | |
healthData.fetch().then(function() { | |
// let's update a single record: | |
healthData.update({ | |
userId : 1, | |
age : 24 | |
}); | |
// The age is now 24: | |
// => {"userId":1,"age":24,"weight":140,"height":65} | |
console.log(JSON.stringify(healthData.rowById(1))); | |
// let's update two records | |
healthData.update([ | |
{ userId : 1, age : 25, weight : 140, height : 65 }, | |
{ userId : 2, age : 42, weight : 140, height : 65 } | |
]); | |
// Our age column should now look like this: | |
// => [25, 42, 13] | |
console.log(healthData.column("age").data); | |
// Let's update all the ages at once | |
healthData.update(function(row) { | |
row.age += 2; | |
return row; | |
}); | |
// Our age column should now look like this: | |
// => [25, 42, 15] | |
console.log(healthData.column("age").data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment