'fill tools_and_job_state_per_month.mako template with
- the name of the tool
- the number of jobs using this tool in state \'ok\'
- the number of jobs using this tool in error'

@web.expose
def tools_and_job_state_per_month(self, trans, **kwd):

    message = escape(util.restore_text(kwd.get('message', '')))
    user_cutoff = int(kwd.get('user_cutoff', 60))
    tool = kwd.get('tool', None)
    if (tool is None):
        raise TypeError("Tool    can't    be    None")
    data = collections.OrderedDict()
    date_and_jobs_ok = sa.select((sa.func.date(galaxy.model.Job.table.c.create_time).label('date'), sa.func.count(galaxy.model.Job.table.c.id).label('job')), from_obj=[galaxy.model.Job.table], whereclause=and_((galaxy.model.Job.table.c.state == 'ok'), (galaxy.model.Job.table.c.tool_id == tool)), group_by=['date'])
    date_and_jobs_error = sa.select((sa.func.date(galaxy.model.Job.table.c.create_time).label('date'), sa.func.count(galaxy.model.Job.table.c.id).label('job')), from_obj=[galaxy.model.Job.table], whereclause=and_((galaxy.model.Job.table.c.state == 'error'), (galaxy.model.Job.table.c.tool_id == tool)), group_by=['date'])
    date_and_jobs_ok = dict(list(date_and_jobs_ok.execute()))
    date_and_jobs_error = dict(list(date_and_jobs_error.execute()))
    dates = list((set(date_and_jobs_ok.keys()) | set(date_and_jobs_error.keys())))
    dates.sort(reverse=True)
    for date in dates:
        date_key = date.strftime('%B    %Y')
        if (date_key not in data):
            data[date_key] = [int(date_and_jobs_ok.get(date, 0)), int(date_and_jobs_error.get(date, 0))]
        else:
            data[date_key][0] += int(date_and_jobs_ok.get(date, 0))
            data[date_key][1] += int(date_and_jobs_error.get(date, 0))
    return trans.fill_template('/webapps/reports/tools_and_job_state_per_month.mako', data=data, tool=tool, user_cutoff=user_cutoff, message=message)
