Skip to content

Commit

Permalink
Merge pull request #33 from factly/feat/add_pref_logs
Browse files Browse the repository at this point in the history
add pref logs
  • Loading branch information
paul-tharun authored Feb 7, 2024
2 parents ce206ec + fda8abd commit b02968f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions app/utils/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def prefetch_profile(
start_time = time.perf_counter()
dataframe = get_dataframe(url)
logger.info(f"Prefetching Profile for: {url}")
fetch_time = time.perf_counter() - start_time
logger.info(f"Time taken to fetch the dataset: {fetch_time:0.4f} seconds")
fetch_end = time.perf_counter()

if dataframe.shape[0] < 100:
logger.info(f"Dataset has less than 100 rows: {dataframe.shape[0]}")
Expand All @@ -51,20 +50,25 @@ def prefetch_profile(
profile_segment = ProfileSegments(profile, columns=list(dataframe.columns))

description = profile_segment.description()
profile_time = time.perf_counter() - fetch_time
profile_end = time.perf_counter()
# Add `url` to the description before saving to MongoDB
description["url"] = url
description["trigger_id"] = trigger_id
logger.info(
f"Time taken to generate the profile: {profile_time:0.4f} seconds"
)

# Upsert a json-encoded description into MongoDB
sync_profiles_collection.update_one(
{"url": url}, {"$set": jsonable_encoder(description)}, upsert=True
)
logger.info(f"Profile Prefetched for: {url}")
upsert_time = time.perf_counter() - profile_time
upsert_end = time.perf_counter()

fetch_time = fetch_end - start_time
profile_time = profile_end - fetch_end
upsert_time = upsert_end - profile_end
logger.info(f"Time taken to fetch the dataset: {fetch_time:0.4f} seconds")
logger.info(
f"Time taken to generate the profile: {profile_time:0.4f} seconds"
)
logger.info(
f"Time taken to upsert the profile: {upsert_time:0.4f} seconds"
)
Expand Down

0 comments on commit b02968f

Please sign in to comment.