Spaces:
Sleeping
Sleeping
Update modules/simulator.py
Browse files- modules/simulator.py +45 -60
modules/simulator.py
CHANGED
@@ -1,65 +1,50 @@
|
|
1 |
-
# modules/simulator.py
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
import datetime
|
5 |
-
from typing import List
|
6 |
|
7 |
-
def simulate_data(n
|
8 |
-
"""Simulate pole data in batches for scalability."""
|
9 |
today = datetime.date.today()
|
10 |
-
|
11 |
-
|
12 |
-
for
|
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 |
-
"PowerSufficient": sufficient,
|
55 |
-
"CameraStatus": cam,
|
56 |
-
"Tilt(°)": tilt,
|
57 |
-
"Vibration(g)": vib,
|
58 |
-
"Anomalies": ";".join(anomaly) if anomaly else "None",
|
59 |
-
"AlertLevel": alert,
|
60 |
-
"Timestamp": pd.Timestamp.now()
|
61 |
-
})
|
62 |
-
|
63 |
-
all_data.append(pd.DataFrame(data))
|
64 |
-
|
65 |
-
return pd.concat(all_data, ignore_index=True)
|
|
|
|
|
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 |
+
"Pole ID": pole,
|
39 |
+
"Date": today,
|
40 |
+
"Solar Gen (kWh)": solar,
|
41 |
+
"Wind Gen (kWh)": wind,
|
42 |
+
"Power Required (kWh)": required,
|
43 |
+
"Power Sufficient": sufficient,
|
44 |
+
"Camera Status": cam,
|
45 |
+
"Tilt (°)": tilt,
|
46 |
+
"Vibration (g)": vib,
|
47 |
+
"Anomalies": "; ".join(anomaly) if anomaly else "None",
|
48 |
+
"Alert Level": alert
|
49 |
+
})
|
50 |
+
return pd.DataFrame(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|