MongoDB MapReduce Standard Deviation over date range -
MongoDB MapReduce Standard Deviation over date range -
good afternoon so, wonder if help me. investigating using mongodb aggregation framework , mapreduce functions.
my dataset looks this
[{ "name" : "person 1", "runningspeed" : [{ "date" : isodate("2005-07-23t23:00:00.000z"), "value" : 10 }, { "date" : isodate("2006-07-23t23:00:00.000z"), "value" : 20 }, { "date" : isodate("2007-07-23t23:00:00.000z"), "value" : 30 }, { "date" : isodate("2008-07-23t23:00:00.000z"), "value" : 40 } ] }, { "name" : "person 2", "runningspeed" : [{ "date" : isodate("2005-07-23t23:00:00.000z"), "value" : 5 }, { "date" : isodate("2006-07-23t23:00:00.000z"), "value" : 10 }, { "date" : isodate("2007-07-23t23:00:00.000z"), "value" : 20 }, { "date" : isodate("2008-07-23t23:00:00.000z"), "value" : 40 } ] }, { "name" : "person 3", "runningspeed" : [{ "date" : isodate("2005-07-23t23:00:00.000z"), "value" : 20 }, { "date" : isodate("2006-07-23t23:00:00.000z"), "value" : 10 }, { "date" : isodate("2007-07-23t23:00:00.000z"), "value" : 30 }, { "date" : isodate("2008-07-23t23:00:00.000z"), "value" : 25 } ] } ]
i have done lot of research , see there no out of box back upwards doing sd calculations. have reviewed few links , posts , came url https://gist.github.com/redbeard0531/1886960, seems looking for.
so plenty background generate chart of sds on each year.
the current function not take inconsideration each year value whole. have changed map function , have no thought set grouping date function.
function map() { emit(1, // or set grouping key here {sum: this.runningspeed.value, // field want stats min: this.runningspeed.value, max: this.runningspeed.value, count:1, diff: 0, // m2,n: sum((val-mean)^2) }); }
however zero's. help me adapt function?
you need utilize getfullyear() , foreach loop through each runningspeed entry:
function map() { this.runningspeed.foreach(function(data){ var year = data.date.getfullyear(); emit(year, // or set grouping key here, grouping key date.getfullyear() {sum: data.value, // field want stats min: data.value, max: data.value, count: 1, diff: 0, // m2,n: sum((val-mean)^2) }); }); } mongodb mapreduce aggregation-framework
Comments
Post a Comment