Bug fixes of training
This commit is contained in:
@@ -494,6 +494,75 @@ class ExternalServiceClient(BaseServiceClient):
|
||||
# POI (POINT OF INTEREST) DATA
|
||||
# ================================================================
|
||||
|
||||
async def detect_poi_for_tenant(
|
||||
self,
|
||||
tenant_id: str,
|
||||
latitude: float,
|
||||
longitude: float,
|
||||
force_refresh: bool = False
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Detect POIs for a tenant's location and generate ML features for forecasting.
|
||||
|
||||
With the new tenant-based architecture:
|
||||
- Gateway receives at: /api/v1/tenants/{tenant_id}/external/poi-context/detect
|
||||
- Gateway proxies to external service at: /api/v1/tenants/{tenant_id}/poi-context/detect
|
||||
- This client calls: poi-context/detect (base client automatically constructs with tenant)
|
||||
|
||||
This triggers POI detection using Overpass API and calculates ML features
|
||||
for demand forecasting.
|
||||
|
||||
Args:
|
||||
tenant_id: Tenant ID
|
||||
latitude: Latitude of the bakery location
|
||||
longitude: Longitude of the bakery location
|
||||
force_refresh: Whether to force refresh even if POI context exists
|
||||
|
||||
Returns:
|
||||
Dict with POI detection results including:
|
||||
- ml_features: Dict of POI features for ML models (e.g., poi_retail_total_count)
|
||||
- poi_detection_results: Full detection results
|
||||
- location: Latitude/longitude
|
||||
- total_pois_detected: Count of POIs
|
||||
"""
|
||||
logger.info(
|
||||
"Detecting POIs for tenant",
|
||||
tenant_id=tenant_id,
|
||||
location=(latitude, longitude),
|
||||
force_refresh=force_refresh
|
||||
)
|
||||
|
||||
params = {
|
||||
"latitude": latitude,
|
||||
"longitude": longitude,
|
||||
"force_refresh": force_refresh
|
||||
}
|
||||
|
||||
# Updated endpoint path to follow tenant-based pattern: external/poi-context/detect
|
||||
result = await self._make_request(
|
||||
"POST",
|
||||
"external/poi-context/detect", # Path will become /api/v1/tenants/{tenant_id}/external/poi-context/detect by base client
|
||||
tenant_id=tenant_id, # Pass tenant_id to include in headers and path construction
|
||||
params=params,
|
||||
timeout=60.0 # POI detection can take longer
|
||||
)
|
||||
|
||||
if result:
|
||||
poi_context = result.get("poi_context", {})
|
||||
ml_features = poi_context.get("ml_features", {})
|
||||
|
||||
logger.info(
|
||||
"POI detection completed successfully",
|
||||
tenant_id=tenant_id,
|
||||
total_pois=poi_context.get("total_pois_detected", 0),
|
||||
ml_features_count=len(ml_features),
|
||||
source=result.get("source", "unknown")
|
||||
)
|
||||
return result
|
||||
else:
|
||||
logger.warning("POI detection failed for tenant", tenant_id=tenant_id)
|
||||
return None
|
||||
|
||||
async def get_poi_context(
|
||||
self,
|
||||
tenant_id: str
|
||||
@@ -504,7 +573,7 @@ class ExternalServiceClient(BaseServiceClient):
|
||||
With the new tenant-based architecture:
|
||||
- Gateway receives at: /api/v1/tenants/{tenant_id}/external/poi-context
|
||||
- Gateway proxies to external service at: /api/v1/tenants/{tenant_id}/poi-context
|
||||
- This client calls: /tenants/{tenant_id}/poi-context
|
||||
- This client calls: poi-context (base client automatically constructs with tenant)
|
||||
|
||||
This retrieves stored POI detection results and calculated ML features
|
||||
that should be included in demand forecasting predictions.
|
||||
@@ -521,11 +590,11 @@ class ExternalServiceClient(BaseServiceClient):
|
||||
"""
|
||||
logger.info("Fetching POI context for forecasting", tenant_id=tenant_id)
|
||||
|
||||
# Updated endpoint path to follow tenant-based pattern: /tenants/{tenant_id}/poi-context
|
||||
# Updated endpoint path to follow tenant-based pattern: external/poi-context
|
||||
result = await self._make_request(
|
||||
"GET",
|
||||
f"tenants/{tenant_id}/poi-context", # Updated path: /tenants/{tenant_id}/poi-context
|
||||
tenant_id=tenant_id, # Pass tenant_id to include in headers for authentication
|
||||
"external/poi-context", # Path will become /api/v1/tenants/{tenant_id}/external/poi-context by base client
|
||||
tenant_id=tenant_id, # Pass tenant_id to include in headers and path construction
|
||||
timeout=5.0
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user