Spaces:
Runtime error
Runtime error
Update utils2.py
Browse files
utils2.py
CHANGED
|
@@ -88,7 +88,7 @@ from google.type import latlng_pb2
|
|
| 88 |
import asyncio
|
| 89 |
|
| 90 |
|
| 91 |
-
async def compute_places_count_with_api_key(api_key, lat, lng, radius,
|
| 92 |
try:
|
| 93 |
client = areainsights_v1.AreaInsightsAsyncClient(
|
| 94 |
client_options={"api_key": api_key}
|
|
@@ -104,8 +104,7 @@ async def compute_places_count_with_api_key(api_key, lat, lng, radius, place_typ
|
|
| 104 |
|
| 105 |
# 2. Define the place type filter
|
| 106 |
type_filter = areainsights_v1.TypeFilter(
|
| 107 |
-
|
| 108 |
-
included_types=place
|
| 109 |
)
|
| 110 |
|
| 111 |
# 3. Assemble the main request body
|
|
@@ -137,13 +136,13 @@ def compute_features(candidate_point, api_key, radius=5000):
|
|
| 137 |
'category_diversity':0
|
| 138 |
}
|
| 139 |
|
| 140 |
-
for i,
|
| 141 |
total_count = asyncio.run(compute_places_count_with_api_key(
|
| 142 |
api_key,
|
| 143 |
lat,
|
| 144 |
lon,
|
| 145 |
radius,
|
| 146 |
-
|
| 147 |
))
|
| 148 |
|
| 149 |
features[f'num_{DATASET_COLUMNS[i]}'] = total_count
|
|
@@ -164,4 +163,6 @@ def compute_features(candidate_point, api_key, radius=5000):
|
|
| 164 |
'category_diversity': sum(bool(v) for v in features.values())
|
| 165 |
})
|
| 166 |
|
|
|
|
|
|
|
| 167 |
return features
|
|
|
|
| 88 |
import asyncio
|
| 89 |
|
| 90 |
|
| 91 |
+
async def compute_places_count_with_api_key(api_key, lat, lng, radius, places):
|
| 92 |
try:
|
| 93 |
client = areainsights_v1.AreaInsightsAsyncClient(
|
| 94 |
client_options={"api_key": api_key}
|
|
|
|
| 104 |
|
| 105 |
# 2. Define the place type filter
|
| 106 |
type_filter = areainsights_v1.TypeFilter(
|
| 107 |
+
included_types=places
|
|
|
|
| 108 |
)
|
| 109 |
|
| 110 |
# 3. Assemble the main request body
|
|
|
|
| 136 |
'category_diversity':0
|
| 137 |
}
|
| 138 |
|
| 139 |
+
for i,places in enumerate(GOOGLE_PLACE_TYPE_MAPPING):
|
| 140 |
total_count = asyncio.run(compute_places_count_with_api_key(
|
| 141 |
api_key,
|
| 142 |
lat,
|
| 143 |
lon,
|
| 144 |
radius,
|
| 145 |
+
places
|
| 146 |
))
|
| 147 |
|
| 148 |
features[f'num_{DATASET_COLUMNS[i]}'] = total_count
|
|
|
|
| 163 |
'category_diversity': sum(bool(v) for v in features.values())
|
| 164 |
})
|
| 165 |
|
| 166 |
+
print(features)
|
| 167 |
+
|
| 168 |
return features
|