diff --git a/hepdata/cli.py b/hepdata/cli.py index b3ddbc86..32f848ec 100644 --- a/hepdata/cli.py +++ b/hepdata/cli.py @@ -223,9 +223,9 @@ def do_unload(records_to_unload): @utils.command() @with_appcontext -@click.option('--endpoint', '-e', type=str, help='Specific endpoint to update (e.g. "rivet" or "MadAnalysis" or "SModelS" or "CheckMATE" or "HackAnalysis" or "Combine"). Omit for all.') +@click.option('--endpoint', '-e', type=str, help='Specific endpoint to update (e.g. "rivet" or "MadAnalysis" or "SModelS" or "CheckMATE" or "HackAnalysis" or "Combine" or "GAMBIT"). Omit for all.') def find_and_add_record_analyses(endpoint): - """Finds analyses such as Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis and Combine and adds them to records.""" + """Finds analyses such as Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis, Combine and GAMBIT and adds them to records.""" update_analyses(endpoint) diff --git a/hepdata/config.py b/hepdata/config.py index 9065b9d3..90d5d42e 100644 --- a/hepdata/config.py +++ b/hepdata/config.py @@ -361,6 +361,9 @@ def _(x): 'url': 'https://creativecommons.org/licenses/by/4.0' }, }, + 'GAMBIT': { + 'endpoint_url': 'https://gambitbsm.org/analyses.json', + }, #'ufo': {}, #'xfitter': {}, #'applgrid': {}, diff --git a/hepdata/ext/opensearch/document_enhancers.py b/hepdata/ext/opensearch/document_enhancers.py index 52d68fdf..8d107765 100644 --- a/hepdata/ext/opensearch/document_enhancers.py +++ b/hepdata/ext/opensearch/document_enhancers.py @@ -94,7 +94,7 @@ def add_shortened_authors(doc): def add_analyses(doc): """ - Add analyses links such as Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis, Combine, HistFactory and NUISANCE to the index. + Add analyses links such as Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis, Combine, HistFactory, NUISANCE and GAMBIT to the index. :param doc: :return: diff --git a/hepdata/modules/records/assets/js/hepdata_common.js b/hepdata/modules/records/assets/js/hepdata_common.js index 04027b4b..833ecd32 100644 --- a/hepdata/modules/records/assets/js/hepdata_common.js +++ b/hepdata/modules/records/assets/js/hepdata_common.js @@ -49,6 +49,7 @@ HEPDATA.file_type_to_details = { "checkmate": {"icon": "area-chart", "description": "CheckMATE Analysis"}, "hackanalysis": {"icon": "area-chart", "description": "HackAnalysis Analysis"}, "combine": {"icon": "area-chart", "description": "Combine Analysis"}, + "gambit": {"icon": "area-chart", "description": "GAMBIT analysis"}, "xfitter": {"icon": "area-chart", "description": "xFitter Analysis"}, "applgrid": {"icon": "area-chart", "description": "APPLgrid Analysis"}, "ufo": {"icon": "rocket", "description": "Universal Feynrules Output (UFO)"}, diff --git a/hepdata/modules/records/templates/hepdata_records/components/resources-widget.html b/hepdata/modules/records/templates/hepdata_records/components/resources-widget.html index 79b35cb0..c8f79c03 100644 --- a/hepdata/modules/records/templates/hepdata_records/components/resources-widget.html +++ b/hepdata/modules/records/templates/hepdata_records/components/resources-widget.html @@ -45,6 +45,7 @@

Add Resource for Submission

