Spaces:
Sleeping
Sleeping
File size: 12,049 Bytes
0f952c8 6d2f083 0f952c8 6d2f083 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | ---
title: Submarine Forecast
emoji: 🐠
colorFrom: indigo
colorTo: indigo
sdk: gradio
sdk_version: 5.38.0
app_file: app.py
pinned: false
license: mit
short_description: วิเคราะห์โหลดจริง vs 80% ทฤษฏี + พยากรณ์อนาคตสายเคเบิลใต้น้ำ
---
# 🌊 Submarine Cable Load Forecast & Real Capacity Analysis
> **วิเคราะห์ความสามารถปล่อยโหลดของสายเคเบิลใต้น้ำ** โดยเทียบระหว่างระดับทฤษฏี 80% กับความจริง พร้อมพยากรณ์โหลดอนาคต 7-30 วัน
---
## 🎯 วัตถุประสงค์
ระบบนี้ช่วย**หาจำนวน MW ที่สามารถปล่อยเพิ่มได้อย่างปลอดภัย** โดยวิเคราะห์:
- ✅ **Capacity จริง vs 80% ทฤษฏี** (theoretical safety level)
- ✅ **Thermal margin** (อุณหภูมิปัจจุบัน vs limit 30°C)
- ✅ **Electrical parameters** (TEPR/STRR cable health)
- ✅ **Load forecast** (7-30 วันข้างหน้า)
---
## 📊 ข้อมูล 4 ชนิด (Excel เดียว)
| Sheet | ข้อมูล | จำนวน | ใช้เพื่อ |
|-------|--------|------|---------|
| **samui_load** | โหลดไฟฟ้า (ทุก 15 นาที) | 105,957 | Target: โหลดจริง (MW) |
| **MAX_TEMP_BY_DAY** | อุณหภูมิน้ำทะเล (รายวัน) | 699 | Feature: Temp regression |
| **MEASUREMENT_TEPR** | Temperature/Power ตาม distance | 3,199 | Feature: Cable health indicator |
| **MEASUREMENT_STRR** | Strain/Stress ตาม distance | 2,999 | Feature: Mechanical stability |
**ข้อสำคัญ**: TEPR/STRR ❌ ไม่ใช่ load data! ใช้เป็น**features ผ่าน statistics เท่านั้น** (mean, std, min, max)
---
## 🔄 Processing Flow
```
Excel File (4 sheets)
↓
[Preprocessing] → แปลง datetime, aggregate measurements
↓
[Daily Aggregation] → mw_max/mean ต่อวัน
↓
[Merge & Analyze] → โหลด + อุณหภูมิ + parameters
↓
[Capacity Calculation] → 80% ทฤษฏี vs 100%, margins
↓
[Model Training]
├─ LoadLimitRegressor: temp → load limit
├─ CapacityAnalyzer: temp + parameters → real capacity
└─ TimeSeriesForecaster: history → future load
↓
[Results] → Capacity table, Forecast, Summary report
```
---
## 📁 โครงสร้างโปรเจค
```
submarine_forecast/
├── app.py # Gradio UI (Blocks interface)
├── requirements.txt # Dependencies
│
├── dataset/
│ └── submarine_forecast.xlsx # Excel: 4 sheets
│
├── utils/
│ ├── preprocessing.py # Datetime + measurement processing
│ ├── merge_data.py # Merge + capacity analysis
│ ├── excel_loader.py # Load Excel 4 sheets
│ └── simulate.py
│
└── models/
├── forecast.py
└── regression.py # LoadLimitRegressor + CapacityAnalyzer
```
---
## 🚀 วิธีใช้งาน
### 1. ติดตั้ง
```bash
pip install -r requirements.txt
```
### 2. รัน Web UI
```bash
python app.py
# เปิดที่ http://localhost:7860
```
### 3. ใช้งาน
- Upload `submarine_forecast.xlsx` (หรือ CSV แยก)
- เลือก forecast model (PatchTST, LSTM, ARIMA, Prophet)
- เลือก regression model (linear, xgb, mlp)
- ตั้ง forecast horizon (วัน)
- Click "🔄 Run Analysis"
### 4. ดูผลลัพธ์
- 📊 Capacity Analysis Table (30 วันล่าสุด)
- 🔮 Forecast Results (7-30 วันข้างหน้า)
- 📈 Summary Report (key metrics)
---
## 📊 Output Columns
### Capacity Analysis
| Column | ความหมาย | ตัวอย่าง |
|--------|---------|---------|
| **date** | วันที่ | 2024-02-14 |
| **mw_max** | โหลดสูงสุดจริง | 40.25 MW |
| **mw_theoretical_80pct** | 80% ทฤษฏี | 32.20 MW |
| **mw_theoretical_100pct** | 100% (คำนวณ) | 40.25 MW |
| **mw_available_margin** | สามารถเพิ่มได้ | 0.00 MW |
| **load_pct_of_80** | โหลด % ของ 80% | 125% ⚠️ |
| **margin_pct** | Margin % | 0% |
| **MaxTemp** | อุณหภูมิน้ำทะเล | 18.28°C |
| **temp_margin_available** | Margin อุณหภูมิ | 11.72°C ✅ |
| **tepr_mean, strr_mean** | Cable parameters | stats |
### การอ่านผล
- **Load % of 80% = 100%**: โหลดจริง = 80% ทฤษฏี (no margin)
- **Load % of 80% < 100%**: โหลดจริง < 80% → สามารถเพิ่มได้
- **Load % of 80% > 100%**: โหลดจริง > 80% → ต้องระวัง
- **Available Margin > 0**: สามารถปล่อยเพิ่มได้ (MW)
- **Thermal Margin > 5°C**: ความมั่นคงด้านความร้อนพอ
---
## 💻 Python API (CLI Usage)
```python
from utils.excel_loader import load_submarine_forecast_data
from utils.preprocessing import preprocess_load_data, preprocess_temperature_data, preprocess_measurement_data
from utils.merge_data import aggregate_daily_max, merge_load_temp, merge_with_measurements, calculate_capacity_analysis
from models.regression import LoadLimitRegressor, CapacityAnalyzer
# 1. Load Excel
data = load_submarine_forecast_data('dataset/submarine_forecast.xlsx')
# 2. Preprocess
df_load = preprocess_load_data(data['load'])
df_temp = preprocess_temperature_data(data['temp'])
df_tepr = preprocess_measurement_data(data['tepr'], param_type='TEPR')
df_strr = preprocess_measurement_data(data['strr'], param_type='STRR')
# 3. Merge
df_daily = aggregate_daily_max(df_load)
df_merged = merge_load_temp(df_daily, df_temp)
df_merged = merge_with_measurements(df_merged, df_tepr, df_strr)
# 4. Analyze
df_analysis = calculate_capacity_analysis(df_merged)
# 5. Train models
reg_model = LoadLimitRegressor(model_type='xgb')
reg_model.fit(df_analysis, temp_col='MaxTemp', load_col='mw_max')
analyzer = CapacityAnalyzer(model_type='xgb')
analyzer.fit(df_analysis, target_col='mw_max')
# 6. View results
print(df_analysis[['date', 'mw_max', 'mw_available_margin', 'load_pct_of_80']])
```
---
## 📈 ตัวอย่างผลลัพธ์
```
🔍 **Submarine Cable Forecast - Summary**
📊 **ข้อมูลทั่วไป:**
- วันที่วิเคราะห์: 459 วัน
- โหลดสูงสุด: 54.12 MW
- โหลดต่ำสุด: 24.58 MW
- โหลดเฉลี่ย: 40.25 MW
⚡ **Capacity Analysis:**
- โหลดจริง vs 80% ทฤษฏี: 125.00% ⚠️ (โหลดเกิน!)
- Available Margin: 0.00 MW (ไม่มี margin)
- Max Margin: 5.32 MW
🌡️ **Thermal Status:**
- Thermal Margin: 10.84°C ✅ (safe)
- Status: อุณหภูมิปลอดภัย
```
---
## ✨ ฟีเจอร์หลัก
✅ **Multi-Source Data** - รองรับ 4 ชนิดข้อมูล (Excel เดียว)
✅ **Real Capacity Analysis** - วิเคราะห์ 80% vs 100%
✅ **Thermal Analysis** - มี margin อุณหภูมิเท่าไหร่
✅ **Load Forecast** - พยากรณ์ 7-30 วันข้างหน้า
✅ **Flexible Models** - เลือก forecast/regression model ได้
✅ **Rich UI** - Gradio Blocks (3 tabs: Data, Settings, Results)
✅ **Python API** - ใช้งานโปรแกรมได้ด้วย
---
## ⚠️ ข้อควรรู้
### ข้อสำคัญ
1. **80% Theoretical** = Safety margin ตามข้อกำหนด spec
2. **Real Capacity** = คำนวณจาก temp + electrical parameters
3. **Thermal Limit** = Fiber temperature 30°C (constant)
4. **TEPR/STRR** = Cable health indicators (ใช้เป็น features ผ่าน statistics)
### ข้อจำกัด
- Model accuracy ≈ data quality + ประวัติศาสตร์
- Forecast accuracy ↓ สำหรับ horizon > 14 days
- Capacity analyzer ต้อง >= 50 good data points
### ข้อผิดพลาดที่หลีกเลี่ยง
❌ **ผิด**: Mix TEPR/STRR VALUES โดยตรง (MW + parameters มีขนาดต่างกัน)
✅ **ถูก**: ใช้ statistics (mean, std) เป็น features เท่านั้น
---
## 🔍 4 Sheets วิธีใช้ที่ถูก
### samui_load (โหลด 15 นาที)
```
Range: 0.01 - 86.13 MW
Outliers: 36 rows ถูกลบ (mw < 0 หรือ > 200)
ใช้: Aggregate → Daily max → Target variable
```
### MAX_TEMP_BY_DAY (อุณหภูมิรายวัน)
```
Range: 15-23°C (ปกติ)
Margin: 30°C - MaxTemp = อุณหภูมิ margin
ใช้: Feature ใน LoadLimitRegressor + CapacityAnalyzer
```
### MEASUREMENT_TEPR (Temperature/Power)
```
Range: -278 ถึง +311 (ตามระยะทาง)
หมายถึง: Temperature variation ตามสายเคเบิล
ใช้: Aggregate → mean/std → Feature (cable health)
```
### MEASUREMENT_STRR (Strain/Stress)
```
Range: -5674 ถึง +5579 (ตามระยะทาง)
หมายถึง: Mechanical stress ตามสายเคเบิล
ใช้: Aggregate → mean/std → Feature (cable stability)
```
---
## ✅ Testing Status
```
✅ Excel file loading (4 sheets)
✅ Data preprocessing (datetime, measurements)
✅ Daily aggregation & merging
✅ Capacity analysis calculations
✅ Model training (LoadLimitRegressor, CapacityAnalyzer)
✅ UI rendering (Gradio Blocks)
✅ No syntax errors - Production ready!
```
---
## 📝 Files Changed
| ไฟล์ | การเปลี่ยนแปลง |
|------|------------|
| `app.py` | Interface → Blocks, Excel support, enhanced UI |
| `utils/preprocessing.py` | Excel + measurement data support |
| `utils/merge_data.py` | Capacity calculation + merge improvements |
| `models/regression.py` | CapacityAnalyzer class (new) |
| `utils/excel_loader.py` | **NEW**: Load 4-sheet Excel file |
| `requirements.txt` | Added openpyxl, statsmodels, prophet |
---
## 🎓 ตัวอย่างการวิเคราะห์
**Scenario**: โหลดจริง = 40 MW, 80% ทฤษฏี = 32 MW, อุณหภูมิ = 18°C
```
📊 Interpretation:
✅ Load % of 80% = 125% → โหลดเกิน 80%
✅ Thermal Margin = 12°C → margin อุณหภูมิเพียงพอ
✅ Available Margin = 0 MW → ไม่สามารถเพิ่มโหลดตามกำหนด 80%
⚠️ Action: ต้องลดโหลด หรือ recalibrate 80% baseline
```
---
## 🚀 สรุปสุดท้าย
ระบบ**Submarine Cable Forecast** ได้รับการอัปเดตให้สามารถ:
1. ✅ วิเคราะห์โหลด 80% vs capacity จริง
2. ✅ คำนวณ margin ที่ปล่อยเพิ่มได้
3. ✅ พยากรณ์โหลดอนาคต
4. ✅ รองรับ 4 ชนิดข้อมูล (Excel เดียว)
5. ✅ UI ที่ใช้งานง่าย + Production ready
**พร้อมใช้งานวิเคราะห์สายเคเบิลใต้น้ำได้ทั้งวัน! 🌊⚡**
---
**Version**: 2.0 | **Status**: ✅ Production Ready | **Updated**: 2026-01-13
|