Last active
August 29, 2015 14:26
-
-
Save Ray901/df092770c0dabc40430f to your computer and use it in GitHub Desktop.
load mongo exam104
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
rm(list=ls()) | |
library(mongolite) | |
setAWSPath <- "ec2-54-238-68-224.ap-northeast-1.compute.amazonaws.com" | |
setDate <- c("") | |
m<-mongo(db = "ehanlin_104", | |
collection = "ExamAnswer", | |
url = paste0("mongodb://",setAWSPath) | |
) | |
ExamAnswer <- m$find( | |
query = paste0( | |
'{ | |
"user":"551dda78e4b0a230f3585f24", | |
"finished":true, | |
"enabled":true | |
}' | |
) | |
) | |
ExamAnswer <- m$aggregate(paste0( | |
'[ | |
{"$match" : {"end":{"$gt":{"$date":"',as.character(setDate[1]),"T15:59:59.000Z",'"},"$lte":{"$date":"',as.character(setDate[2]),"T15:59:59.000Z",'"}}}}, | |
{"$match": {"type":"UNIT"} }, | |
{"$match": {"finished":true} }, | |
{"$match": {"enabled":true} }, | |
{ | |
"$group":{ | |
"_id":{ | |
"user":"$user", | |
"subject":"$subject", | |
"volume":"$volume" | |
}, | |
"answerNum":{"$sum":"$answerNum"}, | |
"contentNum":{"$sum":"$contentNum"}, | |
"correctAnswerNum":{"$sum":"$correctAnswerNum"}, | |
"correctContentNum":{"$sum":"$correctContentNum"}, | |
"incorrectAnswerNum":{"$sum":"$incorrectAnswerNum"}, | |
"incorrectContentNum":{"$sum":"$incorrectContentNum"} | |
} | |
} | |
]' | |
)) | |
m<-mongo(db = "ehanlin_104", | |
collection = "UserQuestion", | |
url = paste0("mongodb://",setAWSPath) | |
) | |
UserQuestion <- m$aggregate(paste0( | |
'[ | |
{"$match" : {"lastUpdate":{"$gt":{"$date":"',as.character(setDate[1]),"T15:59:59.000Z",'"},"$lte":{"$date":"',as.character(setDate[2]),"T15:59:59.000Z",'"}}}}, | |
{ | |
"$group":{ | |
"_id":{ | |
"user":"$user", | |
"subject":"$subject", | |
"volume":"$volume" | |
}, | |
"answerNum":{"$sum":"$answerNum"}, | |
"reviewedNum":{"$sum":{"$cond":[{"$eq":["$reviewed",true]},1,0]}}, | |
"reviewedAndRightNum":{"$sum":{"$cond":[ { "$and": [ { "$eq": [ "$reviewed", true ] }, { "$eq": [ "$corrected", true ] } ] } ,1,0]}}, | |
"correctedNum":{"$sum":{"$cond":[{"$eq":["$corrected",true]},1,0]}}, | |
"staredNum":{"$sum":{"$cond":[{"$eq":["$stared",true]},1,0]}} | |
} | |
} | |
]' | |
)) | |
m<-mongo(db = setdb_exam104, | |
collection = "UserVideo", | |
url = paste0("mongodb://",setExamhost) | |
) | |
UserVideo <- m$aggregate(paste0( | |
'[ | |
{"$match": {"seen":true} }, | |
{ | |
"$group":{ | |
"_id":{ | |
"user":"$user", | |
"subject":"$subject", | |
"volume":"$volume" | |
}, | |
"videoCount":{"$sum":1} | |
} | |
} | |
]' | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment