Skip to content

Commit

Permalink
Added flag to existing extract script to allow purging
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahadik, Mukul Chandrakant authored and Mahadik, Mukul Chandrakant committed Aug 1, 2024
1 parent a600682 commit 1b6833d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bin/debug/extract_timeline_for_day_range_and_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
# only needed to read the motion_activity
# https://github.com/e-mission/e-mission-docs/issues/356#issuecomment-520630934
import emission.export.export as eee
import emission.purge_restore.export_timeseries as epret
import emission.purge_restore.purge_data as eprpd

def export_timeline(user_id, start_day_str, end_day_str, timezone, file_name):
def export_timeline(user_id, start_day_str, end_day_str, timezone, file_name, purge_ts_entries):
logging.info("Extracting timeline for user %s day %s -> %s and saving to file %s" %
(user_id, start_day_str, end_day_str, file_name))

Expand All @@ -38,7 +40,11 @@ def export_timeline(user_id, start_day_str, end_day_str, timezone, file_name):
end_day_ts, arrow.get(end_day_ts).to(timezone)))

ts = esta.TimeSeries.get_time_series(user_id)
eee.export(user_id, ts, start_day_ts, end_day_ts, "%s_%s" % (file_name, user_id), True)
if purge_ts_entries:
export_queries = epret.export(user_id, ts, start_day_ts, end_day_ts, file_name, False)
eprpd.PurgeDataPipeline().delete_timeseries_entries(user_id, ts, start_day_ts, end_day_ts, export_queries)
else:
eee.export(user_id, ts, start_day_ts, end_day_ts, "%s_%s" % (file_name, user_id), True)

import emission.core.get_database as edb
pipeline_state_list = list(edb.get_pipeline_state_db().find({"user_id": user_id}))
Expand All @@ -56,7 +62,7 @@ def export_timeline_for_users(user_id_list, args):
logging.info("=" * 50)
export_timeline(user_id=curr_uuid, start_day_str=args.start_day,
end_day_str= args.end_day, timezone=args.timezone,
file_name=args.file_prefix)
file_name=args.file_prefix, purge_ts_entries=args.purge)

if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
Expand All @@ -72,6 +78,7 @@ def export_timeline_for_users(user_id_list, args):
parser.add_argument("start_day", help="start day in utc - e.g. 'YYYY-MM-DD'" )
parser.add_argument("end_day", help="start day in utc - e.g. 'YYYY-MM-DD'" )
parser.add_argument("file_prefix", help="prefix for the filenames generated - e.g /tmp/dump_ will generate files /tmp/dump_<uuid1>.gz, /tmp/dump_<uuid2>.gz..." )
parser.add_argument("-p", "--purge", default=False, action='store_true', help="select whether to purge the timeseries database entries (only timeseries_db not analysis_db)")

args = parser.parse_args()

Expand Down

0 comments on commit 1b6833d

Please sign in to comment.