---
name: pv-prediction-model
description: PV power prediction model skill, providing functions to obtain weather information, list PV power prediction models, load models, perform PV power prediction, and calculate model evaluation parameters (MAE, RMSE, R², MAPE). Supports manual training for a single station, automatically generates HTML reports after evaluation, and requires secondary parameter confirmation before training.
compatibility: Requires Python 3.x and access to API http://47.96.16.84:5006
return_format_specification:
  preview_training_params:
    format: "&**&key1=value1|key2=value2|...|keyN=valueN&**&"
    description: "Parameter preview return format, using | as a separator, wrapped in &**&, JSON format is NOT used"
    example: "&**&stations=P2413|learning_rate=0.001|batch_size=64|max_epochs=100|hidden_dim=64|dropout=0.1|patience=15|train_ratio=0.7|start_time=2024-12-19 00:00:00|end_time=2025-08-10 23:45:00&**&"
  evaluate_model:
    format: "@@@@@<report_address>@@@@@"
    description: "Evaluation report return format, using @@@@@ to wrap the report address"
    example: "@@@@@/skills/report-generator/output/report_1234567890.html@@@@@"
metadata:
  author: Manus AI
---

# 【PV Prediction Model】

This skill is used for the complete evaluation process and single-station training function of photovoltaic (PV) power generation prediction models. It provides functions to obtain weather information, model lists, load models, perform PV power prediction, and calculate model evaluation parameters.

---

## ⚠️ Critical Rules

- MUST: For model evaluation, model listing, prediction results, data comparison, and weather data, you must call `report-generator` to generate an HTML report.
- MUST: Before training, you must call `handle_training_request.py` to preview all parameters and perform secondary parameter confirmation.
- MUST: The training function must be triggered manually through conversation and will not be executed automatically.
- MUST: The system will only start training after the user explicitly expresses the intention to confirm (e.g., "Confirm parameters, start training").
- NEVER: The parameter preview return format strictly prohibits the use of JSON; it must strictly be `&**&key1=value1|key2=value2|...&**&` (using | as a separator and wrapped in &**&).

---

## When to Use

### Handled by this skill

- User asks about PV power generation prediction models, model evaluation, or calculating model parameters.
- User requests to list all PV power prediction models.
- User requests to execute PV power prediction or compare historical data with predicted data.
- User requests to obtain weather forecast data.
- User wants to perform model training for a single station.

### Not handled by this skill (Hand over to other skills)

- Power load forecasting related tasks → Hand over to `【load-forecasting】`
- Pure report generation and formatting tasks (non-PV data) → Hand over to `【report-generator】`

---

## How to Execute

> Execute the following steps in order. For each step, you MUST send a progress message before running the command.

### Step 1: Select Template

**FIRST**, send this message to the user:

`【开始分析】正在理解需求，匹配数据视图与展示模板...`

**THEN**, run:

```bash
cd /workspace/skills/report-generator && \
python3 scripts/step1_select.py --query "{{USER_QUERY}}" --data "{}"
```

*Replace `{{USER_QUERY}}` with the user's original question.*

Output example:

```json
{
  "status": "success",
  "template_name": "dataTable",
  "reason": "模型列表适合用表格形式展示"
}
```

Pass to next step: `template_name` → `--template` in Step 3.

---

### Step 2: Execute Action

**FIRST**, send this message to the user:

`【数据处理】正在执行操作并获取数据...`

**THEN**, run the appropriate command based on user request:

**Get model list:**
```bash
python scripts/predict_and_evaluate.py --action list_models
```

**Evaluate model:**
```bash
python scripts/predict_and_evaluate.py --action evaluate_model --model_id "{{MODEL_ID}}"
```

**Preview training parameters (secondary confirmation):**
```bash
python scripts/handle_training_request.py --station_id "{{STATION_ID}}"
```

**Start training and monitor progress (ONLY after user confirmation):**
```bash
python scripts/train_station.py --action train_and_monitor --station_id "{{STATION_ID}}"
```

**Compare historical and predicted data:**
```bash
python scripts/compare_prediction.py --target_date "{{TARGET_DATE}}" --station_id "{{STATION_ID}}"
```

**Get weather forecast data:**
```bash
python scripts/get_weather_forecast.py --station_name "{{STATION_NAME}}" --forecast_days "{{DAYS}}"
```

**After Step 2, MUST immediately show the user:**
- Explanation of intermediate results, such as the retrieved model list, evaluation metrics, or parameter preview.

---

### Step 3: Render HTML Report

> Note: Parameter preview and starting training steps do not require report generation.

**FIRST**, send this message to the user:

`【报告生成】正在将结果渲染为可视化报告...`

**THEN**, run:

```bash
cd /workspace/skills/report-generator && \
python3 scripts/step2_render.py \
  --query "{{USER_QUERY}}" \
  --template "{{template_name from Step 1}}" \
  --data "{Output JSON data from Step 2}"
```

Output example:

```json
{
  "status": "success",
  "message": "Report generated successfully",
  "template": "dataTable",
  "address": "/skills/report-generator/output/report_1773642266.html",
  "summary": "共获取到2个光伏功率预测模型，其中best_model为最优模型。"
}
```

---

## Usage Examples

### Example 1: List all PV power prediction models and generate a report

**User Query**: "List all PV power prediction models"

