Hi All,
I'm interesting in returning some average values from mongodb/pymongo, using aggregate and a custom javascript function, as:
db.system.js.save(
{
'_id': 'ts_secs',
value: function( _ts ){
var d = new Date( _ts );
var s = d.getHours()*3600;
s += d.getMinutes()*60;
s += d.getSeconds();
return s;
}
}
);
match={'HOST_ID':{'$in':sids},
'BEGIN_TS':{'$gte':begin_ts,'$lt':end_ts},
'CONSTNT_CD':user,
'HANGUP_IND':{'$ne':1}};
group={'_id':'id',
'avg_total_events':{'$avg':'$TOTAL_EVENTS'},
'avg_elapsed_secs':{'$avg':db.system_js.ts_secs('$END_TS')-db.system_js.ts_secs('$BEGIN_TS')}};
pipe = [
{'$match':match},
{'$group':group}
];
call_avgs=db.calls.aggregate(pipeline=pipe);
result:[{u'avg_total_events': 19.520588105629766, u'avg_elapsed_secs': nan, u'_id': u'id'}] # function arguments are ISODate type, e.g. ISODate("2013-07-23T12:11:56Z"), value returned is nan.
If this approach isn't supported, would I be better off using map/reduce, and/or maybe something like python/numpy?
Let me know what you think - thanks
John