'Fill the template tool_execution_time_per_month.mako with informations:
- Tool average execution time
- last job execution time
- min and max execution time'

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

    user_cutoff = int(kwd.get('user_cutoff', 60))
    sort_by = kwd.get('sort_by', 'month')
    descending = (1 if (kwd.get('descending', 'desc') == 'desc') else (-1))
    sort_by = (0 if (sort_by == 'month') else (1 if (sort_by == 'min') else (2 if (sort_by == 'max') else 3)))
    tool = kwd.get('tool', None)
    color = (True if (kwd.get('color', '') == 'True') else False)
    if (tool is None):
        raise ValueError("Tool    can't    be    None")
    ordered_data = collections.OrderedDict()
    sort_functions = [(lambda first, second, i=i: (descending if (first[i] < second[i]) else (- descending))) for i in range(4)]
    jobs_times = sa.select((sa.func.date_trunc('month', galaxy.model.Job.table.c.create_time).label('date'), sa.func.max((galaxy.model.Job.table.c.update_time - galaxy.model.Job.table.c.create_time)), sa.func.avg((galaxy.model.Job.table.c.update_time - galaxy.model.Job.table.c.create_time)), sa.func.min((galaxy.model.Job.table.c.update_time - galaxy.model.Job.table.c.create_time))), from_obj=[galaxy.model.Job.table], whereclause=(galaxy.model.Job.table.c.tool_id == tool), group_by=['date'])
    months = list(jobs_times.execute())
    months.sort(sort_functions[sort_by])
    if user_cutoff:
        months = months[:user_cutoff]
    for month in months:
        ordered_data[str(month[0]).split('    ')[0][:(-3)]] = (self.formatted(month[1], color), self.formatted(month[2], color), self.formatted(month[3], color))
    return trans.fill_template('/webapps/reports/tool_execution_time_per_month.mako', data=ordered_data, tool=tool, descending=descending, user_cutoff=user_cutoff, sort_by=sort_by)
