From c58bacce7fab9402a2050ba4d4efdc219bb22b32 Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Fri, 12 Dec 2008 09:43:42 -0500 Subject: [PATCH] New report showing last login for users, a few bug fixes and some code cleanup for the reports as well. --- lib/galaxy/model/mapping.py | 1 + lib/galaxy/webapps/reports/app.py | 3 +- lib/galaxy/webapps/reports/base/controller.py | 1 - .../webapps/reports/controllers/system.py | 10 +- .../webapps/reports/controllers/users.py | 45 ++++--- .../webapps/reports/templates/index.mako | 111 ++++++++++++++---- .../jobs_specified_date_in_error.mako | 2 +- .../webapps/reports/templates/users.mako | 29 +++++ .../templates/users_last_access_date.mako | 46 ++++++++ 9 files changed, 203 insertions(+), 45 deletions(-) create mode 100644 lib/galaxy/webapps/reports/templates/users.mako create mode 100644 lib/galaxy/webapps/reports/templates/users_last_access_date.mako diff --git a/lib/galaxy/model/mapping.py b/lib/galaxy/model/mapping.py index bb0b801667f..75391720639 100644 --- a/lib/galaxy/model/mapping.py +++ b/lib/galaxy/model/mapping.py @@ -299,6 +299,7 @@ assign_mapper( context, History, History.table, assign_mapper( context, User, User.table, properties=dict( histories=relation( History, backref="user", order_by=desc(History.table.c.update_time) ), + galaxy_sessions=relation( GalaxySession, order_by=desc( GalaxySession.table.c.update_time ) ), stored_workflow_menu_entries=relation( StoredWorkflowMenuEntry, backref="user", cascade="all, delete-orphan", collection_class=ordering_list( 'order_index' ) ) diff --git a/lib/galaxy/webapps/reports/app.py b/lib/galaxy/webapps/reports/app.py index 435889b7dc6..bda4f0646b8 100644 --- a/lib/galaxy/webapps/reports/app.py +++ b/lib/galaxy/webapps/reports/app.py @@ -1,6 +1,5 @@ -import sys, os, atexit +import sys, config import galaxy.model -import config class UniverseApplication( object ): """Encapsulates the state of a Universe application""" diff --git a/lib/galaxy/webapps/reports/base/controller.py b/lib/galaxy/webapps/reports/base/controller.py index 9a602e5bcc9..33c9151996f 100644 --- a/lib/galaxy/webapps/reports/base/controller.py +++ b/lib/galaxy/webapps/reports/base/controller.py @@ -2,7 +2,6 @@ import os, time, logging # Pieces of Galaxy to make global in every controller from galaxy import web, util -from Cheetah.Template import Template log = logging.getLogger( __name__ ) diff --git a/lib/galaxy/webapps/reports/controllers/system.py b/lib/galaxy/webapps/reports/controllers/system.py index e4017544460..1f87d74636d 100644 --- a/lib/galaxy/webapps/reports/controllers/system.py +++ b/lib/galaxy/webapps/reports/controllers/system.py @@ -37,7 +37,15 @@ class System( BaseController ): deleted_histories_days, msg = self.deleted_histories( **kwd ) elif kwd['action'] == "deleted_datasets": deleted_datasets_days, msg = self.deleted_datasets( **kwd ) - return trans.fill_template( 'system.mako', file_path=file_path, disk_usage=disk_usage, datasets=datasets, file_size_str=file_size_str, userless_histories_days=userless_histories_days, deleted_histories_days=deleted_histories_days, deleted_datasets_days=deleted_datasets_days, msg=msg ) + return trans.fill_template( 'system.mako', + file_path=file_path, + disk_usage=disk_usage, + datasets=datasets, + file_size_str=file_size_str, + userless_histories_days=userless_histories_days, + deleted_histories_days=deleted_histories_days, + deleted_datasets_days=deleted_datasets_days, + msg=msg ) def userless_histories( self, **kwd ): """The number of userless histories and associated datasets that have not been updated for the specified number of days.""" diff --git a/lib/galaxy/webapps/reports/controllers/users.py b/lib/galaxy/webapps/reports/controllers/users.py index 185a18107c3..31b0463231d 100644 --- a/lib/galaxy/webapps/reports/controllers/users.py +++ b/lib/galaxy/webapps/reports/controllers/users.py @@ -1,7 +1,9 @@ -from datetime import * +from datetime import datetime, timedelta +from time import strftime import calendar from galaxy.webapps.reports.base.controller import * import galaxy.model +from galaxy.model.orm import * import pkg_resources pkg_resources.require( "SQLAlchemy >= 0.4" ) import sqlalchemy as sa @@ -10,23 +12,20 @@ log = logging.getLogger( __name__ ) class Users( BaseController ): @web.expose + def index( self, trans, **kwd ): + params = util.Params( kwd ) + msg = params.get( 'msg', '' ) + return trans.fill_template( 'users.mako', msg=msg ) + @web.expose def registered_users( self, trans, **kwd ): params = util.Params( kwd ) - msg = '' - engine = galaxy.model.mapping.metadata.engine - s = """ - SELECT - count(id) AS num_users - FROM - galaxy_user - """ - rows = engine.text( s ).execute().fetchall() - num_users = rows[0].num_users + msg = params.get( 'msg', '' ) + num_users = galaxy.model.User.query().count() return trans.fill_template( 'registered_users.mako', num_users=num_users, msg=msg ) @web.expose def registered_users_per_month( self, trans, **kwd ): params = util.Params( kwd ) - msg = '' + msg = params.get( 'msg', '' ) q = sa.select( ( sa.func.date_trunc( 'month', sa.func.date( galaxy.model.User.table.c.create_time ) ).label( 'date' ), sa.func.count( galaxy.model.User.table.c.id ).label( 'num_users' ) ), from_obj = [ galaxy.model.User.table ], @@ -42,7 +41,7 @@ class Users( BaseController ): @web.expose def specified_month( self, trans, **kwd ): params = util.Params( kwd ) - msg = '' + msg = params.get( 'msg', '' ) year, month = map( int, params.get( 'month', datetime.utcnow().strftime( "%Y-%m" ) ).split( "-" ) ) start_date = date( year, month, 1 ) end_date = start_date + timedelta( days=calendar.monthrange( year, month )[1] ) @@ -70,7 +69,7 @@ class Users( BaseController ): @web.expose def specified_date( self, trans, **kwd ): params = util.Params( kwd ) - msg = '' + msg = params.get( 'msg', '' ) year, month, day = map( int, params.get( 'specified_date', datetime.utcnow().strftime( "%Y-%m-%d" ) ).split( "-" ) ) start_date = date( year, month, day ) end_date = start_date + timedelta( days=1 ) @@ -95,3 +94,21 @@ class Users( BaseController ): day_of_month=day_of_month, users=users, msg=msg ) + @web.expose + def last_access_date( self, trans, **kwd ): + params = util.Params( kwd ) + msg = params.get( 'msg', '' ) + not_logged_in_for_days = params.get( 'not_logged_in_for_days', 0 ) + if not not_logged_in_for_days: + not_logged_in_for_days = 0 + cutoff_time = datetime.utcnow() - timedelta( days=int( not_logged_in_for_days ) ) + now = strftime( "%Y-%m-%d %H:%M:%S" ) + users = [] + for user in galaxy.model.User.query().order_by( galaxy.model.User.table.c.email ).all(): + last_galaxy_session = user.galaxy_sessions[ 0 ] + if last_galaxy_session.update_time < cutoff_time: + users.append( ( user.email, last_galaxy_session.update_time.strftime( "%Y-%m-%d" ) ) ) + return trans.fill_template( 'users_last_access_date.mako', + users=users, + not_logged_in_for_days=not_logged_in_for_days, + msg=msg ) diff --git a/lib/galaxy/webapps/reports/templates/index.mako b/lib/galaxy/webapps/reports/templates/index.mako index ec971dca499..b069b51bcb6 100644 --- a/lib/galaxy/webapps/reports/templates/index.mako +++ b/lib/galaxy/webapps/reports/templates/index.mako @@ -1,29 +1,88 @@ <%inherit file="/base_panels.mako"/> <%def name="main_body()"> - ## Display the available reports -
-

Galaxy Reports

- - - - - - - - - - - -
Job Information
Number of jobs today - displays the total number of jobs for today
Number of jobs per day for current month - displays days of the current month with the total number of jobs for each day
Number of jobs in error per day for current month - displays days of the current month with the total number of jobs in error for each day
All unfinished jobs - displays jobs that are currently in a "new" state, a "queued" state or a "running" state
Number of jobs per month - displays a list of months with the total number of jobs for each month
Number of jobs in error per month - displays a list of months with the total number of jobs in error for each month
Number of jobs per user - displays users sorted in descending order by the number of jobs they have submitted
Number of jobs per tool - displays tools sorted in alphabetical order by tool id and the number of jobs created by the tool
Number of jobs per Internet domain - displays the number of jobs that have been submitted per Internet domain
-



- - - -
User Information
Number of registered users - displays the total number of registered users
-



- - - -
System Information
Disk space, old histories and datasets - displays history and dataset information including disk space allocation where datasets are stored
-
+ ## Display the available reports +
+

Galaxy Reports

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Job Information
+
+ Number of jobs today - displays the total number of jobs for today +
+
+
+ Number of jobs per day for current month - displays days of the current month with the total number of jobs for each day +
+
+
+ Number of jobs in error per day for current month - displays days of the current month with the total number of jobs in error for each day +
+
+
+ All unfinished jobs - displays jobs that are currently in a "new" state, a "queued" state or a "running" state +
+
+
+ Number of jobs per month - displays a list of months with the total number of jobs for each month +
+
+
+ Number of jobs in error per month - displays a list of months with the total number of jobs in error for each month +
+
+
+ Number of jobs per user - displays users sorted in descending order by the number of jobs they have submitted +
+
+
+ Number of jobs per tool - displays tools sorted in alphabetical order by tool id and the number of jobs created by the tool +
+
+



+ + + + + +
User Information
+
+ Users - displays information about registered users +
+
+



+ + + + + +
System Information
+
+ Disk space, old histories and datasets - displays history and dataset information including disk space allocation where datasets are stored +
+
+
diff --git a/lib/galaxy/webapps/reports/templates/jobs_specified_date_in_error.mako b/lib/galaxy/webapps/reports/templates/jobs_specified_date_in_error.mako index 633919e33c6..e260baeeec6 100644 --- a/lib/galaxy/webapps/reports/templates/jobs_specified_date_in_error.mako +++ b/lib/galaxy/webapps/reports/templates/jobs_specified_date_in_error.mako @@ -2,7 +2,7 @@ <%def name="main_body()">
-

All Jobs in Error for ${day_label}, ${month_label} ${day_of_month}, ${year_label} ( includes jobs deleted before finishing )

+

All Jobs in Error for ${day_label}, ${month_label} ${day_of_month}, ${year_label}

%if msg: diff --git a/lib/galaxy/webapps/reports/templates/users.mako b/lib/galaxy/webapps/reports/templates/users.mako new file mode 100644 index 00000000000..eed2d58d1be --- /dev/null +++ b/lib/galaxy/webapps/reports/templates/users.mako @@ -0,0 +1,29 @@ +<%inherit file="/base_panels.mako"/> + +<%def name="main_body()"> +

Registered Users

+ %if msg: +
${msg}
+ +
${msg}
+ %endif + + + + +
+
+ Registered Users - displays the number of registered users +
+
+

+ + + + +
+
+ Date of Last Login - displays users sorted by date of last login +
+
+ diff --git a/lib/galaxy/webapps/reports/templates/users_last_access_date.mako b/lib/galaxy/webapps/reports/templates/users_last_access_date.mako new file mode 100644 index 00000000000..4e2fd82eaac --- /dev/null +++ b/lib/galaxy/webapps/reports/templates/users_last_access_date.mako @@ -0,0 +1,46 @@ +<%inherit file="/base_panels.mako"/> + +<%def name="main_body()"> +

Date of Last Galaxy Login

+

Listed in descending order by access date ( oldest date first )

+ %if msg: + + +
${msg}
+ %endif + + + + +
+
+

+ Users that have not logged in to Galaxy for + days. +   +

+
+
+ + %if users: + + + + + <% ctr = 0 %> + %for user in users: + %if ctr % 2 == 1: + + %else: + + %endif + + + + <% ctr += 1 %> + %endfor + %else: + + %endif +
EmailDate of last Login
${user[0]}${user[1]}
All users have logged in to Galaxy within the past ${not_logged_in_for_days} days
+