Skip to content

Commit

Permalink
Added compatibility for postgres, bug fix where sparklines broke when…
Browse files Browse the repository at this point in the history
… no jobs were done

in the past 50 days(arbitrary amount decided in code)
  • Loading branch information
Airistotal committed Jun 22, 2015
1 parent bc69acb commit 3a9ff2a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
48 changes: 29 additions & 19 deletions lib/galaxy/webapps/reports/controllers/jobs.py
Expand Up @@ -11,6 +11,7 @@
import re
import sqlalchemy as sa
from galaxy.webapps.reports.controllers.query import ReportQueryBuilder
import sys

import logging
log = logging.getLogger( __name__ )
Expand Down Expand Up @@ -570,16 +571,18 @@ def per_user( self, trans, **kwd ):
currday = datetime.today().date()
trends = dict()
for job in all_jobs_per_user.execute():
curr_user = re.sub(r'\W+', '', str(job.user_email))
curr_user = re.sub(r'\W+', '', job.user_email)
try:
day = currday - job.date
day = day.days
except TypeError:
day = currday - datetime.date(job.date)

day = day.days
try:
if day < day_limit:
trends[curr_user][day] += 1
except KeyError:
trends[curr_user] = [0] * day_limit
day = currday - job.date
day = day.days
if day < day_limit:
trends[curr_user][day] += 1

Expand Down Expand Up @@ -685,9 +688,10 @@ def per_tool( self, trans, **kwd ):
group_by=[ 'tool_id' ],
order_by=[ _order ] )

all_jobs_per_tool = sa.select( ( self.select_month( model.Job.table.c.create_time ).label( 'date' ),
model.Job.table.c.id.label( 'id' ),
model.Job.table.c.tool_id.label( 'tool_id' ) ),
all_jobs_per_tool = sa.select( ( model.Job.table.c.tool_id.label( 'tool_id' ),
model.Job.table.c.id.label( 'id' ),
self.select_month( model.Job.table.c.create_time ).label( 'date' ) ),
whereclause=model.Job.table.c.user_id != monitor_user_id,
from_obj=[ model.Job.table ] )

currday = date.today()
Expand All @@ -696,20 +700,30 @@ def per_tool( self, trans, **kwd ):
curr_tool = re.sub(r'\W+', '', str(job.tool_id))
try:
day = currday - job.date
day = day.days
except TypeError:
day = currday - datetime.date(job.date)

day = day.days
try:
if day < day_limit:
trends[curr_tool][day] += 1
except KeyError:
trends[curr_tool] = [0] * day_limit
day = currday - job.date
day = day.days
if day < day_limit:
trends[curr_tool][day] += 1

for row in q.execute():
jobs.append( ( row.tool_id,
row.total_jobs ) )

print("==========jobs==================", file=sys.stderr)
for job in jobs:
print(re.sub(r'\W+', '', job[0]), file=sys.stderr)

print("==========trends==================", file=sys.stderr)
for item in trends.keys():
print(item, file=sys.stderr)

return trans.fill_template( '/webapps/reports/jobs_per_tool.mako',
order=order,
arrow=arrow,
Expand Down Expand Up @@ -760,21 +774,17 @@ def errors_per_tool( self, trans, **kwd ):
curr_tool = re.sub(r'\W+', '', str(job.tool_id))
try:
day = currday - job.date
day = day.days
except TypeError:
day = currday - datetime.date(job.date)

day = day.days
try:
if day < day_limit:
trends[curr_tool][day] += 1
except KeyError:
trends[curr_tool] = [0] * day_limit
day = currday - job.date
day = day.days
if day < day_limit:
trends[curr_tool][day] += 1
except TypeError:
day = currday - date(job.date)
day = day.days
if day < day_limit:
trends[curr_tool][day] += 1

jobs = []
for row in jobs_in_error_per_tool.execute():
jobs.append( ( row.total_jobs, row.tool_id ) )
Expand Down
5 changes: 4 additions & 1 deletion templates/webapps/reports/jobs_errors_per_tool.mako
Expand Up @@ -52,7 +52,10 @@ ${get_css()}
%endif
<td><a href="${h.url_for( controller='jobs', action='tool_per_month', tool_id=job[1], sort_id='default', order='default' )}">${job[1]}</a></td>
<td><a href="${h.url_for( controller='jobs', action='specified_date_handler', operation='specified_tool_in_error', tool_id= job[1] )}">${job[0]}</a></td>
${make_sparkline(key, trends[key], "line", "/ day")}
%try:
${make_sparkline(key, trends[key], "line", "/ day")}
%except KeyError:
%endtry
<td id="${key}"></td>
</tr>
<% ctr += 1 %>
Expand Down
5 changes: 4 additions & 1 deletion templates/webapps/reports/jobs_per_tool.mako
Expand Up @@ -51,7 +51,10 @@ ${get_css()}
%endif
<td><a href="${h.url_for( controller='jobs', action='tool_per_month', tool_id=job[0], sort_id='default', order='default' )}">${job[0]}</a></td>
<td>${job[1]}</td>
${make_sparkline(key, trends[key], "line", "/ day")}
%try:
${make_sparkline(key, trends[key], "line", "/ day")}
%except KeyError:
%endtry
<td id="${key}"></td>
</tr>
<% ctr += 1 %>
Expand Down
5 changes: 4 additions & 1 deletion templates/webapps/reports/jobs_per_user.mako
Expand Up @@ -44,7 +44,10 @@ ${get_css()}
%endif
<td><a href="${h.url_for( controller='jobs', action='user_per_month', email=job[0], sort_id='default', order='default' )}">${job[0]}</a></td>
<td>${job[1]}</td>
${make_sparkline(key, trends[key], "line", "/ day")}
%try:
${make_sparkline(key, trends[key], "line", "/ day")}
%except KeyError:
%endtry
<td id="${key}"></td>
</tr>
<% ctr += 1 %>
Expand Down

0 comments on commit 3a9ff2a

Please sign in to comment.