#!/usr/bin/env python
# Copyright 2007 Kees Cook <kees@ubuntu.com>
# License: GPLv2

print '''
set xdata time
set timefmt "%s"
set xtics rotate by 90
set xlabel "Date/Time" 0,-1

set ylabel "Number of Bugs"

set term png small size 400,300
set grid
set key top left
'''

statinfo = {
    'open': { 'title':'Open', 'column':2 },
    'critical': { 'title':'Critical', 'column':3 },
    'unconfirmed': { 'title':'New', 'column':4 },
    'unassigned': { 'title':'Unassigned', 'column':5 },
    'ever-reported': { 'title':'All Bugs Ever Assigned', 'column':6 },
    }

days = {
    'fullyear': { 'step': 350, 'span': 3600*24*365, 'format': '%b %Y' },
    'halfyear': { 'step': 350, 'span': 3600*24*180, 'format': '%b %Y' },
    'month': { 'step': 24, 'span': 3600*24*30, 'format': '%d %b' },
    'week': { 'step': 6, 'span': 3600*24*7, 'format': '%d %b' },
    '1day': { 'step': 1, 'span': 3600*24, 'format': '%m/%d %H:%M' },
    }

now = int(open('bugstats.data').read().splitlines().pop().split(",")[0])

for day in days.keys():
    xmin = now - days[day]['span']
    for stat in statinfo.keys():
        print '''
set format x "%s"
set output "plots/%s-%s.png"
plot ["%d":] "bugstats.data" using 1:%d every %d title "%s" with linespoints
''' % (days[day]['format'], day, stat, xmin, statinfo[stat]['column'], days[day]['step'], statinfo[stat]['title'])