+ diff --git a/hepdata/modules/records/utils/analyses.py b/hepdata/modules/records/utils/analyses.py index 188949e0..2217a303 100644 --- a/hepdata/modules/records/utils/analyses.py +++ b/hepdata/modules/records/utils/analyses.py @@ -44,11 +44,11 @@ @shared_task def update_analyses(endpoint=None): """ - Update (Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis and Combine) analyses and remove outdated resources. + Update (Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis, Combine, and GAMBIT) analyses and remove outdated resources. Allow bulk subscription to record update notifications if "subscribe_user_id" in endpoint. Add optional "description" and "license" fields if present in endpoint. - :param endpoint: either "rivet" or "MadAnalysis" or "SModelS" or "CheckMATE" or "HackAnalysis" or "Combine" or None (default) for all + :param endpoint: either "rivet" or "MadAnalysis" or "SModelS" or "CheckMATE" or "HackAnalysis" or "Combine" or "GAMBIT" or None (default) for all """ endpoints = current_app.config["ANALYSES_ENDPOINTS"] for analysis_endpoint in endpoints: @@ -64,62 +64,129 @@ def update_analyses(endpoint=None): if response and response.status_code == 200: - analyses = response.json() - analysis_resources = DataResource.query.filter_by(file_type=analysis_endpoint).all() - # Check for missing analyses. - for record in analyses: - submission = get_latest_hepsubmission(inspire_id=record, overall_status='finished') - - if submission: - num_new_resources = 0 - - for analysis in analyses[record]: - _resource_url = endpoints[analysis_endpoint]["url_template"].format(analysis) - - if not is_resource_added_to_submission(submission.publication_recid, submission.version, - _resource_url): - - log.info('Adding {} analysis to ins{} with URL {}'.format( - analysis_endpoint, record, _resource_url) - ) - new_resource = DataResource( - file_location=_resource_url, - file_type=analysis_endpoint) - - if "description" in endpoints[analysis_endpoint]: - new_resource.file_description = str(endpoints[analysis_endpoint]["description"]) - - if "license" in endpoints[analysis_endpoint]: - resource_license = get_license(endpoints[analysis_endpoint]["license"]) - new_resource.file_license = resource_license.id - - submission.resources.append(new_resource) - num_new_resources += 1 - - else: - - # Remove resources from 'analysis_resources' list. - resources = list(filter(lambda a: a.file_location == _resource_url, analysis_resources)) - for resource in resources: - analysis_resources.remove(resource) - - if num_new_resources: - - try: - db.session.add(submission) - db.session.commit() - latest_submission = get_latest_hepsubmission(inspire_id=record) - if submission.version == latest_submission.version: - index_record_ids([submission.publication_recid]) - except Exception as e: - db.session.rollback() - log.error(e) + r_json = response.json() + new_json = "analyses" in r_json + + if new_json: + + # Check for missing analyses. + for ana in r_json["analyses"]: + inspire_id = ana["inspire_id"] + submission = get_latest_hepsubmission(inspire_id=str(inspire_id), overall_status='finished') # TODO: make inspire_id an int - else: - log.debug("An analysis is available in {0} but with no equivalent in HEPData (ins{1}).".format( - analysis_endpoint, record)) + if submission: + num_new_resources = 0 + + for implementation in ana["implementations"]: + ana_name = implementation["name"] + ana_path = implementation["path"] if "path" in implementation else "" + _resource_url = r_json["url_templates"]["main_url"] + prev_url = None + n_tries, max_tries = 0, 10 + while _resource_url!=prev_url and n_triesOther useful searches (ProSelecta analysis for use with NUISANCE) +
  • + analysis:GAMBIT + + (GAMBIT analysis) + +
  • diff --git a/tests/records_test.py b/tests/records_test.py index d701ae69..181b7324 100644 --- a/tests/records_test.py +++ b/tests/records_test.py @@ -1117,6 +1117,14 @@ def test_update_analyses(app): assert license_data.name == 'cc-by-4.0' assert license_data.url == 'https://creativecommons.org/licenses/by/4.0' + # Import a record that has an associated GAMBIT analysis + import_records(['ins1827025'], synchronous=True) + analysis_resources = DataResource.query.filter_by(file_type='GAMBIT').all() + assert len(analysis_resources) == 0 + update_analyses('GAMBIT') + analysis_resources = DataResource.query.filter_by(file_type='GAMBIT').all() + assert len(analysis_resources) == 1 + assert analysis_resources[0].file_location == 'https://github.com/GambitBSM/gambit_2.6/blob/release_2.6/ColliderBit/src/analyses/Analysis_ATLAS_13TeV_0LEP_139invfb.cpp' def test_generate_license_data_by_id(app): """