DSatishchandra commited on
Commit
a85c77b
·
verified ·
1 Parent(s): 5ef8843

Update modules/simulator.py

Browse files
Files changed (1) hide show
  1. modules/simulator.py +45 -60
modules/simulator.py CHANGED
@@ -1,65 +1,50 @@
1
- # modules/simulator.py
2
  import pandas as pd
3
  import numpy as np
4
  import datetime
5
- from typing import List
6
 
7
- def simulate_data(n: int = 1000, faults: bool = True, batch_size: int = 10000) -> pd.DataFrame:
8
- """Simulate pole data in batches for scalability."""
9
  today = datetime.date.today()
10
- all_data = []
11
-
12
- for batch in range(0, n, batch_size):
13
- batch_n = min(batch_size, n - batch)
14
- poles = [f"Pole_{batch + i + 1:07}" for i in range(batch_n)]
15
- data = []
16
-
17
- for pole in poles:
18
- solar = round(np.random.uniform(3.0, 7.5), 2)
19
- wind = round(np.random.uniform(0.5, 2.0), 2)
20
- required = round(np.random.uniform(1.0, 1.5), 2)
21
- total = solar + wind
22
- cam = np.random.choice(['Online', 'Offline'], p=[0.85, 0.15]) if faults else "Online"
23
- tilt = round(np.random.uniform(0, 12), 1)
24
- vib = round(np.random.uniform(0.1, 2.5), 2)
25
- sufficient = "Yes" if total >= required else "No"
26
- anomaly = []
27
-
28
- if faults:
29
- if solar < 4.0:
30
- anomaly.append("LowSolarOutput")
31
- if wind < 0.7:
32
- anomaly.append("LowWindOutput")
33
- if tilt > 10:
34
- anomaly.append("PoleTiltRisk")
35
- if vib > 2.0:
36
- anomaly.append("VibrationAlert")
37
- if cam == "Offline":
38
- anomaly.append("CameraOffline")
39
- if sufficient == "No":
40
- anomaly.append("PowerInsufficient")
41
-
42
- alert = "Green"
43
- if len(anomaly) == 1:
44
- alert = "Yellow"
45
- elif len(anomaly) > 1:
46
- alert = "Red"
47
-
48
- data.append({
49
- "PoleID": pole,
50
- "Date": today,
51
- "SolarGen(kWh)": solar,
52
- "WindGen(kWh)": wind,
53
- "PowerRequired(kWh)": required,
54
- "PowerSufficient": sufficient,
55
- "CameraStatus": cam,
56
- "Tilt(°)": tilt,
57
- "Vibration(g)": vib,
58
- "Anomalies": ";".join(anomaly) if anomaly else "None",
59
- "AlertLevel": alert,
60
- "Timestamp": pd.Timestamp.now()
61
- })
62
-
63
- all_data.append(pd.DataFrame(data))
64
-
65
- return pd.concat(all_data, ignore_index=True)
 
 
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
+ for pole in poles:
10
+ solar = round(np.random.uniform(3.0, 7.5), 2)
11
+ wind = round(np.random.uniform(0.5, 2.0), 2)
12
+ required = round(np.random.uniform(1.0, 1.5), 2)
13
+ total = solar + wind
14
+ cam = np.random.choice(['Online', 'Offline'], p=[0.85, 0.15]) if faults else "Online"
15
+ tilt = round(np.random.uniform(0, 12), 1)
16
+ vib = round(np.random.uniform(0.1, 2.5), 2)
17
+ sufficient = "Yes" if total >= required else "No"
18
+ anomaly = []
19
+ if faults:
20
+ if solar < 4.0:
21
+ anomaly.append("Low Solar Output")
22
+ if wind < 0.7:
23
+ anomaly.append("Low Wind Output")
24
+ if tilt > 10:
25
+ anomaly.append("Pole Tilt Risk")
26
+ if vib > 2.0:
27
+ anomaly.append("Vibration Alert")
28
+ if cam == "Offline":
29
+ anomaly.append("Camera Offline")
30
+ if sufficient == "No":
31
+ anomaly.append("Power Insufficient")
32
+ alert = "Green"
33
+ if len(anomaly) == 1:
34
+ alert = "Yellow"
35
+ elif len(anomaly) > 1:
36
+ alert = "Red"
37
+ data.append({
38
+ "Pole ID": pole,
39
+ "Date": today,
40
+ "Solar Gen (kWh)": solar,
41
+ "Wind Gen (kWh)": wind,
42
+ "Power Required (kWh)": required,
43
+ "Power Sufficient": sufficient,
44
+ "Camera Status": cam,
45
+ "Tilt (°)": tilt,
46
+ "Vibration (g)": vib,
47
+ "Anomalies": "; ".join(anomaly) if anomaly else "None",
48
+ "Alert Level": alert
49
+ })
50
+ return pd.DataFrame(data)