DSatishchandra commited on
Commit
1a8ba80
·
verified ·
1 Parent(s): 3b33856

Update modules/simulator.py

Browse files
Files changed (1) hide show
  1. modules/simulator.py +34 -53
modules/simulator.py CHANGED
@@ -1,43 +1,25 @@
1
  import pandas as pd
2
  import numpy as np
3
  import datetime
4
- import uuid
5
 
6
- def simulate_data(n=50, faults=True, update_time=None):
7
  today = datetime.date.today()
8
- update_time = update_time or datetime.datetime.now() # Use provided time or current time
9
  poles = [f"Pole_{i+1:03}" for i in range(n)]
10
- # Distribute poles across 4 locations
11
- locations = ["Hyderabad"] * 12 + ["Gadwal"] * 12 + ["Kurnool"] * 12 + ["Ballari"] * 14
12
- # Simulate coordinates and zones for each location
13
- base_hyderabad = (17.329181, 78.610091) # Vacant land space in Hyderabad
14
- coords = {
15
- "Hyderabad": [
16
- (
17
- base_hyderabad[0] + (i * 0.0001) + np.random.uniform(-0.00005, 0.00005), # Approx 10-15 ft spacing
18
- base_hyderabad[1] + (i * 0.0001) + np.random.uniform(-0.00005, 0.00005),
19
- f"Zone_{np.random.choice(['North', 'South', 'Central'])}"
20
- ) for i in range(12)
21
- ],
22
- "Gadwal": [
23
- (16.235 + np.random.uniform(-0.03, 0.03), 77.795 + np.random.uniform(-0.03, 0.03), f"Zone_{np.random.choice(['East', 'West'])}")
24
- for _ in range(12)
25
- ],
26
- "Kurnool": [
27
- (15.828 + np.random.uniform(-0.04, 0.04), 78.037 + np.random.uniform(-0.04, 0.04), f"Zone_{np.random.choice(['Urban', 'Rural'])}")
28
- for _ in range(12)
29
- ],
30
- "Ballari": [
31
- (15.139 + np.random.uniform(-0.04, 0.04), 76.921 + np.random.uniform(-0.04, 0.04), f"Zone_{np.random.choice(['Downtown', 'Industrial', 'Residential'])}")
32
- for _ in range(14)
33
- ]
34
- }
35
- location_coords = []
36
- for loc in locations:
37
- coord = coords[loc].pop(0)
38
- location_coords.append(coord)
39
  data = []
40
- for i, (pole, location, (lat, lon, zone)) in enumerate(zip(poles, locations, location_coords)):
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  solar = round(np.random.uniform(3.0, 7.5), 2)
42
  wind = round(np.random.uniform(0.5, 2.0), 2)
43
  required = round(np.random.uniform(1.0, 1.5), 2)
@@ -46,43 +28,42 @@ def simulate_data(n=50, faults=True, update_time=None):
46
  tilt = round(np.random.uniform(0, 12), 1)
47
  vib = round(np.random.uniform(0.1, 2.5), 2)
48
  sufficient = "Yes" if total >= required else "No"
49
- rfid = str(uuid.uuid4())[:16] # 16-digit unique RFID
50
  anomaly = []
 
51
  if faults:
52
  if solar < 4.0:
53
  anomaly.append("Low Solar Output")
54
  if wind < 0.7:
55
  anomaly.append("Low Wind Output")
56
  if tilt > 10:
57
- anomaly.append("High Pole Tilt Risk")
58
  if vib > 2.0:
59
- anomaly.append("Excessive Vibration")
60
  if cam == "Offline":
61
  anomaly.append("Camera Offline")
62
  if sufficient == "No":
63
  anomaly.append("Power Insufficient")
 
64
  alert = "Green"
65
  if len(anomaly) == 1:
66
  alert = "Yellow"
67
  elif len(anomaly) > 1:
68
  alert = "Red"
 
69
  data.append({
70
- "PoleID": pole,
71
- "RFID": rfid,
72
- "Location": location,
73
- "Zone": zone,
74
- "Latitude": lat,
75
- "Longitude": lon,
76
  "Date": today,
77
- "Timestamp": update_time,
78
- "SolarGen(kWh)": solar,
79
- "WindGen(kWh)": wind,
80
- "PowerRequired(kWh)": required,
81
- "PowerSufficient": sufficient,
82
- "CameraStatus": cam,
83
- "Tilt(°)": tilt,
84
- "Vibration(g)": vib,
85
- "Anomalies": ";".join(anomaly) if anomaly else "None",
86
- "AlertLevel": alert
 
87
  })
88
- 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
+ # Define location coordinates for the sites
11
+ locations = {
12
+ "Hyderabad": (17.385044, 78.486671),
13
+ "Gadwal": (16.2333, 77.1833),
14
+ "Kurnool": (15.8281, 78.0469),
15
+ "Ballari": (15.1502, 75.9246)
16
+ }
17
+
18
+ # Assign poles to sites randomly
19
+ for pole in poles:
20
+ site = np.random.choice(list(locations.keys()))
21
+ lat, lon = locations[site]
22
+
23
  solar = round(np.random.uniform(3.0, 7.5), 2)
24
  wind = round(np.random.uniform(0.5, 2.0), 2)
25
  required = round(np.random.uniform(1.0, 1.5), 2)
 
28
  tilt = round(np.random.uniform(0, 12), 1)
29
  vib = round(np.random.uniform(0.1, 2.5), 2)
30
  sufficient = "Yes" if total >= required else "No"
 
31
  anomaly = []
32
+
33
  if faults:
34
  if solar < 4.0:
35
  anomaly.append("Low Solar Output")
36
  if wind < 0.7:
37
  anomaly.append("Low Wind Output")
38
  if tilt > 10:
39
+ anomaly.append("Pole Tilt Risk")
40
  if vib > 2.0:
41
+ anomaly.append("Vibration Alert")
42
  if cam == "Offline":
43
  anomaly.append("Camera Offline")
44
  if sufficient == "No":
45
  anomaly.append("Power Insufficient")
46
+
47
  alert = "Green"
48
  if len(anomaly) == 1:
49
  alert = "Yellow"
50
  elif len(anomaly) > 1:
51
  alert = "Red"
52
+
53
  data.append({
54
+ "Pole ID": pole,
 
 
 
 
 
55
  "Date": today,
56
+ "Solar Gen (kWh)": solar,
57
+ "Wind Gen (kWh)": wind,
58
+ "Power Required (kWh)": required,
59
+ "Power Sufficient": sufficient,
60
+ "Camera Status": cam,
61
+ "Tilt (°)": tilt,
62
+ "Vibration (g)": vib,
63
+ "Anomalies": "; ".join(anomaly) if anomaly else "None",
64
+ "Alert Level": alert,
65
+ "Latitude": lat,
66
+ "Longitude": lon
67
  })
68
+
69
+ return pd.DataFrame(data)