Spaces:
Sleeping
Sleeping
Create modules/simulator.py
Browse files- modules/simulator.py +50 -0
modules/simulator.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
import datetime
|
| 4 |
+
|
| 5 |
+
def simulate_data(n=10, faults=True):
|
| 6 |
+
today = datetime.date.today()
|
| 7 |
+
poles = [f"Pole_{i+1:03}" for i in range(n)]
|
| 8 |
+
data = []
|
| 9 |
+
for pole in poles:
|
| 10 |
+
solar = round(np.random.uniform(3.0, 7.5), 2)
|
| 11 |
+
wind = round(np.random.uniform(0.5, 2.0), 2)
|
| 12 |
+
required = round(np.random.uniform(1.0, 1.5), 2)
|
| 13 |
+
total = solar + wind
|
| 14 |
+
cam = np.random.choice(['Online', 'Offline'], p=[0.85, 0.15]) if faults else "Online"
|
| 15 |
+
tilt = round(np.random.uniform(0, 12), 1)
|
| 16 |
+
vib = round(np.random.uniform(0.1, 2.5), 2)
|
| 17 |
+
sufficient = "Yes" if total >= required else "No"
|
| 18 |
+
anomaly = []
|
| 19 |
+
if faults:
|
| 20 |
+
if solar < 4.0:
|
| 21 |
+
anomaly.append("Low Solar Output")
|
| 22 |
+
if wind < 0.7:
|
| 23 |
+
anomaly.append("Low Wind Output")
|
| 24 |
+
if tilt > 10:
|
| 25 |
+
anomaly.append("Pole Tilt Risk")
|
| 26 |
+
if vib > 2.0:
|
| 27 |
+
anomaly.append("Vibration Alert")
|
| 28 |
+
if cam == "Offline":
|
| 29 |
+
anomaly.append("Camera Offline")
|
| 30 |
+
if sufficient == "No":
|
| 31 |
+
anomaly.append("Power Insufficient")
|
| 32 |
+
alert = "Green"
|
| 33 |
+
if len(anomaly) == 1:
|
| 34 |
+
alert = "Yellow"
|
| 35 |
+
elif len(anomaly) > 1:
|
| 36 |
+
alert = "Red"
|
| 37 |
+
data.append({
|
| 38 |
+
"PoleID": pole,
|
| 39 |
+
"Date": today,
|
| 40 |
+
"SolarGen(kWh)": solar,
|
| 41 |
+
"WindGen(kWh)": wind,
|
| 42 |
+
"PowerRequired(kWh)": required,
|
| 43 |
+
"PowerSufficient": sufficient,
|
| 44 |
+
"CameraStatus": cam,
|
| 45 |
+
"Tilt(°)": tilt,
|
| 46 |
+
"Vibration(g)": vib,
|
| 47 |
+
"Anomalies": ";".join(anomaly) if anomaly else "None",
|
| 48 |
+
"AlertLevel": alert
|
| 49 |
+
})
|
| 50 |
+
return pd.DataFrame(data)
|