[Blends-commit] r3010 - /blends/trunk/team_analysis_tools/upload_history.py
tille at users.alioth.debian.org
tille at users.alioth.debian.org
Tue Nov 1 17:17:29 UTC 2011
Author: tille
Date: Tue Nov 1 17:17:29 2011
New Revision: 3010
URL: http://svn.debian.org/wsvn/blends/?sc=1&rev=3010
Log:
Adapted to PG 9.1
Modified:
blends/trunk/team_analysis_tools/upload_history.py
Modified: blends/trunk/team_analysis_tools/upload_history.py
URL: http://svn.debian.org/wsvn/blends/blends/trunk/team_analysis_tools/upload_history.py?rev=3010&op=diff
==============================================================================
--- blends/trunk/team_analysis_tools/upload_history.py (original)
+++ blends/trunk/team_analysis_tools/upload_history.py Tue Nov 1 17:17:29 2011
@@ -2,8 +2,10 @@
# Copyright 2011: Andreas Tille <tille at debian.org>
# License: GPL
-# MAXUPLOADERS=20
-MAXUPLOADERS=10
+# PLOTUPLOADERS=20
+PLOTUPLOADERS=10
+
+MAXUPLOADERS=1000
teams = {
'debian-med' : 'debian-med-packaging at lists.alioth.debian.org' ,
@@ -40,6 +42,7 @@
try:
conn = psycopg2.connect(host="localhost",port=PORT,user="guest",database="udd")
+ conn.set_session(autocommit) # make sure it is possible to continue after a query error
except psycopg2.OperationalError:
try:
conn = psycopg2.connect(host="localhost",port=DEFAULTPORT,user="guest",database="udd")
@@ -75,17 +78,21 @@
return result
for team in teams.keys():
+ # print team
datafile='uploaders_'+team+'.txt'
out = open(datafile, 'w')
- query = "SELECT replace(uploader,' ','_') AS uploader FROM active_uploader_names_of_pkggroup('%s', 1000) AS (uploader text);" % (teams[team])
+ query = "SELECT replace(uploader,' ','_') AS uploader FROM active_uploader_names_of_pkggroup('%s', %i) AS (uploader text);" % (teams[team], MAXUPLOADERS)
# print query
curs.execute(query)
+ nuploaders = curs.rowcount
+ if nuploaders == 0:
+ print >>stderr, "No uploaders found for team %s" % team
+ continue
+
print >>out, ' year',
- nuploaders = 0
for row in curs.fetchall():
print >>out, '\t' + re.sub('^(.*_\w)[^_]*$', '\\1', row[0]),
- nuploaders += 1
print >>out, ''
typestring = 'year text'
@@ -98,19 +105,38 @@
FROM active_uploader_per_year_of_pkggroup(''%s'', %i) AS (name text, year int, count int)',
'SELECT * FROM active_uploader_names_of_pkggroup(''%s'', %i) AS (category text)'
) As (%s)
-""" % (teams[team], nuploaders, teams[team], nuploaders, typestring)
+""" % (teams[team], nuploaders, teams[team], MAXUPLOADERS, typestring)
try:
# print query
curs.execute(query)
except psycopg2.ProgrammingError, err:
if crosstab_missing_re.match(str(err)):
- print >>stderr, """Please do
- psql udd < /usr/share/postgresql/<pgversion>/contrib/tablefunc.sql
-before calling this program."""
+# print >>stderr, """Please do
+# psql udd < /usr/share/postgresql/<pgversion>/contrib/tablefunc.sql
+#before calling this program."""
+ print >>stderr, "Please do `psql udd -c 'CREATE EXTENSION tablefunc;'` before calling this program.\n", err, query, nuploaders
+ exit(-1)
else:
- print >>stderr, "To few uploaders in %s team.\n%s" % (team, err)
- exit(-1)
+ m = re.match(".*\n.*Query-specified return tuple has (\d+) columns but crosstab returns (\d+).*", str(err))
+ nuploaders_calculated = int(m.group(1))
+ nuploaders_returned = int(m.group(2))
+ # somehow the crosstable returns less columns
+ print >>stderr, "Warning: team %s should have %d uploaders but crosstable returned only %d. Try again with this number." % (team, nuploaders_calculated, nuploaders_returned)
+ typestring = 'year text'
+ for i in range(nuploaders_returned - 1):
+ typestring = typestring + ', upl' + str(i+1) + ' int'
+ query = """SELECT *
+ FROM
+ crosstab(
+ 'SELECT year AS row_name, name AS bucket, count AS value
+ FROM active_uploader_per_year_of_pkggroup(''%s'', %i) AS (name text, year int, count int)',
+ 'SELECT * FROM active_uploader_names_of_pkggroup(''%s'', %i) AS (category text)'
+ ) As (%s)
+""" % (teams[team], nuploaders, teams[team], nuploaders, typestring)
+ # print query
+ conn.rollback()
+ curs.execute(query)
for row in curs.fetchall():
print >>out, ' ' + row[0] ,
for v in row[1:]:
@@ -120,7 +146,7 @@
print >>out, '\t0',
print >>out, ''
out.close()
- cmdstring='./author_stats_create_graph ' + datafile + ' ' + str(min(nuploaders, MAXUPLOADERS))
+ cmdstring='./author_stats_create_graph ' + datafile + ' ' + str(min(nuploaders, PLOTUPLOADERS))
if len(argv) > 1 :
if argv[1].startswith('pdf'):
cmdstring = cmdstring + ' "" pdf'
More information about the Blends-commit
mailing list