From 3c92c4b38ebc5d6d3b30ae6b04c687810dbaa55e Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Fri, 25 Aug 2023 17:11:58 -0700 Subject: [PATCH] Updated builtin_timeseries.py to add count_documents() implementation Implemented code for issue #933 in e-mission-docs for adding functionality to count number of documents. I've determined that 'key' parameter can be passed to retrieve appropriate timeseries db collection. A query is generated with optional extra_query keys list which returns filtered data set. --- emission/storage/timeseries/builtin_timeseries.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/emission/storage/timeseries/builtin_timeseries.py b/emission/storage/timeseries/builtin_timeseries.py index 64898dcef..e0f3af947 100644 --- a/emission/storage/timeseries/builtin_timeseries.py +++ b/emission/storage/timeseries/builtin_timeseries.py @@ -440,3 +440,15 @@ def update_data(user_id, key, obj_id, data): logging.debug("updating entry %s into timeseries" % new_entry) edb.save(ts.get_timeseries_db(key), new_entry) + def count_data(self, key, extra_query_list): + """ + Returns the total number of documents for the specific key referring to a timeseries db. + Additional keys can be passed as an optional list for filtering data. + """ + logging.debug("count_data timeseries called") + created_query = self._get_query([key], extra_query_list) + result_dataset = self.get_timeseries_db(key) + total_entries = result_set.count_documents(created_query) + return total_entries + +