Spaces:
Sleeping
Sleeping
Update modules/simulator.py
Browse files- modules/simulator.py +47 -16
modules/simulator.py
CHANGED
@@ -1,19 +1,50 @@
|
|
1 |
import pandas as pd
|
2 |
import numpy as np
|
3 |
|
4 |
-
def
|
5 |
-
np.random.seed(
|
6 |
-
sites =
|
7 |
-
|
8 |
-
"
|
9 |
-
"
|
10 |
-
"
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import pandas as pd
|
2 |
import numpy as np
|
3 |
|
4 |
+
def simulate_data(n=50, faults=True):
|
5 |
+
np.random.seed(42)
|
6 |
+
sites = {
|
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" if len(anomaly) == 0 else "Yellow" if len(anomaly) == 1 else "Red"
|
35 |
+
|
36 |
+
data.append({
|
37 |
+
"Pole ID": f"Pole_{i+1:03}",
|
38 |
+
"Site": site,
|
39 |
+
"Latitude": lat + np.random.uniform(-0.01, 0.01),
|
40 |
+
"Longitude": lon + np.random.uniform(-0.01, 0.01),
|
41 |
+
"SolarGen(kWh)": solar,
|
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)
|