Spaces:
Sleeping
Sleeping
Update modules/simulator.py
Browse files- modules/simulator.py +29 -32
modules/simulator.py
CHANGED
@@ -1,50 +1,47 @@
|
|
1 |
import pandas as pd
|
2 |
import numpy as np
|
|
|
3 |
|
4 |
-
def simulate_data(n=
|
5 |
-
|
6 |
-
|
7 |
-
"Hyderabad": (17.385, 78.4867),
|
8 |
-
"Ballari": (15.1394, 76.9214),
|
9 |
-
"Gadwal": (16.232, 77.795),
|
10 |
-
"Kurnool": (15.8281, 78.0373)
|
11 |
-
}
|
12 |
data = []
|
13 |
-
for i in range(n):
|
14 |
-
site = np.random.choice(list(sites.keys()))
|
15 |
-
lat, lon = sites[site]
|
16 |
-
solar = np.round(np.random.uniform(3, 7.5), 2)
|
17 |
-
wind = np.round(np.random.uniform(0.5, 2.0), 2)
|
18 |
-
tilt = np.round(np.random.uniform(0, 15), 1)
|
19 |
-
vib = np.round(np.random.uniform(0.1, 3.0), 2)
|
20 |
-
cam = np.random.choice(["Online", "Offline"], p=[0.85, 0.15])
|
21 |
-
power_required = np.round(np.random.uniform(1.0, 1.5), 2)
|
22 |
-
total = solar + wind
|
23 |
-
sufficient = "Yes" if total >= power_required else "No"
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
anomaly = []
|
|
|
26 |
if faults:
|
27 |
-
if solar < 4.0: anomaly.append("Low Solar")
|
28 |
-
if wind < 0.7: anomaly.append("Low Wind")
|
29 |
-
if tilt > 10: anomaly.append("Tilt Risk")
|
30 |
if vib > 2.0: anomaly.append("Vibration Alert")
|
31 |
if cam == "Offline": anomaly.append("Camera Offline")
|
32 |
if sufficient == "No": anomaly.append("Power Insufficient")
|
33 |
|
34 |
-
alert = "Green"
|
|
|
|
|
35 |
|
36 |
data.append({
|
37 |
-
"Pole ID":
|
38 |
-
"
|
39 |
-
"
|
40 |
-
"
|
41 |
-
"
|
42 |
-
"WindGen(kWh)": wind,
|
43 |
-
"Tilt(°)": tilt,
|
44 |
-
"Vibration(g)": vib,
|
45 |
-
"Camera Status": cam,
|
46 |
"Power Sufficient": sufficient,
|
|
|
|
|
|
|
47 |
"Anomalies": "; ".join(anomaly) if anomaly else "None",
|
48 |
"Alert Level": alert
|
49 |
})
|
|
|
50 |
return pd.DataFrame(data)
|
|
|
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 |
|
10 |
+
for pole in poles:
|
11 |
+
solar = round(np.random.uniform(3.0, 7.5), 2)
|
12 |
+
wind = round(np.random.uniform(0.5, 2.0), 2)
|
13 |
+
required = round(np.random.uniform(1.0, 1.5), 2)
|
14 |
+
total = solar + wind
|
15 |
+
cam = np.random.choice(['Online', 'Offline'], p=[0.85, 0.15]) if faults else "Online"
|
16 |
+
tilt = round(np.random.uniform(0, 12), 1)
|
17 |
+
vib = round(np.random.uniform(0.1, 2.5), 2)
|
18 |
+
sufficient = "Yes" if total >= required else "No"
|
19 |
anomaly = []
|
20 |
+
|
21 |
if faults:
|
22 |
+
if solar < 4.0: anomaly.append("Low Solar Output")
|
23 |
+
if wind < 0.7: anomaly.append("Low Wind Output")
|
24 |
+
if tilt > 10: anomaly.append("Pole Tilt Risk")
|
25 |
if vib > 2.0: anomaly.append("Vibration Alert")
|
26 |
if cam == "Offline": anomaly.append("Camera Offline")
|
27 |
if sufficient == "No": anomaly.append("Power Insufficient")
|
28 |
|
29 |
+
alert = "Green"
|
30 |
+
if len(anomaly) == 1: alert = "Yellow"
|
31 |
+
elif len(anomaly) > 1: alert = "Red"
|
32 |
|
33 |
data.append({
|
34 |
+
"Pole ID": pole,
|
35 |
+
"Date": today,
|
36 |
+
"Solar Gen (kWh)": solar,
|
37 |
+
"Wind Gen (kWh)": wind,
|
38 |
+
"Power Required (kWh)": required,
|
|
|
|
|
|
|
|
|
39 |
"Power Sufficient": sufficient,
|
40 |
+
"Camera Status": cam,
|
41 |
+
"Tilt (°)": tilt,
|
42 |
+
"Vibration (g)": vib,
|
43 |
"Anomalies": "; ".join(anomaly) if anomaly else "None",
|
44 |
"Alert Level": alert
|
45 |
})
|
46 |
+
|
47 |
return pd.DataFrame(data)
|