**Execution Process**:
1. **Step 1**: Call `step1_select.py --query "列出所有光伏功率预测模型" --data "{}"` to get the template name `dataTable`.
2. **Step 2**: Call `predict_and_evaluate.py --action list_models` to get the model list.
3. **Step 3**: Call `step2_render.py --query "列出所有光伏功率预测模型" --template "dataTable" --data "{模型列表数据JSON}"` to generate the final report.

**Final Reply**:
Based on the `summary` returned in Step 3, organize the final reply.
```
@@@@@/skills/report-generator/output/report_1773642266.html@@@@@

#####%查看详细数据%￥点击上方链接查看完整的数据分析报告￥ %继续深入分析%￥基于当前数据进行更深度的挖掘￥ %导出报告%￥将当前报告导出为PDF或图片格式￥#####
```

### Example 2: Evaluate a PV power prediction model and generate a report

**User Query**: "Evaluate the performance of best_model"

**Execution Process**:
1. **Step 1**: Call `step1_select.py --query "评估光伏功率预测模型" --data "{\"model_id\": \"best_model\"}"` to get the template name `dataTable`.
2. **Step 2**: Call `predict_and_evaluate.py --action evaluate_model --model_id best_model` to get prediction and evaluation data.
3. **Step 3**: Call `step2_render.py --query "评估光伏功率预测模型" --template "dataTable" --data "{预测和评估数据JSON}"` to generate the final report containing evaluation metrics.

### Example 3: Preview training parameters (secondary confirmation)

**User Query**: "I want to train a model for station P1154"

**Execution Process**:
1. **Step 2**: Call `handle_training_request.py --station_id P1154 --base_model_id P2113_20260324_150417 --learning_rate 0.001 --batch_size 64`.
2. **Final Reply**: Return the formatted string like `&**&stations=P1154|learning_rate=0.001|batch_size=64|...&**&` directly. The system framework will automatically convert it into a table to display to the user and wait for confirmation.

### Example 4: Start training after parameter confirmation and generate a report

**User Query**: "Confirm parameters, start training" (User action after Example 3)

**Execution Process**:
1. **Step 1**: Call `step1_select.py --query "训练光伏功率预测模型" --data "{\"station_id\": \"P1154\"}"` to get the template name `lineChart`.
2. **Step 2**: Call `train_station.py --action train_and_monitor --station_id P1154 --base_model_id P2113_20260324_150417 --learning_rate 0.001 --batch_size 64` to start training and monitor progress.
3. **Step 3**: Call `step2_render.py --query "训练光伏功率预测模型" --template "lineChart" --data "{训练结果数据JSON}"` to generate the final report containing the training loss curve.

### Example 5: Compare historical data with PV power prediction data and generate a report

**User Query**: "Compare historical and predicted data for station P2413 on 2026-03-30"

**Execution Process**:
1. **Step 2**: Call `compare_prediction.py --target_date "2026-03-30" --station_id P2413` to get the comparison data.

### Example 6: Get weather forecast data and generate a report

**User Query**: "Get weather forecast data for station P2413 for the next 2 days"

**Execution Process**:
1. **Step 2**: Call `get_weather_forecast.py --station_name P2413 --forecast_days 2` to get the weather data.

---

## Final Reply Format

Your final reply MUST have exactly three parts:

**Part 1 — Data Analysis Summary (Mandatory, cannot be omitted)**
Based on the `summary` field from the final script output, write a genuine data analysis in the user's language.
**DO NOT** just write "The report has been generated"; you must actually analyze the data content.
⚠️ CRITICAL: Write a brand-new analysis every time. **DO NOT reuse text from previous replies.**

**Part 2 — Address Tag (Second to last line, fixed format)**
```
@@@@@/skills/report-generator/output/report_1773642266.html@@@@@
```
⚠️ Copy the `address` field value EXACTLY from script output. NO spaces around `@@@@@`.

**Part 3 — Suggestions Tag (Last line, fixed format)**
```
#####%查看详细数据%￥点击上方链接查看完整的数据分析报告￥ %继续深入分析%￥基于当前数据进行更深度的挖掘￥ %导出报告%￥将当前报告导出为PDF或图片格式￥#####
```

---

## Gotchas

- Confusion between multi-station and single-station: Multiple stations can be evaluated simultaneously, but training must be performed for a single station.
- Skipping parameter confirmation: It is strictly prohibited to skip the parameter confirmation step and start training directly; you must wait for explicit user consent.
- Report format error: The report address format must strictly follow `@@@@@<report_address>@@@@@`.

---

## Bundled Resources

- `scripts/predict_and_evaluate.py` — Executes PV power prediction model list retrieval and evaluation calculations.
- `scripts/handle_training_request.py` — Handles user training requests and previews training parameters.
- `scripts/train_station.py` — Performs PV power prediction model training for a single station.
- `scripts/compare_prediction.py` — Compares historical data and predicted data for a specified date.
- `scripts/get_weather_forecast.py` — Gets weather forecast data.

> Read these files only when debugging. Normal execution does not require manual inspection.

---

## Error Handling

- `"status": "error"` → Inform the user "Service is temporarily unavailable, please try again later", and output the content of the `message` field.
- API call failure → Check the connection status of the API service `http://47.96.16.84:5006`.
- User refuses to confirm parameters → Cancel the training task and ask the user if they need to adjust the parameters.
