Nawinkumar15 commited on
Commit
67688b4
·
verified ·
1 Parent(s): 8037d2f

Update modules/simulator.py

Browse files
Files changed (1) hide show
  1. modules/simulator.py +58 -58
modules/simulator.py CHANGED
@@ -2,72 +2,72 @@ import pandas as pd
2
  import numpy as np
3
  import datetime
4
 
 
 
 
 
 
 
 
 
5
  def simulate_data(n=48, faults=True):
6
  today = datetime.date.today()
7
-
8
- sites = ["Hyderabad", "Gadwal", "Kurnool", "Ballari"]
9
-
10
- # Define latitude and longitude for each site
11
- site_coords = {
12
- "Hyderabad": (17.3850, 78.4867),
13
- "Gadwal": (16.2350, 77.8000),
14
- "Kurnool": (15.8281, 78.0373),
15
- "Ballari": (15.1394, 76.9214)
16
- }
17
-
18
- poles = [f"Pole_{i+1:03}" for i in range(n)]
19
  data = []
20
 
21
- for i, pole in enumerate(poles):
22
- site = sites[i // 12] # 12 poles per site
23
- lat, lon = site_coords[site]
 
 
 
 
 
 
 
 
 
24
 
25
- solar = round(np.random.uniform(3.0, 7.5), 2)
26
- wind = round(np.random.uniform(0.5, 2.0), 2)
27
- required = round(np.random.uniform(1.0, 1.5), 2)
28
- total = solar + wind
29
- cam = np.random.choice(['Online', 'Offline'], p=[0.85, 0.15]) if faults else "Online"
30
- tilt = round(np.random.uniform(0, 12), 1)
31
- vib = round(np.random.uniform(0.1, 2.5), 2)
32
- sufficient = "Yes" if total >= required else "No"
33
 
34
- anomaly = []
35
- if faults:
36
- if solar < 4.0:
37
- anomaly.append("Low Solar Output")
38
- if wind < 0.7:
39
- anomaly.append("Low Wind Output")
40
- if tilt > 10:
41
- anomaly.append("Pole Tilt Risk")
42
- if vib > 2.0:
43
- anomaly.append("Vibration Alert")
44
- if cam == "Offline":
45
- anomaly.append("Camera Offline")
46
- if sufficient == "No":
47
- anomaly.append("Power Insufficient")
48
 
49
- alert = "Green"
50
- if len(anomaly) == 1:
51
- alert = "Yellow"
52
- elif len(anomaly) > 1:
53
- alert = "Red"
54
 
55
- data.append({
56
- "Pole ID": pole,
57
- "Site": site,
58
- "Latitude": lat + np.random.uniform(-0.005, 0.005), # small offset
59
- "Longitude": lon + np.random.uniform(-0.005, 0.005),
60
- "Date": today,
61
- "Solar Gen (kWh)": solar,
62
- "Wind Gen (kWh)": wind,
63
- "Power Required (kWh)": required,
64
- "Power Sufficient": sufficient,
65
- "Camera Status": cam,
66
- "Tilt (°)": tilt,
67
- "Vibration (g)": vib,
68
- "Anomalies": "; ".join(anomaly) if anomaly else "None",
69
- "Alert Level": alert
70
- })
71
 
72
  return pd.DataFrame(data)
73
 
 
2
  import numpy as np
3
  import datetime
4
 
5
+ # Rough base coordinates for each site (example, can adjust for realism)
6
+ site_coords = {
7
+ "Hyderabad": (17.385, 78.4867),
8
+ "Gadwal": (16.2333, 77.8),
9
+ "Kurnool": (15.8281, 78.0373),
10
+ "Ballari": (15.1394, 76.9214)
11
+ }
12
+
13
  def simulate_data(n=48, faults=True):
14
  today = datetime.date.today()
15
+ sites = list(site_coords.keys())
 
 
 
 
 
 
 
 
 
 
 
16
  data = []
17
 
18
+ poles_per_site = n // len(sites)
19
+ for site in sites:
20
+ base_lat, base_lon = site_coords[site]
21
+ for i in range(poles_per_site):
22
+ pole_num = len(data) + 1
23
+ pole_id = f"Pole_{pole_num:03}"
24
+
25
+ # Spread out poles in a grid (every 10 feet ≈ 0.00003 degrees)
26
+ row = i // 4
27
+ col = i % 4
28
+ lat = base_lat + row * 0.00003
29
+ lon = base_lon + col * 0.00003
30
 
31
+ solar = round(np.random.uniform(3.0, 7.5), 2)
32
+ wind = round(np.random.uniform(0.5, 2.0), 2)
33
+ required = round(np.random.uniform(1.0, 1.5), 2)
34
+ total = solar + wind
35
+ cam = np.random.choice(['Online', 'Offline'], p=[0.85, 0.15]) if faults else "Online"
36
+ tilt = round(np.random.uniform(0, 12), 1)
37
+ vib = round(np.random.uniform(0.1, 2.5), 2)
38
+ sufficient = "Yes" if total >= required else "No"
39
 
40
+ anomaly = []
41
+ if faults:
42
+ if solar < 4.0: anomaly.append("Low Solar Output")
43
+ if wind < 0.7: anomaly.append("Low Wind Output")
44
+ if tilt > 10: anomaly.append("Pole Tilt Risk")
45
+ if vib > 2.0: anomaly.append("Vibration Alert")
46
+ if cam == "Offline": anomaly.append("Camera Offline")
47
+ if sufficient == "No": anomaly.append("Power Insufficient")
 
 
 
 
 
 
48
 
49
+ alert = "Green"
50
+ if len(anomaly) == 1:
51
+ alert = "Yellow"
52
+ elif len(anomaly) > 1:
53
+ alert = "Red"
54
 
55
+ data.append({
56
+ "Pole ID": pole_id,
57
+ "Site": site,
58
+ "Date": today,
59
+ "Latitude": lat,
60
+ "Longitude": lon,
61
+ "Solar Gen (kWh)": solar,
62
+ "Wind Gen (kWh)": wind,
63
+ "Power Required (kWh)": required,
64
+ "Power Sufficient": sufficient,
65
+ "Camera Status": cam,
66
+ "Tilt (°)": tilt,
67
+ "Vibration (g)": vib,
68
+ "Anomalies": "; ".join(anomaly) if anomaly else "None",
69
+ "Alert Level": alert
70
+ })
71
 
72
  return pd.DataFrame(data)
73