X-Git-Url: https://piware.de/gitweb/?a=blobdiff_plain;f=workitems.py;h=fa40e47764b0800d579b0f252df41171a2e1d27c;hb=440cd71f9afa01857159a5881b513aa7694b8354;hp=928c941b1e0f969f5761527f2657690fef720b5b;hpb=a133fc8d32cd892bd5ef58eb42af7d86f18eeddc;p=bin.git diff --git a/workitems.py b/workitems.py index 928c941..fa40e47 100755 --- a/workitems.py +++ b/workitems.py @@ -23,9 +23,9 @@ def get_db(dbpath): workitem VARCHAR(255) NOT NULL, status VARCHAR(20) NOT NULL, date TIMESTAMP NOT NULL)''') - cur.execute('''CREATE TABLE statuses ( + cur.execute('''CREATE TABLE status ( blueprint VARCHAR(255) NOT NULL, - status VARCHAR(20) NOT NULL, + status VARCHAR(1000) NOT NULL, date TIMESTAMP NOT NULL)''') db.commit() @@ -88,7 +88,7 @@ def get_blueprints(url, name_pattern): def get_blueprint_workitems(blueprint_url): '''Collect work items from a particular blueprint URL. - This will return a list of ('item', 'state') pairs. + This will return a list of ('item', 'status') pairs. ''' work_items_re = re.compile('(
|^)work items:\s*
', re.I)
@@ -169,7 +169,7 @@ def get_moin_workitems(url):
Every line starting with "|| " is treated as a work item.
- Return a list of ('item', 'state') pairs.
+ Return a list of ('item', 'status') pairs.
'''
result = []
for line in urllib.urlopen(url):
@@ -193,22 +193,32 @@ def dump(db):
'''Dump database contents.'''
cur = db.cursor()
- cur.execute('SELECT w.*, s.status FROM work_items w LEFT JOIN statuses s on w.blueprint = s.blueprint')
- for (blueprint, workitem, status, date) in cur:
- print '%s [%s]\t%s: %s' % (date, blueprint, workitem, status)
+ cur.execute('SELECT * FROM work_items')
+ print '== Work items: =='
+ for (blueprint, workitem, item_status, date) in cur:
+ print '%s [%s]\t%s: %s' % (date, blueprint, workitem, item_status)
+
+ print '\n== Status =='
+ cur = db.cursor()
+ cur.execute('SELECT * FROM status')
+ for (blueprint, status, date) in cur:
+ print '%s: %s [%s]' % (blueprint, status, date)
-def add_work_item(db, blueprint, item, state):
+def add_work_item(db, blueprint, item, status):
'''Add work item to database.'''
cur = db.cursor()
cur.execute('INSERT INTO work_items VALUES (?, ?, ?, date(CURRENT_TIMESTAMP))',
- (blueprint, item, state))
+ (blueprint, item, status))
def add_status(db, blueprint, status):
'''Add blueprint status to database.'''
+ if not status:
+ return
+
cur = db.cursor()
- cur.execute('INSERT INTO statuses VALUES (?, ?, date(CURRENT_TIMESTAMP))',
+ cur.execute('INSERT INTO status VALUES (?, ?, date(CURRENT_TIMESTAMP))',
(blueprint, status))
def import_lp(db, name_pattern, release):
@@ -219,7 +229,7 @@ def import_lp(db, name_pattern, release):
cur = db.cursor()
cur.execute('DELETE FROM work_items WHERE date = date(CURRENT_TIMESTAMP)')
- cur.execute('DELETE FROM statuses WHERE date = date(CURRENT_TIMESTAMP)')
+ cur.execute('DELETE FROM status WHERE date = date(CURRENT_TIMESTAMP)')
for bp in blueprints:
#print 'Checking', bp
@@ -228,8 +238,6 @@ def import_lp(db, name_pattern, release):
status = get_blueprint_status(bp)
if not work_items:
print >> sys.stderr, 'WARNING: %s has no work items' % bpname
- if not status:
- print >> sys.stderr, 'WARNING: %s has no status' % bpname
for (item, state) in work_items:
add_work_item(db, bpname, item, state)
add_status(db, bpname, status)
@@ -248,10 +256,10 @@ def workitems_over_time(db):
data.setdefault(date, {})[s] = num
return data
-def blueprint_stats(db):
- '''Determine current blueprint stats.
+def blueprint_completion(db):
+ '''Determine current blueprint completion.
- Return blueprint -> [todo, done, postponed] mapping.
+ Return blueprint -> [todo, done, postponed, status] mapping.
'''
data = {}
@@ -264,18 +272,18 @@ def blueprint_stats(db):
for s in valid_states:
cur = db.cursor()
cur.execute('SELECT w.blueprint, count(w.workitem), s.status FROM work_items w '
- 'LEFT JOIN statuses s ON w.blueprint = s.blueprint '
+ 'LEFT JOIN status s ON w.blueprint = s.blueprint '
'WHERE w.status = ? AND w.date = ? GROUP BY w.blueprint',
(s, last_date))
for (bp, num, status) in cur:
- data.setdefault(bp, [0, 0, 0, ""])[index] = num
- data[bp][-1] = status
+ data.setdefault(bp, [0, 0, 0, ''])[index] = num
+ data[bp][-1] = status or ''
index += 1
return data
def text(db):
- '''Print work item stats as text.'''
+ '''Print work item completion as text.'''
data = workitems_over_time(db)
@@ -283,8 +291,8 @@ def text(db):
for d in sorted(data.keys()):
print d, data[d]
- print '\nBlueprint stats:'
- data = blueprint_stats(db)
+ print '\nBlueprint completion:'
+ data = blueprint_completion(db)
for (bp, (todo, done, postponed, status)) in data.iteritems():
# TODO print status
print '%s: %i/%i (%i%%)' % (bp, postponed+done, todo+done+postponed,
@@ -349,7 +357,7 @@ def html(db):