Skip to content

Commit

Permalink
Used get entry at ts
Browse files Browse the repository at this point in the history
  • Loading branch information
TeachMeTW committed Oct 15, 2024
1 parent fc3f0ee commit d02f186
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
13 changes: 7 additions & 6 deletions emission/storage/timeseries/builtin_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@ def _get_query(self, key_list = None, time_query = None, geo_query = None,
eq_keys = set(extra_query.keys())
curr_keys = set(ret_query.keys())
overlap_keys = eq_keys.intersection(curr_keys)
if overlap_keys:
logging.info(
f"eq_keys = {eq_keys}, curr_keys = {curr_keys}, overlap_keys = {overlap_keys}"
)
raise AttributeError(f"extra query would overwrite keys {list(overlap_keys)}")
ret_query.update(extra_query)
if len(overlap_keys) != 0:
logging.info("eq_keys = %s, curr_keys = %s, overlap_keys = %s" %
(eq_keys, curr_keys, overlap_keys))
raise AttributeError("extra query would overwrite keys %s" %
list(overlap_keys))
else:
ret_query.update(extra_query)

return ret_query

Expand Down
32 changes: 8 additions & 24 deletions emission/tests/funcTests/TestFunctionTiming.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,11 @@ def execute_and_time_function(func: t.Callable[[], bool]):
# Verification: Adjusted Query to Match Document Structure
timeseries_db = esta.TimeSeries.get_time_series(None)

# Define the time range and additional filters
time_query = {
"data.ts": {"$gte": timestamp, "$lte": timestamp},
"data.name": function_name,
"data.reading": {"$gte": elapsed_ms, "$lte": elapsed_ms}
}

# Retrieve the first matching entry using the get_first_entry method
stored_document = timeseries_db.get_first_entry(
# Retrieve the document
stored_document = timeseries_db.get_entry_at_ts(
key="stats/dashboard_time",
field="data.ts",
sort_order=pymongo.DESCENDING,
time_query=time_query
ts_key="data.ts",
ts=timestamp
)

if stored_document:
Expand Down Expand Up @@ -120,19 +112,11 @@ def execute_and_time_function(func: t.Callable[[], bool]):
# Initialize the TimeSeries database connection
timeseries_db = esta.TimeSeries.get_time_series(None)

# Define the time range and additional filters
time_query = {
"data.ts": {"$gte": timestamp, "$lte": timestamp},
"data.name": function_name,
"data.reading": {"$gte": elapsed_ms, "$lte": elapsed_ms}
}

# Retrieve the first matching entry using the get_first_entry method
stored_error = timeseries_db.get_first_entry(
# Retrieve the document
stored_error = timeseries_db.get_entry_at_ts(
key="stats/dashboard_error",
field="data.ts",
sort_order=pymongo.DESCENDING,
time_query=time_query
ts_key="data.ts",
ts=timestamp
)


Expand Down

0 comments on commit d02f186

Please sign in to comment.