From 68bd282312ad4f81bcd8d8d9fa4d5d19674f719f Mon Sep 17 00:00:00 2001 From: Matthew Richards Date: Wed, 14 Oct 2020 10:33:09 +0000 Subject: [PATCH] #146: Add count functionality for 1st ISIS endpoint - Makes use of the existing function but adds a flag to detect whether the function should be used as a count query or not --- common/icat/helpers.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/common/icat/helpers.py b/common/icat/helpers.py index 93fc5b32..8d44841a 100644 --- a/common/icat/helpers.py +++ b/common/icat/helpers.py @@ -461,7 +461,9 @@ def create_entities(client, table_name, data): return created_data -def get_facility_cycles_for_instrument(client, instrument_id, filters): +def get_facility_cycles_for_instrument( + client, instrument_id, filters, count_query=False +): """ Given an Instrument ID, get the Facility Cycles where there are Instruments that have investigations occurring within that cycle @@ -472,11 +474,17 @@ def get_facility_cycles_for_instrument(client, instrument_id, filters): :type instrument_id: :class:`int` :param filters: The list of filters to be applied to the request :type filters: List of specific implementations :class:`QueryFilter` + :param count_query: Flag to determine if the query in this function should be used + as a count query. Used for `get_facility_cycles_for_instrument_count()` + :type count_query: :class:`bool` :return: A list of Facility Cycles that match the query """ # TODO - Add logging - query = ICATQuery(client, "FacilityCycle", aggregate="DISTINCT", isis_endpoint=True) + query_aggregate = "COUNT" if count_query else None + query = ICATQuery( + client, "FacilityCycle", aggregate=query_aggregate, isis_endpoint=True + ) instrument_id_check = PythonICATWhereFilter( "facility.instruments.id", instrument_id, "eq" @@ -524,7 +532,9 @@ def get_facility_cycles_for_instrument_count(client, instrument_id, filters): :type filters: List of specific implementations :class:`QueryFilter` :return: The number of Facility Cycles that match the query """ - pass + return get_facility_cycles_for_instrument( + client, instrument_id, filters, count_query=True + )[0] def get_investigations_for_instrument_in_facility_cycle(