Created
November 17, 2015 03:33
-
-
Save ronfe/f473fcbea97ae3da4cd2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# _*_ coding: utf8 _*_ | |
from pymongo import MongoClient | |
from bson.objectid import ObjectId | |
import datetime | |
# link to db | |
dbClient = MongoClient('mongodb://localhost:27017') | |
db = dbClient['yangcong-prod25'] | |
# open collections | |
points = db['points'] | |
users = db['users'] | |
rooms = db['rooms'] | |
# configure daterange | |
lastWeekStartDate = datetime.datetime(2015,11,01) | |
lastWeekEndDate = lastWeekStartDate + datetime.timedelta(days = 7) | |
startDate = datetime.datetime(2015,11,8) | |
endDate = startDate + datetime.timedelta(days = 7) | |
print("2015-11-8 ~ 2015-11-14") | |
print("") | |
print("###### Part.3 周活跃 ######") | |
def calPcWork(startDate, endDate): | |
pipeLine = [ | |
{"$match": { | |
"createdBy": { | |
"$gte": startDate, | |
"$lt": endDate | |
}, | |
"from": "pc" | |
}}, | |
{ | |
"$group": { | |
"_id": "$user" | |
} | |
} | |
] | |
return list(points.aggregate(pipeLine)) | |
pcActUsers = calPcWork(startDate, endDate) | |
pcActUsersArray = [] | |
for x in pcActUsers: | |
pcActUsersArray.append(x['_id']) | |
# print("PC本周活动用户:") | |
# print(len(pcActUsersArray)) | |
def isUsers(startDate, endDate): | |
pipeLine = [ | |
{"$match": { | |
"usefulData.registDate": { | |
"$gte": startDate, | |
"$lt": endDate | |
}, | |
"usefulData.from": "signup" | |
}}, | |
{"$group": { | |
"_id": "$_id" | |
}} | |
] | |
return list(users.aggregate(pipeLine)) | |
def isAllUsers(): | |
pipeLine = [ | |
{"$group": { | |
"_id": None, | |
"users": {"$push": "$_id"} | |
}} | |
] | |
return list(users.aggregate(pipeLine))[0]['users'] | |
regUsers = isAllUsers() | |
# print("PC本周注册用户") | |
# print(len(regUsersArray)) | |
pcOutArray = [] | |
pcOutArray = list(set.intersection(set(regUsers), set(pcActUsersArray))) | |
print("PC周活跃统计") | |
print(len(pcOutArray)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment