Skip to content

Commit

Permalink
Added option for how long sparklines jobs per user, jobs per tool and…
Browse files Browse the repository at this point in the history
… errors per tool are
  • Loading branch information
Airistotal committed Jun 22, 2015
1 parent 3a9ff2a commit d870a24
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 40 deletions.
101 changes: 71 additions & 30 deletions lib/galaxy/webapps/reports/controllers/jobs.py
Expand Up @@ -6,6 +6,7 @@
from galaxy import model, util
from galaxy.web.framework.helpers import grids
from galaxy.model.orm import and_, not_, or_
from math import floor
import pkg_resources
pkg_resources.require( "SQLAlchemy >= 0.4" )
import re
Expand Down Expand Up @@ -554,7 +555,19 @@ def per_user( self, trans, **kwd ):
order = specs.order
arrow = specs.arrow
_order = specs.exc_order
day_limit = 50
time_period = kwd.get('spark_time')
if time_period == "days":
_time_period = 1.0
elif time_period == "weeks":
_time_period = 7.0
elif time_period == "months":
_time_period = 30.0
elif time_period == "years":
_time_period = 365.0
else:
time_period = "days"
_time_period = 1.0
limit = 30

jobs = []
jobs_per_user = sa.select( ( model.User.table.c.email.label( 'user_email' ),
Expand All @@ -568,7 +581,7 @@ def per_user( self, trans, **kwd ):
model.User.table.c.email.label( 'user_email' ) ),
from_obj=[ sa.outerjoin( model.Job.table, model.User.table ) ] )

currday = datetime.today().date()
currday = date.today()
trends = dict()
for job in all_jobs_per_user.execute():
curr_user = re.sub(r'\W+', '', job.user_email)
Expand All @@ -578,13 +591,15 @@ def per_user( self, trans, **kwd ):
day = currday - datetime.date(job.date)

day = day.days
container = floor(day / _time_period)
container = int(container)
try:
if day < day_limit:
trends[curr_user][day] += 1
if container < limit:
trends[curr_user][container] += 1
except KeyError:
trends[curr_user] = [0] * day_limit
if day < day_limit:
trends[curr_user][day] += 1
trends[curr_user] = [0] * limit
if container < limit:
trends[curr_user][container] += 1

for row in jobs_per_user.execute():
if ( row.user_email is None ):
Expand All @@ -600,7 +615,8 @@ def per_user( self, trans, **kwd ):
order=order,
arrow=arrow,
sort_id=sort_id,
day_limit=day_limit,
limit=limit,
time_period=time_period,
trends=trends,
jobs=jobs,
message=message )
Expand Down Expand Up @@ -675,7 +691,20 @@ def per_tool( self, trans, **kwd ):
order = specs.order
arrow = specs.arrow
_order = specs.exc_order
day_limit = 50
time_period = kwd.get('spark_time')
if time_period == "days":
_time_period = 1.0
elif time_period == "weeks":
_time_period = 7.0
elif time_period == "months":
_time_period = 30.0
elif time_period == "years":
_time_period = 365.0
else:
time_period = "days"
_time_period = 1.0

limit = 30

# In case we don't know which is the monitor user we will query for all jobs
monitor_user_id = get_monitor_id( trans, monitor_email )
Expand Down Expand Up @@ -704,31 +733,26 @@ def per_tool( self, trans, **kwd ):
day = currday - datetime.date(job.date)

day = day.days
container = floor(day / _time_period)
container = int(container)
try:
if day < day_limit:
trends[curr_tool][day] += 1
if container < limit:
trends[curr_tool][container] += 1
except KeyError:
trends[curr_tool] = [0] * day_limit
if day < day_limit:
trends[curr_tool][day] += 1
trends[curr_tool] = [0] * limit
if container < limit:
trends[curr_tool][container] += 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,
sort_id=sort_id,
day_limit=day_limit,
limit=limit,
time_period=time_period,
trends=trends,
jobs=jobs,
message=message,
Expand All @@ -748,7 +772,20 @@ def errors_per_tool( self, trans, **kwd ):
order = specs.order
arrow = specs.arrow
_order = specs.exc_order
day_limit = 50
time_period = kwd.get('spark_time')
if time_period == "days":
_time_period = 1.0
elif time_period == "weeks":
_time_period = 7.0
elif time_period == "months":
_time_period = 30.0
elif time_period == "years":
_time_period = 365.0
else:
time_period = "days"
_time_period = 1.0

