Skip to content

Commit

Permalink
Adds logging for autocomplete responses. (datacommonsorg#4678)
Browse files Browse the repository at this point in the history
Logs the response count for autocompletion. Staging is not showing any
responses. Would like to better understand where the breakdown is
occurring.
  • Loading branch information
gmechali authored and hqpho committed Oct 29, 2024
1 parent 0deab30 commit f1d4b1b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/routes/shared_api/autocomplete/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import json
import logging

from flask import Blueprint
from flask import jsonify
Expand Down Expand Up @@ -51,6 +52,8 @@ def autocomplete():
place_id_to_dcid = []
if place_ids:
place_id_to_dcid = json.loads(findplacedcid(place_ids).data)
logging.info("[Place_Autocomplete] Found %d place ID to DCID mappings.",
len(place_id_to_dcid))

final_predictions = []
for prediction in prediction_responses:
Expand All @@ -61,5 +64,8 @@ def autocomplete():
matched_query=prediction.matched_query,
dcid=place_id_to_dcid[prediction.place_id])
final_predictions.append(current_prediction)
logging.info(
"[Place_Autocomplete] Returning a total of %d place predictions.",
len(final_predictions))

return jsonify(AutoCompleteApiResponse(predictions=final_predictions))
3 changes: 3 additions & 0 deletions server/routes/shared_api/autocomplete/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import json
import logging
import re
from typing import Dict, List
from urllib.parse import urlencode
Expand Down Expand Up @@ -122,6 +123,8 @@ def predict(queries: List[str], lang: str) -> List[ScoredPrediction]:
all_responses.append(scored_prediction)

all_responses.sort(key=get_score)
logging.info("[Place_Autocomplete] Received %d total place predictions.",
len(all_responses))

responses = []
place_ids = set()
Expand Down

0 comments on commit f1d4b1b

Please sign in to comment.