return data
+def assignee_completion(db):
+ '''Determine current by-assignee completion.
+
+ Return assignee -> [todo, done, postponed] mapping.
+ '''
+ data = {}
+
+ # last date
+ cur = db.cursor()
+ cur.execute('SELECT max(date) FROM work_items')
+ (last_date,) = cur.fetchone()
+
+ index = 0
+ for s in valid_states:
+ cur = db.cursor()
+ cur.execute('SELECT assignee, count(workitem) FROM work_items '
+ 'WHERE date=? and status=? GROUP BY assignee',
+ (last_date, s))
+ for (a, num) in cur:
+ data.setdefault(a, [0, 0, 0])[index] = num
+ index += 1
+
+ return data
+
def text(db):
'''Print work item completion as text.'''
print '</table>'
+ print '''
+<h1>Status by assignee</h1>
+<table>
+ <tr><th>Assignee</th> <th>todo/postponed/done</th> <th>Completion</th></tr>
+'''
+ data = assignee_completion(db)
+
+ completion = []
+ for (a, (todo, done, postponed)) in data.iteritems():
+ completion.append((a,
+ int(float(postponed+done)/(todo+done+postponed)*100 + 0.5)))
+
+ completion.sort(key=lambda k: k[0], reverse=False)
+
+ for (a, percent) in completion:
+ url = '%s/~%s/+specs?role=assignee' % (blueprints_base_url, a)
+ print ' <tr><td><a href="%s">%s</a></td> <td>%i/%i/%i</td> <td>%i%%</td></tr>' % (
+ url, a, data[a][0], data[a][2],
+ data[a][1], percent)
+ print '</table>'
+
print '</body></html>'
def import_moin(db, urls):