limit = 30
# In case we don't know which is the monitor user we will query for all jobs
monitor_user_id = get_monitor_id( trans, monitor_email )

Expand Down Expand Up @@ -777,22 +814,26 @@ def errors_per_tool( self, trans, **kwd ):
except TypeError:
day = currday - datetime.date(job.date)

#convert day into days/weeks/months/years
day = day.days
container = floor(day / _time_period)
container = int(container)
try:
if day < day_limit:
trends[curr_tool][day] += 1
if container < limit:
trends[curr_tool][container] += 1
except KeyError:
trends[curr_tool] = [0] * day_limit
if day < day_limit:
trends[curr_tool][day] += 1
trends[curr_tool] = [0] * limit
if day < limit:
trends[curr_tool][container] += 1
jobs = []
for row in jobs_in_error_per_tool.execute():
jobs.append( ( row.total_jobs, row.tool_id ) )
return trans.fill_template( '/webapps/reports/jobs_errors_per_tool.mako',
order=order,
arrow=arrow,
sort_id=sort_id,
day_limit=day_limit,
limit=limit,
time_period=time_period,
trends=trends,
jobs=jobs,
message=message,
Expand Down
51 changes: 51 additions & 0 deletions templates/spark_base.mako
Expand Up @@ -8,6 +8,57 @@
</style>
</%def>

<%def name="spark_css()">
<style>
#spark_time_select {
display: inline-block;
}
#spark_select {
height: 23px;
width: 30px;
padding: 0;
border-radius: 2px;
}
</style>
</%def>

<%def name="make_spark_settings( controller, action, limit, sort_id, order, time_period )">
<div id="spark_time_select">
<form method="post" controller=${controller} action=${action}>
<input type="hidden" value=${sort_id} name="sort_id">
<input type="hidden" value=${order} name="order">
${limit}
<select name="spark_time">
%if time_period == "days":
<option value="days" selected="selected">Days</option>
%else:
<option value="days">Days</option>
%endif
%if time_period == "weeks":
<option value="weeks" selected="selected">Weeks</option>
%else:
<option value="weeks">Weeks</option>
%endif
%if time_period == "months":
<option value="months" selected="selected">Months</option>
%else:
<option value="months">Months</option>
%endif
%if time_period == "years":
<option value="years" selected="selected">Years</option>
%else:
<option value="years">Years</option>
%endif
</select>
<button id="spark_select">Go</button>
</form>
</div>
</%def>

<%def name="make_sparkline(id, data, sparktype, length)">
<%
color = '<span style="color: {{color}}">&#9679;</span>'
Expand Down
2 changes: 1 addition & 1 deletion templates/webapps/reports/index.mako
Expand Up @@ -53,7 +53,7 @@
<div class="toolTitle"><a target="galaxy_main" href="${h.url_for( controller='jobs', action='per_month_in_error', sort_id='default', order='default' )}">Jobs in error per month</a></div>
<div class="toolTitle"><a target="galaxy_main" href="${h.url_for( controller='jobs', action='per_user', sort_id='default', order='default' )}">Jobs per user</a></div>
<div class="toolTitle"><a target="galaxy_main" href="${h.url_for( controller='jobs', action='per_tool', sort_id='default', order='default' )}">Jobs per tool</a></div>
<div class="toolTitle"><a target="galaxy_main" href="${h.url_for( controller='jobs', action='errors_per_tool', sort_id='default', order='default' )}">Errors per tool</a></div>
<div class="toolTitle"><a target="galaxy_main" href="${h.url_for( controller='jobs', action='errors_per_tool', sort_id='default', order='default')}">Errors per tool</a></div>
</div>
</div>
<div class="toolSectionPad"></div>
Expand Down
7 changes: 4 additions & 3 deletions templates/webapps/reports/jobs_errors_per_tool.mako
@@ -1,6 +1,6 @@
<%inherit file="/base.mako"/>
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/spark_base.mako" import="jqs_style, make_sparkline" />
<%namespace file="/spark_base.mako" import="jqs_style, make_sparkline, make_spark_settings, spark_css" />
<%namespace file="/sorting_base.mako" import="get_sort_url, get_css" />
<%!
import re
Expand All @@ -10,6 +10,7 @@
${render_msg( message, 'done' )}
%endif

