Skip to content

Commit

Permalink
#146: Add count functionality for 1st ISIS endpoint
Browse files Browse the repository at this point in the history
- Makes use of the existing function but adds a flag to detect whether the function should be used as a count query or not
  • Loading branch information
MRichards99 committed Oct 14, 2020
1 parent 5944932 commit 68bd282
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions common/icat/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 68bd282

Please sign in to comment.