Last active
August 29, 2015 14:08
-
-
Save Ray901/71e6aad3d7329b529498 to your computer and use it in GitHub Desktop.
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
from pymongo import Connection | |
import datetime | |
setPath="ec2-54-248-156-148.ap-northeast-1.compute.amazonaws.com" | |
setDBS="ehanlin_103_jhs_db" | |
conn=Connection(setPath,27017) | |
db = conn[setDBS] | |
pipe = [ | |
{"$match" : {"date":{"$gt":datetime.datetime(2014,10,21,23,59,59),"$lte":datetime.datetime(2014,10,22,23,59,59)}}}, | |
{ | |
"$group" : { | |
"_id":{ | |
"user":"$user", | |
"year":{"$year":"$date"}, | |
"month":{"$month":"$date"}, | |
"day":{"$dayOfMonth":"$date"}, | |
"subject":"$subject", | |
"volume":"$volume" | |
}, | |
"examCount":{"$sum":{"$cond":[{"$gte":["$exam",1]},"$exam",0]}}, | |
"doCount":{"$sum":{"$cond":[{"$gte":["$exam",1]},"$total",0]}}, | |
"rightCount":{"$sum":{"$cond":[{"$gte":["$exam",1]},"$right",0]}}, | |
"slipRight":{"$sum":{"$cond":[{"$eq":["$type","slip"]},"$right",0]}}, | |
"videoCount":{"$sum":{"$cond":[{"$eq":["$type","video"]},"$total",0]}}, | |
"progressVideoCount":{"$sum":{"$cond":[{"$eq":["$type","progressVideo"]},"$total",0]}}, | |
"animationCount":{"$sum":{"$cond":[{"$eq":["$type","animation"]},"$total",0]}}, | |
"labVideoCount":{"$sum":{"$cond":[{"$eq":["$type","labVideo"]},"$total",0]}} | |
} | |
}, | |
{"$sort" : {"doCount" : 1}} | |
] | |
result=db.HourlyUnitCounters.aggregate(pipeline=pipe) | |
for doc in result['result']: | |
print(doc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment