Skip to content

Instantly share code, notes, and snippets.

@gitabites
Last active December 27, 2015 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitabites/7240798 to your computer and use it in GitHub Desktop.
Save gitabites/7240798 to your computer and use it in GitHub Desktop.
Reclassification queries, updated 11/21/13 with weekly/biweekly options
#number of reclassifications, cumulative
skimToMain = db.recategorization.find({"recategorizedTo": "main"}).count()
print "Number of messages recategorized to main, cummulative:" + str(skimToMain)
mainToSkim = db.recategorization.find({"recategorizedTo": "skim"}).count()
print "Number of messages recategorized to skim, cummulative:" + str(maintoSkim)
#Weekly reclassifications
from datetime import date, timedelta
today = date.today()
lastWeek = today - timedelta(days=7)
lastWeekMinusOne = lastWeek - timedelta(days=1)
twoWeeksAgo = today - timedelta(days=14)
yesterday = date.today() - timedelta(1)
print today, yesterday, lastWeek, twoWeeksAgo
mainRecatLastWeek = db.recategorization.find({"date":{"$gt": str(lastweek), "$lt": str(today)}, "recategorizedTo": "main"}).count()
print "Number of messages recategorized to main " + str(lastWeek) + " - " + str(yesterday) + " : " + str(skimRecatLastWeek)
mainRecatTwoWeeks = db.recategorization.find({"date":{"$gt": str(twoWeeksAgo), "$lt": str(lastWeek)}, "recategorizedTo": "main"}).count()
print "Number of messages recategorized to main " + str(twoWeeksAgo) + " - " + str(lastWeekMinusOne) + " : " + str(skimRecatTwoWeeks)
skimRecatLastWeek = db.recategorization.find({"date":{"$gt": str(lastweek), "$lt": str(today)}, "recategorizedTo": "skim"}).count()
print "Number of messages recategorized to skim " + str(lastWeek) + " - " + str(yesterday) + " : " + str(skimRecatLastWeek)
skimRecatTwoWeeks = db.recategorization.find({"date":{"$gt": str(twoWeeksAgo), "$lt": str(lastWeek)}, "recategorizedTo": "skim"}).count()
print "Number of messages recategorized to skim " + str(twoWeeksAgo) + " - " + str(lastWeekMinusOne) + " : " + str(skimRecatTwoWeeks)
#Percentage of messages moved from skim to main and main/skim /all received messages
totalRecat = skimToMain + mainToSkim #total reclassified
sentMessages = list(db.folders.find({'type':'Sent'}, {'_id':1})) #get all sent messages first
receivedMessages = list(db.emails.find({"_id": {"$nin": sentMessages}})) #find all emails where the _id isn't in sentFolders
receivedMessages = len(receivedMessages)
percentSkimToMain = (float(skimToMain) / float(receivedMessages)) * 100
print "Percent messages reclassified as skim/all messages received:" + str(percentSkimToMain)
percentMainToSkim = (float(mainToSkim) / float(messagesReceived)) * 100
print "Percent messages reclassified as main/all messages received:" + str(percentMainToSkim)
#total reclassified / all messages
percentTotalRecat = (float(totalRecat) / float(messagesReceived)) * 100
print "Percent total messages reclassified/all messages received:" + str(percentTotalRecat)
@wihl
Copy link

wihl commented Nov 20, 2013

here's how to do this without editing the file every week:

from datetime import date, timedelta

today = date.today()
lastweek = today - timedelta(days=7)
twoweeksago = today - timedelta(days=14)

print today, lastweek, twoweeksago

#Weekly reclassifications
mainRecatLastWeek = db.recategorization.find({"date":{ $gt: str(lastweek)}, "date":{$lt:str(today)}},
                                "recategorizedTo": "main"}).count()
#print "Number of messages recategorized to main 11/16/2013 - 11/22/2013:" + mainRecatWeek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment