Skip to content

Commit

Permalink
Fixed datetime module + Cleaned up redundant changes from other PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahadik, Mukul Chandrakant authored and Mahadik, Mukul Chandrakant committed Jul 11, 2024
1 parent 24548f4 commit 6a990cb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
6 changes: 3 additions & 3 deletions bin/purge_user_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def purgeUserTimeseries(user_uuid, user_email=None, dir_name=DEFAULT_DIR_NAME, u
export_file_name = dir_name + "/archive_%s_%s_%s" % (user_id, time_query.startTs, time_query.endTs)


start_ts_datetime = datetime.datetime.fromtimestamp(time_query.startTs).strftime('%Y-%m-%d %H:%M:%S')
end_ts_datetime = datetime.datetime.fromtimestamp(time_query.endTs).strftime('%Y-%m-%d %H:%M:%S')
start_ts_datetime = datetime.fromtimestamp(time_query.startTs).strftime('%Y-%m-%d %H:%M:%S')
end_ts_datetime = datetime.fromtimestamp(time_query.endTs).strftime('%Y-%m-%d %H:%M:%S')
print("Start Time: ", start_ts_datetime)
print("Start Ts: ", time_query.startTs)
print("End Time: ", end_ts_datetime)
Expand Down Expand Up @@ -143,7 +143,7 @@ def purgeUserTimeseries(user_uuid, user_email=None, dir_name=DEFAULT_DIR_NAME, u
print(f"Key query: {key}")
print("{} deleted entries from {} to {}".format(result.deleted_count, start_ts_datetime, end_ts_datetime))

return file_name
return export_file_name


if __name__ == '__main__':
Expand Down
10 changes: 2 additions & 8 deletions emission/analysis/classification/inference/labels/inferrers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import copy
import time
import arrow
from uuid import UUID

import emission.analysis.modelling.tour_model_first_only.load_predict as lp
import emission.analysis.modelling.trip_model.run_model as eamur
Expand Down Expand Up @@ -172,19 +171,14 @@ def predict_cluster_confidence_discounting(trip_list, max_confidence=None, first
user_id_list = []
for trip in trip_list:
user_id_list.append(trip['user_id'])
error_message = f"""
Multiple user_ids found for trip_list, expected unique user_id for all trips.
Unique user_ids count = {len(set(user_id_list))}
{set(user_id_list)}
"""
assert user_id_list.count(user_id_list[0]) == len(user_id_list), error_message
assert user_id_list.count(user_id_list[0]) == len(user_id_list), "Multiple user_ids found for trip_list, expected unique user_id for all trips"
# Assertion successful, use unique user_id
user_id = user_id_list[0]

# load model
start_model_load_time = time.process_time()
model = eamur._load_stored_trip_model(user_id, model_type, model_storage)
logging.debug(f"{arrow.now()} Inside predict_cluster_confidence_discounting: Model load time = {time.process_time() - start_model_load_time}")
print(f"{arrow.now()} Inside predict_labels_n: Model load time = {time.process_time() - start_model_load_time}")

labels_n_list = eamur.predict_labels_with_n(trip_list, model)
predictions_list = []
Expand Down
4 changes: 2 additions & 2 deletions emission/analysis/modelling/trip_model/run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def predict_labels_with_n(
"""

predictions_list = []
logging.debug(f"{arrow.now()} Inside predict_labels_n: Predicting...")
print(f"{arrow.now()} Inside predict_labels_n: Predicting...")
start_predict_time = time.process_time()
for trip in trip_list:
if model is None:
Expand All @@ -118,7 +118,7 @@ def predict_labels_with_n(
else:
predictions, n = model.predict(trip)
predictions_list.append((predictions, n))
logging.debug(f"{arrow.now()} Inside predict_labels_n: Predictions complete for trip_list in time = {time.process_time() - start_predict_time}")
print(f"{arrow.now()} Inside predict_labels_n: Predictions complete for trip_list in time = {time.process_time() - start_predict_time}")
return predictions_list


Expand Down
2 changes: 1 addition & 1 deletion emission/tests/exportTests/TestExportModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def testExportModule(self):
self.assertTrue(pl.Path(file_name).is_file())
with gzip.open(file_name, 'r') as ef:
exported_data = json.loads(ef.read().decode('utf-8'))

confirmed_trips_exported = []
for t in exported_data:
if t['metadata']['key'] == "analysis/confirmed_trip":
Expand Down

0 comments on commit 6a990cb

Please sign in to comment.