${spark_css()}
${jqs_style()}
${get_css()}

Expand All @@ -19,7 +20,7 @@ ${get_css()}
<h4 align="center">Jobs In Error Per Tool</h4>
<h5 align="center">
<p>Click Tool ID to view details. Click error number to view job details.</p>
<p> Graph goes from present to past(${day_limit} days).</p>
Graph goes from present to past for ${make_spark_settings( "jobs", "errors_per_tool", limit, sort_id, order, time_period )}
</h5>
<table align="center" width="60%" class="colored">
%if len( jobs ) == 0:
Expand Down Expand Up @@ -53,7 +54,7 @@ ${get_css()}
<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>
%try:
${make_sparkline(key, trends[key], "line", "/ day")}
${make_sparkline(key, trends[key], "bar", "/ day")}
%except KeyError:
%endtry
<td id="${key}"></td>
Expand Down
7 changes: 4 additions & 3 deletions templates/webapps/reports/jobs_per_tool.mako
@@ -1,6 +1,6 @@
<%inherit file="/base.mako"/>
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/spark_base.mako" import="jqs_style, make_sparkline" />
<%namespace file="/spark_base.mako" import="jqs_style, make_sparkline, make_spark_settings, spark_css" />
<%namespace file="/sorting_base.mako" import="get_sort_url, get_css" />
<%!
import re
Expand All @@ -10,6 +10,7 @@
${render_msg( message, 'done' )}
%endif

${spark_css()}
${jqs_style()}
${get_css()}

Expand All @@ -18,7 +19,7 @@ ${get_css()}
<div class="toolFormBody">
<h4 align="center">Jobs Per Tool</h4>
<h5 align="center">
Click Tool ID to view details. Graph goes from present to past(${day_limit} days).
Click Tool ID to view details. Graph goes from present to past ${make_spark_settings( "jobs", "per_tool", limit, sort_id, order, time_period )}
</h5>
<table align="center" width="60%" class="colored">
%if len( jobs ) == 0:
Expand Down Expand Up @@ -52,7 +53,7 @@ ${get_css()}
<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>
%try:
${make_sparkline(key, trends[key], "line", "/ day")}
${make_sparkline(key, trends[key], "bar", "/ day")}
%except KeyError:
%endtry
<td id="${key}"></td>
Expand Down
7 changes: 4 additions & 3 deletions templates/webapps/reports/jobs_per_user.mako
@@ -1,6 +1,6 @@
<%inherit file="/base.mako"/>
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/spark_base.mako" import="jqs_style, make_sparkline" />
<%namespace file="/spark_base.mako" import="jqs_style, make_sparkline, make_spark_settings, spark_css" />
<%namespace file="/sorting_base.mako" import="get_sort_url, get_css" />
<%!
import re
Expand All @@ -10,6 +10,7 @@
${render_msg( message, 'done' )}
%endif

${spark_css()}
${jqs_style()}
${get_css()}

Expand All @@ -18,7 +19,7 @@ ${get_css()}
<div class="toolFormBody">
<h4 align="center">Jobs Per User</h4>
<h5 align="center">
Click User to view details. Graph goes from present to past(${day_limit} days).
Click User to view details. Graph goes from present to past ${make_spark_settings( "jobs", "per_user", limit, sort_id, order, time_period )}
</h5>
<table align="center" width="60%" class="colored">
%if len( jobs ) == 0:
Expand All @@ -45,7 +46,7 @@ ${get_css()}
<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>
%try:
${make_sparkline(key, trends[key], "line", "/ day")}
${make_sparkline(key, trends[key], "bar", "/ day")}
%except KeyError:
%endtry
<td id="${key}"></td>
Expand Down

0 comments on commit d870a24

Please sign in to comment.