commit/galaxy-central: greg: Enable an admin to be able to view and regenerate tool shed statistics.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/69aab50e8e18/ changeset: 69aab50e8e18 user: greg date: 2012-04-03 21:18:29 summary: Enable an admin to be able to view and regenerate tool shed statistics. affected #: 5 files diff -r 12a3c47995d6269f49b4695fb9acc5c7fbf630a9 -r 69aab50e8e18b3cda8ffd9acf4537e01a0c6c31f lib/galaxy/util/shed_util.py --- a/lib/galaxy/util/shed_util.py +++ b/lib/galaxy/util/shed_util.py @@ -24,35 +24,73 @@ class ShedCounter( object ): def __init__( self, model ): self.model = model - self.count_time = strftime( "%b %d, %Y", gmtime() ) - self.valid_tools = self.count_valid_tools() + self.generation_time = strftime( "%b %d, %Y", gmtime() ) + self.repositories = 0 + self.new_repositories = 0 + self.deleted_repositories = 0 + self.invalid_tools = 0 + self.valid_tools = 0 + self.workflows = 0 + self.proprietary_datatypes = 0 + self.total_clones = 0 + self.generate_statistics() @property def sa_session( self ): """Returns a SQLAlchemy session""" return self.model.context - def count_valid_tools( self ): - valid_tools = 0 - processed_repository_ids = [] - for repository_metadata in self.sa_session.query( self.model.RepositoryMetadata ) \ - .filter( and_( self.model.RepositoryMetadata.table.c.malicious == False, - self.model.RepositoryMetadata.table.c.metadata is not None, - self.model.RepositoryMetadata.table.c.tool_versions is not None ) ): - processed_guids = [] - repository = repository_metadata.repository - if repository.id not in processed_repository_ids: - for revision_metadata in repository.downloadable_revisions: - metadata = revision_metadata.metadata + def generate_statistics( self ): + self.repositories = 0 + self.new_repositories = 0 + self.deleted_repositories = 0 + self.invalid_tools = 0 + self.valid_tools = 0 + self.workflows = 0 + self.proprietary_datatypes = 0 + self.total_clones = 0 + for repository in self.sa_session.query( self.model.Repository ): + self.total_clones += repository.times_downloaded + if repository.deleted: + self.deleted_repositories += 1 + elif repository.is_new: + self.new_repositories += 1 + else: + self.repositories += 1 + for downloadable_revision in repository.downloadable_revisions: + processed_guids = [] + processed_invalid_tool_configs = [] + processed_relative_workflow_paths = [] + processed_datatypes = [] + metadata = downloadable_revision.metadata if 'tools' in metadata: tool_dicts = metadata[ 'tools' ] for tool_dict in tool_dicts: if 'guid' in tool_dict: guid = tool_dict[ 'guid' ] if guid not in processed_guids: - valid_tools += 1 + self.valid_tools += 1 processed_guids.append( guid ) - processed_repository_ids.append( repository.id ) - return valid_tools - + if 'invalid_tools' in metadata: + invalid_tool_configs = metadata[ 'invalid_tools' ] + for invalid_tool_config in invalid_tool_configs: + if invalid_tool_config not in processed_invalid_tool_configs: + self.invalid_tools += 1 + processed_invalid_tool_configs.append( invalid_tool_config ) + if 'datatypes' in metadata: + datatypes = metadata[ 'datatypes' ] + for datatypes_dict in datatypes: + if 'extension' in datatypes_dict: + extension = datatypes_dict[ 'extension' ] + if extension not in processed_datatypes: + self.proprietary_datatypes += 1 + processed_datatypes.append( extension ) + if 'workflows' in metadata: + workflows = metadata[ 'workflows' ] + for workflow_tup in workflows: + relative_path, exported_workflow_dict = workflow_tup + if relative_path not in processed_relative_workflow_paths: + self.workflows += 1 + processed_relative_workflow_paths.append( relative_path ) + self.generation_time = strftime( "%b %d, %Y", gmtime() ) def add_to_shed_tool_config( app, shed_tool_conf_dict, elem_list ): # A tool shed repository is being installed so change the shed_tool_conf file. Parse the config file to generate the entire list # of config_elems instead of using the in-memory list since it will be a subset of the entire list if one or more repositories have diff -r 12a3c47995d6269f49b4695fb9acc5c7fbf630a9 -r 69aab50e8e18b3cda8ffd9acf4537e01a0c6c31f lib/galaxy/webapps/community/controllers/admin.py --- a/lib/galaxy/webapps/community/controllers/admin.py +++ b/lib/galaxy/webapps/community/controllers/admin.py @@ -548,6 +548,15 @@ return self.repository_list_grid( trans, **kwd ) @web.expose @web.require_admin + def regenerate_statistics( self, trans, **kwd ): + if 'regenerate_statistics_button' in kwd: + trans.app.shed_counter.generate_statistics() + message = "Successfully regenerated statistics" + return trans.fill_template( '/webapps/community/admin/statistics.mako', + message=message, + status='done' ) + @web.expose + @web.require_admin def delete_repository( self, trans, **kwd ): params = util.Params( kwd ) message = util.restore_text( params.get( 'message', '' ) ) diff -r 12a3c47995d6269f49b4695fb9acc5c7fbf630a9 -r 69aab50e8e18b3cda8ffd9acf4537e01a0c6c31f templates/webapps/community/admin/index.mako --- a/templates/webapps/community/admin/index.mako +++ b/templates/webapps/community/admin/index.mako @@ -89,6 +89,12 @@ </div></div></div> + <div class="toolSectionTitle"> + Statistics + </div> + <div class="toolTitle"> + <a target="galaxy_main" href="${h.url_for( controller='admin', action='regenerate_statistics', webapp='community' )}">View shed statistics</a> + </div></div></div></div> diff -r 12a3c47995d6269f49b4695fb9acc5c7fbf630a9 -r 69aab50e8e18b3cda8ffd9acf4537e01a0c6c31f templates/webapps/community/admin/statistics.mako --- /dev/null +++ b/templates/webapps/community/admin/statistics.mako @@ -0,0 +1,56 @@ +<%inherit file="/base.mako"/> +<%namespace file="/message.mako" import="render_msg" /> + +%if message: + ${render_msg( message, status )} +%endif + +<div class="toolForm"> + <div class="toolFormTitle">Tool shed statistics generated on ${trans.app.shed_counter.generation_time}</div> + <form name="regenerate_statistics" id="regenerate_statistics" action="${h.url_for( controller='admin', action='regenerate_statistics', webapp='community' )}" method="post" > + <div class="form-row"> + <table class="grid"> + <tr> + <th>Item</th> + <th>Count</th> + </tr> + <tr> + <td>Total repositories</td> + <td>${trans.app.shed_counter.repositories}</td> + </tr> + <tr> + <td>New repositories</td> + <td>${trans.app.shed_counter.new_repositories}</td> + </tr> + <tr> + <td>Deleted repositories</td> + <td>${trans.app.shed_counter.deleted_repositories}</td> + </tr> + <tr> + <td>Valid tools</td> + <td>${trans.app.shed_counter.valid_tools}</td> + </tr> + <tr> + <td>Invalid tools</td> + <td>${trans.app.shed_counter.invalid_tools}</td> + </tr> + <tr> + <td>Workflows</td> + <td>${trans.app.shed_counter.workflows}</td> + </tr> + <tr> + <td>Proprietary datatypes</td> + <td>${trans.app.shed_counter.proprietary_datatypes}</td> + </tr> + <tr> + <td>Total clones</td> + <td>${trans.app.shed_counter.total_clones}</td> + </tr> + </table> + </div> + <div class="form-row"> + <input type="submit" name="regenerate_statistics_button" value="Regenerate statistics"/> + </div> + </form> + </div> +</div> diff -r 12a3c47995d6269f49b4695fb9acc5c7fbf630a9 -r 69aab50e8e18b3cda8ffd9acf4537e01a0c6c31f templates/webapps/community/index.mako --- a/templates/webapps/community/index.mako +++ b/templates/webapps/community/index.mako @@ -39,7 +39,7 @@ <%def name="left_panel()"><div class="unified-panel-header" unselectable="on"> - <div class='unified-panel-header-inner'>${trans.app.shed_counter.valid_tools} valid tools on ${trans.app.shed_counter.count_time}</div> + <div class='unified-panel-header-inner'>${trans.app.shed_counter.valid_tools} valid tools on ${trans.app.shed_counter.generation_time}</div></div><div class="page-container" style="padding: 10px;"><div class="toolMenu"> Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket