Start fixing forecast service API 7
This commit is contained in:
@@ -563,31 +563,73 @@ echo ""
|
||||
# STEP 5: ONBOARDING COMPLETION (DASHBOARD ACCESS)
|
||||
# =================================================================
|
||||
|
||||
echo -e "${STEP_ICONS[4]} ${PURPLE}STEP 5: ONBOARDING COMPLETION${NC}"
|
||||
echo "Simulating completion and dashboard access"
|
||||
echo ""
|
||||
|
||||
log_step "5.1. Testing basic dashboard functionality"
|
||||
|
||||
# Use a real product name from our CSV for forecasting
|
||||
FIRST_PRODUCT=$(echo "$REAL_PRODUCTS" | sed 's/"//g' | cut -d',' -f1)
|
||||
|
||||
FORECAST_RESPONSE=$(curl -s -X POST "$API_BASE/api/v1/tenants/$TENANT_ID/forecasts/single" \
|
||||
# Get a real product name from CSV (fix the product extraction)
|
||||
FIRST_PRODUCT=$(head -2 "$REAL_CSV_FILE" | tail -1 | cut -d',' -f3 | sed 's/"//g' | head -1)
|
||||
|
||||
if [ -z "$FIRST_PRODUCT" ]; then
|
||||
FIRST_PRODUCT="Pan Integral" # Fallback product name
|
||||
log_warning "Could not extract product from CSV, using fallback: $FIRST_PRODUCT"
|
||||
else
|
||||
log_success "Using product from CSV: $FIRST_PRODUCT"
|
||||
fi
|
||||
|
||||
# CORRECTED forecast request with proper schema
|
||||
FORECAST_REQUEST="{
|
||||
\"product_name\": \"$FIRST_PRODUCT\",
|
||||
\"forecast_date\": \"2025-07-30\",
|
||||
\"forecast_days\": 1,
|
||||
\"location\": \"madrid_centro\",
|
||||
\"confidence_level\": 0.85
|
||||
}"
|
||||
|
||||
echo "Forecast Request:"
|
||||
echo "$FORECAST_REQUEST" | python3 -m json.tool
|
||||
|
||||
# Make the API call
|
||||
FORECAST_RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X POST "$API_BASE/api/v1/tenants/$TENANT_ID/forecasts/single" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-d "{
|
||||
\"product_name\": [\"$FIRST_PRODUCT\"],
|
||||
\"forecast_date\": "2025-11-30",
|
||||
\"forecast_days\": 1,
|
||||
\"date\": \"2025-09-15\",
|
||||
\"location\": \"madrid_centro\",
|
||||
\"confidence_level\": 0.85
|
||||
}")
|
||||
|
||||
if echo "$FORECAST_RESPONSE" | grep -q '"predictions"\|"forecast"'; then
|
||||
log_success "Forecasting service is accessible"
|
||||
-d "$FORECAST_REQUEST")
|
||||
|
||||
# Extract HTTP code and response
|
||||
HTTP_CODE=$(echo "$FORECAST_RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2)
|
||||
FORECAST_RESPONSE=$(echo "$FORECAST_RESPONSE" | sed '/HTTP_CODE:/d')
|
||||
|
||||
echo "Forecast HTTP Status: $HTTP_CODE"
|
||||
echo "Forecast Response:"
|
||||
echo "$FORECAST_RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$FORECAST_RESPONSE"
|
||||
|
||||
# Validate response
|
||||
if [ "$HTTP_CODE" = "200" ]; then
|
||||
if echo "$FORECAST_RESPONSE" | grep -q '"predicted_demand"\|"id"'; then
|
||||
log_success "Forecasting service is working correctly"
|
||||
|
||||
# Extract key values for validation
|
||||
PREDICTED_DEMAND=$(extract_json_field "$FORECAST_RESPONSE" "predicted_demand")
|
||||
CONFIDENCE_LOWER=$(extract_json_field "$FORECAST_RESPONSE" "confidence_lower")
|
||||
CONFIDENCE_UPPER=$(extract_json_field "$FORECAST_RESPONSE" "confidence_upper")
|
||||
|
||||
if [ -n "$PREDICTED_DEMAND" ]; then
|
||||
echo " Predicted Demand: $PREDICTED_DEMAND"
|
||||
echo " Confidence Range: [$CONFIDENCE_LOWER, $CONFIDENCE_UPPER]"
|
||||
fi
|
||||
else
|
||||
log_error "Forecast response missing expected fields"
|
||||
echo "Response: $FORECAST_RESPONSE"
|
||||
fi
|
||||
elif [ "$HTTP_CODE" = "422" ]; then
|
||||
log_error "Forecast request validation failed"
|
||||
echo "Validation errors: $FORECAST_RESPONSE"
|
||||
elif [ "$HTTP_CODE" = "404" ]; then
|
||||
log_warning "Forecast endpoint not found - check API routing"
|
||||
elif [ "$HTTP_CODE" = "500" ]; then
|
||||
log_error "Internal server error in forecasting service"
|
||||
echo "Error details: $FORECAST_RESPONSE"
|
||||
else
|
||||
log_warning "Forecasting may not be ready yet (model training required)"
|
||||
log_warning "Forecasting may not be ready yet (HTTP $HTTP_CODE)"
|
||||
echo "Response: $FORECAST_RESPONSE"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user