Skip to content

Instantly share code, notes, and snippets.

@Ray901
Last active August 29, 2015 14:26
Show Gist options
  • Save Ray901/df092770c0dabc40430f to your computer and use it in GitHub Desktop.
Save Ray901/df092770c0dabc40430f to your computer and use it in GitHub Desktop.
load mongo exam104
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