| import numpy as np |
| import pandas as pd |
| from datetime import datetime, timedelta |
|
|
| VEHICLE_IDS = ["EV-FRT-001", "EV-FRT-002", "EV-FRT-003", "EV-LM-004", "EV-LM-005", |
| "EV-BUS-006", "EV-MIN-007", "EV-MIN-008", "EV-CST-009", "EV-CST-010"] |
|
|
| def generate_bms_history(vehicle_id: str, days: int = 365, seed: int = None) -> pd.DataFrame: |
| if seed is not None: |
| np.random.seed(seed) |
|
|
| |
| profiles = { |
| "EV-FRT-001": {"base_temp": 32, "fast_charge_freq": 0.05, "cycles_per_day": 1.2}, |
| "EV-FRT-002": {"base_temp": 34, "fast_charge_freq": 0.10, "cycles_per_day": 1.4}, |
| "EV-FRT-003": {"base_temp": 30, "fast_charge_freq": 0.03, "cycles_per_day": 1.0}, |
| "EV-LM-004": {"base_temp": 28, "fast_charge_freq": 0.20, "cycles_per_day": 2.0}, |
| "EV-LM-005": {"base_temp": 29, "fast_charge_freq": 0.15, "cycles_per_day": 1.8}, |
| "EV-BUS-006": {"base_temp": 35, "fast_charge_freq": 0.02, "cycles_per_day": 1.0}, |
| "EV-MIN-007": {"base_temp": 38, "fast_charge_freq": 0.08, "cycles_per_day": 1.6}, |
| "EV-MIN-008": {"base_temp": 40, "fast_charge_freq": 0.12, "cycles_per_day": 1.7}, |
| "EV-CST-009": {"base_temp": 33, "fast_charge_freq": 0.06, "cycles_per_day": 1.3}, |
| "EV-CST-010": {"base_temp": 31, "fast_charge_freq": 0.04, "cycles_per_day": 1.1}, |
| } |
| profile = profiles.get(vehicle_id, profiles["EV-FRT-001"]) |
|
|
| records = [] |
| start = datetime.utcnow() - timedelta(days=days) |
| cycle_count = 0 |
|
|
| for i in range(days): |
| timestamp = start + timedelta(days=i) |
| |
| temp = profile['base_temp'] + np.random.normal(0, 3) |
| if np.random.random() < 0.02: |
| temp += np.random.uniform(8, 18) |
|
|
| cycle_count += profile['cycles_per_day'] + np.random.normal(0, 0.1) |
| soc = np.random.uniform(30, 90) |
|
|
| |
| is_fast_charge = np.random.random() < profile['fast_charge_freq'] |
| current = np.random.uniform(-80, 120) |
| if is_fast_charge: |
| current = np.random.uniform(200, 320) |
|
|
| voltage = 350 + (100 - soc) * 0.8 + np.random.normal(0, 2) |
|
|
| records.append({ |
| "timestamp": timestamp, |
| "vehicle_id": vehicle_id, |
| "soc": round(soc, 1), |
| "voltage": round(voltage, 1), |
| "current": round(current, 1), |
| "temperature": round(temp, 1), |
| "cycle_count": int(cycle_count), |
| "odometer_km": round(cycle_count * np.random.uniform(80, 120), 1) |
| }) |
|
|
| return pd.DataFrame(records) |
|
|
|
|
| def get_all_bms_data() -> dict: |
| data = {} |
| for vid in VEHICLE_IDS: |
| data[vid] = generate_bms_history(vid, days=365, seed=hash(vid) % 10000) |
| return data |
|
|