dschandra commited on
Commit
4982cc3
·
verified ·
1 Parent(s): dc68c16

Create modules/simulator.py

Browse files
Files changed (1) hide show
  1. modules/simulator.py +78 -0
modules/simulator.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ import datetime
4
+
5
+ def simulate_data(n=50, faults=True):
6
+ today = datetime.date.today()
7
+ sites = ["Hyderabad", "Ballari", "Kurnool", "Gadwal"]
8
+ poles_per_site = n // len(sites) # Approximately 12-13 poles per site
9
+ poles = []
10
+ site_assignments = []
11
+ x_coords = []
12
+ y_coords = []
13
+
14
+ # Assign poles to sites and generate spatial coordinates for heatmap
15
+ for i, site in enumerate(sites):
16
+ site_poles = [f"Pole_{j+1:03}" for j in range(i * poles_per_site, (i + 1) * poles_per_site)]
17
+ poles.extend(site_poles)
18
+ site_assignments.extend([site] * len(site_poles))
19
+ # Assign coordinates within a grid for each site (e.g., 4x4 grid per site)
20
+ for _ in site_poles:
21
+ x_coords.append(np.random.uniform(i * 10, (i + 1) * 10)) # Spread across x-axis per site
22
+ y_coords.append(np.random.uniform(0, 10)) # Common y-axis range
23
+
24
+ # Handle remaining poles (to reach exactly 50)
25
+ remaining = n - len(poles)
26
+ if remaining > 0:
27
+ extra_poles = [f"Pole_{len(poles)+j+1:03}" for j in range(remaining)]
28
+ poles.extend(extra_poles)
29
+ site_assignments.extend([sites[-1]] * remaining)
30
+ x_coords.extend([np.random.uniform(30, 40)] * remaining)
31
+ y_coords.extend([np.random.uniform(0, 10)] * remaining)
32
+
33
+ data = []
34
+ for pole, site, x, y in zip(poles, site_assignments, x_coords, y_coords):
35
+ solar = round(np.random.uniform(3.0, 7.5), 2)
36
+ wind = round(np.random.uniform(0.5, 2.0), 2)
37
+ required = round(np.random.uniform(1.0, 1.5), 2)
38
+ total = solar + wind
39
+ cam = np.random.choice(['Online', 'Offline'], p=[0.85, 0.15]) if faults else "Online"
40
+ tilt = round(np.random.uniform(0, 12), 1)
41
+ vib = round(np.random.uniform(0.1, 2.5), 2)
42
+ sufficient = "Yes" if total >= required else "No"
43
+ anomaly = []
44
+ if faults:
45
+ if solar < 4.0:
46
+ anomaly.append("LowSolarOutput")
47
+ if wind < 0.7:
48
+ anomaly.append("LowWindOutput")
49
+ if tilt > 10:
50
+ anomaly.append("PoleTiltRisk")
51
+ if vib > 2.0:
52
+ anomaly.append("VibrationAlert")
53
+ if cam == "Offline":
54
+ anomaly.append("CameraOffline")
55
+ if sufficient == "No":
56
+ anomaly.append("PowerInsufficient")
57
+ alert = "Green"
58
+ if len(anomaly) == 1:
59
+ alert = "Yellow"
60
+ elif len(anomaly) > 1:
61
+ alert = "Red"
62
+ data.append({
63
+ "PoleID": pole,
64
+ "Site": site,
65
+ "Date": today,
66
+ "SolarGen(kWh)": solar,
67
+ "WindGen(kWh)": wind,
68
+ "PowerRequired(kWh)": required,
69
+ "PowerSufficient": sufficient,
70
+ "CameraStatus": cam,
71
+ "Tilt(°)": tilt,
72
+ "Vibration(g)": vib,
73
+ "Anomalies": ";".join(anomaly) if anomaly else "None",
74
+ "AlertLevel": alert,
75
+ "XCoord": x,
76
+ "YCoord": y
77
+ })
78
+ return pd.DataFrame(data)