Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added count_documents() implementation to builtin_timeseries #935

Merged
merged 11 commits into from
Sep 13, 2023
12 changes: 12 additions & 0 deletions emission/storage/timeseries/builtin_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
shankari marked this conversation as resolved.
Show resolved Hide resolved
"""
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_list=[key], extra_query_list=extra_query_list)
result_dataset = self.get_timeseries_db(key)
total_entries = result_dataset.count_documents(created_query)
return total_entries


16 changes: 16 additions & 0 deletions emission/tests/storageTests/TestTimeSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ def testExtraQueries(self):
with self.assertRaises(AttributeError):
list(ts.find_entries(time_query=tq, extra_query_list=[ignored_phones]))

def testCountData(self):
'''
Test 1 : Specific key with empty extra_queries
key = 'background/location', extra_query_list = []
Results in empty query = {}, which matches all documents for a user for that key.
Hence should return total count of all documents matching that key.
Testing this with sample dataset: "shankari_2015-aug-27"
'''
ts = esta.TimeSeries.get_time_series(self.testUUID)
total_count = ts.count_data("background/location",[])
print(total_count)
self.assertEqual(total_count, 555)
shankari marked this conversation as resolved.
Show resolved Hide resolved
print("Assert Test for Count Data successful!")



if __name__ == '__main__':
import emission.tests.common as etc
etc.configLogging()
Expand Down