Python 映射时间戳上的Reduce
Mongodb数据库:Python 映射时间戳上的Reduce,python,mongodb,Python,Mongodb,Mongodb数据库: {"thread": "abc", "message": "hjhjh", "Date": (2010,4,5,0,0,0)} {"thread": "abc", "message": "hjhjh", "Date": (2009,3,5,0,0,0)} {"thread": "efg", "message": "hjhjh", "Date": (2010,3,7,0,0,0)} {"thread": "efg", "message": "hjhjh", "Date
{"thread": "abc", "message": "hjhjh", "Date": (2010,4,5,0,0,0)}
{"thread": "abc", "message": "hjhjh", "Date": (2009,3,5,0,0,0)}
{"thread": "efg", "message": "hjhjh", "Date": (2010,3,7,0,0,0)}
{"thread": "efg", "message": "hjhjh", "Date": (2011,4,5,0,0,0)}
我如何映射或聚合上述数据以生成以下输出:
{"thread": "abc", "messages_per_month": 5}
{"thread": "efg", "messages_per_month": 4}
我正在尝试编写一些代码,但很难对未排序的日期进行平均。是否有任何内置函数可以按时间平均执行此操作?您可以按数字所述的日期执行min/max,只需为消息添加一个计数器即可。结果将是一个包含消息数和最小/最大日期的线程列表。从日期开始,您可以计算月数,然后使用月数计算邮件数的平均值