diff --git a/UI/src/views/prediction/ProductPredictionView.vue b/UI/src/views/prediction/ProductPredictionView.vue index 279d38f..ad19c34 100644 --- a/UI/src/views/prediction/ProductPredictionView.vue +++ b/UI/src/views/prediction/ProductPredictionView.vue @@ -44,25 +44,7 @@ - - - - - - - - + - + - + - + -
- - - 开始预测 - +
+

📦 可用模型版本

+ + + + + + + + + + + + + + + + + + +
@@ -162,9 +172,7 @@ const form = reactive({ analyze_result: true }) -const canPredict = computed(() => { - return form.product_id && form.model_type && form.version -}) + const fetchModelTypes = async () => { try { @@ -188,9 +196,7 @@ const fetchAvailableVersions = async () => { const response = await axios.get(url) if (response.data.status === 'success') { availableVersions.value = response.data.data.versions || [] - if (response.data.data.latest_version) { - form.version = response.data.data.latest_version - } + // No longer setting a default version, the user will choose from the list. } } catch (error) { availableVersions.value = [] @@ -203,26 +209,29 @@ const handleProductChange = () => { form.model_type = '' form.version = '' availableVersions.value = [] + predictionResult.value = null; } const handleModelTypeChange = () => { form.version = '' + availableVersions.value = [] + predictionResult.value = null; fetchAvailableVersions() } -const startPrediction = async () => { +const startPrediction = async (version) => { + form.version = version; // Keep track of which version is running try { predicting.value = true const payload = { product_id: form.product_id, model_type: form.model_type, - version: form.version, + version: version, future_days: form.future_days, history_lookback_days: form.history_lookback_days, start_date: form.start_date, include_visualization: form.analyze_result, } - // Corrected API endpoint from /api/predict to /api/prediction const response = await axios.post('/api/prediction', payload) if (response.data.status === 'success') { // The backend response may have history_data and prediction_data at the top level @@ -382,13 +391,14 @@ watch([() => form.product_id, () => form.model_type], () => { .model-selection-section h4 { margin-bottom: 16px; } -.prediction-actions { - display: flex; - justify-content: center; +.versions-list-section { margin-top: 20px; padding-top: 20px; border-top: 1px solid #ebeef5; } +.versions-list-section h4 { + margin-bottom: 16px; +} .prediction-chart { margin-top: 20px; } diff --git a/prediction_history.db b/prediction_history.db index 6544b32..1f58e6f 100644 Binary files a/prediction_history.db and b/prediction_history.db differ diff --git a/server/api.py b/server/api.py index 58f7808..7ce4ff8 100644 --- a/server/api.py +++ b/server/api.py @@ -3536,15 +3536,17 @@ def get_model_versions_api(product_id, model_type): result = model_manager.list_models(product_id=product_id, model_type=model_type) models = result.get('models', []) - versions = sorted(list(set(m['version'] for m in models)), key=lambda v: (v != 'best', v)) - latest_version = versions[0] if versions else None + # Sort models: 'best' version first, then by creation date descending + models.sort(key=lambda x: (x.get('version') != 'best', x.get('created_at', '')), reverse=True) + + latest_version = models[0]['version'] if models else None return jsonify({ "status": "success", "data": { "product_id": product_id, "model_type": model_type, - "versions": versions, + "versions": models, # Return the full list of model details "latest_version": latest_version } })