Last active
November 17, 2015 03:30
-
-
Save diggzhang/c766aa919a6c28b8b63e 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
# _*_ 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 = [ | |
{"$match": { | |
"usefulData.from": "signup" | |
}}, | |
{"$group": { | |
"_id": "$_id" | |
}} | |
] | |
return list(users.aggregate(pipeLine)) | |
regUsers = isAllUsers() | |
regUsersArray = [] | |
for x in regUsers: | |
regUsersArray.append(x['_id']) | |
# print("PC本周注册用户") | |
# print(len(regUsersArray)) | |
pcOutArray = [] | |
pcOutArray = list(set.intersection(set(regUsersArray), 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