Skip to content

Commit 139d9ba

Browse files
committed
Enhance logging
1 parent 3b7ff56 commit 139d9ba

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

functions-python/helpers/utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,21 +254,20 @@ def check_maximum_executions(
254254

255255
trace_service = DatasetTraceService()
256256
trace = trace_service.get_by_execution_and_stable_ids(execution_id, stable_id)
257-
logger.info(f"Dataset trace: {trace}")
258257
executions = len(trace) if trace else 0
259258
logger.info(
260-
f"Dataset executed times={executions}/{maximum_executions} "
259+
f"Function executed times={executions}/{maximum_executions} "
261260
f"in execution=[{execution_id}] "
262261
)
263262

264263
if executions > 0:
265264
if executions >= maximum_executions:
266-
error_message = (
265+
message = (
267266
f"Function already executed maximum times "
268267
f"in execution: [{execution_id}]"
269268
)
270-
logger.error(error_message)
271-
return error_message
269+
logger.warning(message)
270+
return message
272271
return None
273272

274273

functions-python/reverse_geolocation/src/scripts/reverse_geolocation_process_verifier.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,44 @@
2929

3030
feeds = [
3131
{
32-
# 1539 stops, NZ, 1 location
32+
# 0. 1539 stops, NZ, 1 location
3333
"stable_id": "local-test-gbfs-flamingo_auckland",
3434
"station_information_url": "https://data.rideflamingo.com/gbfs/3/auckland/station_information.json",
3535
"vehicle_status_url": "https://data.rideflamingo.com/gbfs/3/auckland/vehicle_status.json",
3636
"data_type": "gbfs",
3737
},
3838
{
39-
# 11777 stops, JP, 241 locations
39+
# 1. 11777 stops, JP, 241 locations
4040
"stable_id": "local-test-gbfs-hellocycling",
4141
"station_information_url": "https://api-public.odpt.org/api/v4/gbfs/hellocycling/station_information.json",
4242
"data_type": "gbfs",
4343
},
4444
{
45-
# 308611, UK aggregated, 225 locations
45+
# 2. 308611, UK aggregated, 225 locations
4646
"stable_id": "local-test-2014",
4747
"stops_url": "https://storage.googleapis.com/mobilitydata-datasets-prod/mdb-2014/"
4848
"mdb-2014-202508120303/extracted/stops.txt",
4949
"data_type": "gtfs",
5050
},
5151
{
52-
# 663 stops, Europe, 334 locations
52+
# 3. 663 stops, Europe, 334 locations
5353
"stable_id": "local-test-1139",
5454
"stops_url": "https://storage.googleapis.com/mobilitydata-datasets-prod/mdb-1139/"
5555
"mdb-1139-202406071559/stops.txt",
5656
"data_type": "gtfs",
5757
},
5858
{
59-
# 10985 stops, Spain, duplicate key error(https://github.com/MobilityData/mobility-feed-api/issues/1289)
59+
# 4. 10985 stops, Spain, duplicate key error(https://github.com/MobilityData/mobility-feed-api/issues/1289)
6060
"stable_id": "local-test-gtfs-mdb-2825",
6161
"stops_url": "https://storage.googleapis.com/mobilitydata-datasets-prod/mdb-2825/"
6262
"mdb-2825-202508181628/extracted/stops.txt",
6363
"data_type": "gtfs",
6464
},
6565
]
66+
run_with_feed_index = (
67+
4 # Set to an integer index to run with a specific feed from the list above
68+
)
69+
6670

6771
# Load environment variables from .env.local
6872
load_dotenv(dotenv_path=".env.local")
@@ -218,7 +222,7 @@ def create_test_data(feed_stable_id: str, feed_dict: Dict, db_session: Session =
218222

219223
strategy = ReverseGeocodingStrategy.PER_POLYGON
220224

221-
feed_dict = feeds[3]
225+
feed_dict = feeds[run_with_feed_index]
222226
feed_stable_id = feed_dict["stable_id"]
223227
# create test data in the database if does not exist
224228
create_test_data(feed_stable_id=feed_stable_id, feed_dict=feed_dict)
@@ -237,7 +241,7 @@ def create_test_data(feed_stable_id: str, feed_dict: Dict, db_session: Session =
237241
"stops_url": f"http://{HOST}:{PORT}/{BUCKET_NAME}/{feed_stable_id}/stops.txt",
238242
"strategy": str(strategy.value),
239243
"data_type": feed_dict["data_type"],
240-
"use_cache": False,
244+
# "use_cache": False,
241245
"public": False,
242246
"maximum_executions": 1000,
243247
}

functions-python/reverse_geolocation/src/strategy_extraction_per_polygon.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def extract_location_aggregates_per_polygon(
7676
batch_size = max(
7777
int(total_stop_count / 20), 0
7878
) # Process ~5% of the total stops in each batch
79+
stop_clustered_total = 0
7980
while not remaining_stops_df.empty:
8081
if (last_seen_count - len(remaining_stops_df)) >= batch_size or len(
8182
remaining_stops_df
@@ -126,6 +127,7 @@ def extract_location_aggregates_per_polygon(
126127
highest.admin_level,
127128
count_before - len(remaining_stops_df),
128129
)
130+
stop_clustered_total += count_before - len(remaining_stops_df)
129131
else:
130132
# If admin_level < locality_admin_level, we assume the polygon is too large to filter points
131133
# directly, so we just use the first point as a representative
@@ -169,4 +171,6 @@ def extract_location_aggregates_per_polygon(
169171
location_aggregates[location_aggregate.group_id] = location_aggregate
170172
# Make sure to commit the changes after processing all points
171173
db_session.commit()
172-
logger.info("Completed processing all points")
174+
logger.info(
175+
"Completed processing all points with clustered total %d", stop_clustered_total
176+
)

0 commit comments

Comments
 (0)