Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get statistics on the health of plone mailing lists
#! /bin/python
import urllib2
import csv
import datetime
import math
class GmaneListStats(object):
def __init__(self, what_is_recent=30, group='gmane.comp.web.zope.plone.devel'):
@what_is_recent: how many days to keep in recent tally
""" = {}
# last what_is_recent days activity
self.days = 0
self.recent = what_is_recent
stats_url = '' % group
fp = urllib2.urlopen(stats_url)
stats =
for row in csv.reader(stats.split("\n")[1:], delimiter=' '):
if len(row) < 3:
date = row[0]
messages = int(row[1])
self.addDate(datetime.datetime.strptime(date, '%Y%m%d'), messages)
def addDate(self, date, count):
Add a date to the collection of data. date is
expected to be a datetime argument. this is un-granularizing
the data a bit
if date.year not in[date.year] = [0,0,0,0,0,0,0,0,0,0,0,0]
year =[date.year]
year[date.month-1] += count
today =
if (today - date).days <= self.recent:
self.days += count
def getTotal(self):
total = 0
for year, months in
total += sum(months)
return total
def getYearlyAverage(self):
return self.getTotal()/len(
def getYearlySummary(self):
return [ (year, self.getMonthlyAverage(year)) for year in sorted( ]
def getMonthlyAverage(self, year=None):
if not year:
year =
year_total = sum([year])
num_months = 12.0
# skip months that haven't occured yet
today =
if today.year == year:
num_months = (today.month - 1.0) + float( # approx
return math.ceil(float(year_total)/num_months)
def getCurrentHealth(self):
return self.days/self.recent
def getMonthlyStats(self, months=4):
today =
total = 0
num = 0
years = sorted(, reverse=True)
for year in years:
# go through months in reverse
for month in reversed([year]):
if month == 0: # hasn't occured yet
total += month
num += 1
if num == months:
# crunch
average = float(total)/float(months)
return {'average': average,
'stddev': 0,
def isTrollRequired(self, months=4):
A troll is required if the activity in the last troll period months
In theory this should be a standard deviation but for now I'll go with 30%
troll_level = self.getMonthlyStats(months)['average']/30.0 * .7
return self.getCurrentHealth() < troll_level
def report_out(group='gmane.comp.web.zope.plone.devel'):
stats = GmaneListStats(group=group)
print "+++++++++++++++++"
print group
print "+++++++++++++++++"
print "Average Yearly: ", stats.getYearlyAverage()
print "All Years"
for (year, num) in stats.getYearlySummary():
print "%s\t%s" % (year, num)
print "2012 Monthly Average: ", stats.getMonthlyAverage()
print "Current Health: ", stats.getCurrentHealth()
print "Stats", stats.getMonthlyStats()
print "Troll Required?", stats.isTrollRequired() and "YES!" or "All clear"
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.