#!/usr/bin/python
# Copyright 2007-2008  Canonical, Ltd
# Author: Brian Murray <brian@ubuntu.com>
# License: GPLv2
# ---------------------------------------
# Reads data from the -changes csv file and presents it in a readable fashion
# Something similar should be used to write it to html

import csv
import sys

sourcepackage = sys.argv[1]
sourcepackagechanges = sys.argv[1] + '/' + sys.argv[1] + '-changes.csv' 

reader = csv.reader(open('%s' % sourcepackagechanges, "rb"))
# name: column - base 0
statinfo = {
    'total': { 'title':'Total', 'column':1 },
    'new': { 'title':'New', 'column':2 },
    'incomplete': { 'title':'Incomplete', 'column':3 },
    'confirmed': { 'title':'Confirmed', 'column':4 },
    'triaged': { 'title':'Triaged', 'column':5 },
    'inprogress': { 'title':'In Progress', 'column':6 },
    'fixcommitted': { 'title':'Fix Committed', 'column':7 },
    'fixreleased': { 'title':'Fix Released', 'column':8 },
    'invalid': { 'title':'Invalid', 'column':9 },
    'wontfix': { 'title':'''Won't Fix''', 'column':10 },
#    'undecided': { 'title':'Undecided', 'column':12 },
#    'wishlist': { 'title':'Wishlist', 'column':13 },
#    'low': { 'title':'Low', 'column':14 },
#    'medium': { 'title':'Medium', 'column':15 },
#    'high': { 'title':'High', 'column':16 },
#    'critical': { 'title':'Critical', 'column':17 },
            }

statuses = [ 'total', 'new', 'incomplete', 'confirmed', 'triaged', 'inprogress', 'fixcommitted', 'fixreleased', 'invalid', 'wontfix' ]
# length of time in days: number of rows from end where -1 is the last row
periods = { 1: '-25',
            7: '-169',
            30: '-721'
          }

for row in reader:
    #if row[0].startswith('1'):
    #    for status in statuses: 
    #        column = statinfo[status]['column']
    #        print 'In the past day: %s:%s' % (statinfo[status]['title'], row[column])
    #if row[0].startswith('7'):
    #    for status in statuses:
    #        column = statinfo[status]['column']
    #        print 'In the past seven days: %s:%s' % (statinfo[status]['title'], row[column])
    if row[0].startswith('30'):
        for status in statuses:
            column = statinfo[status]['column']
            print '%s In the past thirty days: %s:%s' % (sourcepackage, statinfo[status]['title'], row[column])
