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

Create modules/simulator.py

Browse files
Files changed (1) hide show
  1. modules/simulator.py +65 -0
modules/simulator.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)