-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpowergrrid.py
More file actions
59 lines (45 loc) · 1.6 KB
/
powergrrid.py
File metadata and controls
59 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import random
import time
from datetime import datetime
# sensor configuration
SENSOR_TYPE = "substation_monitor"
LOCATION = "Substation_A"
def generate_sensor_data():
# normal conditions
load_mw = random.uniform(40.0, 55.0)
transformer_temp_c = random.uniform(55.0, 70.0)
voltage_kv = random.uniform(10.8, 11.2) # normal voltage
power_status = "ON"
# random chance of incidents
incident = random.choice(["normal","normal","normal","surge","overheat","blackout","voltage_variation","outage"])
if incident == "surge":
load_mw = random.uniform(75.0, 90.0)
transformer_temp_c = random.uniform(80.0, 95.0)
elif incident == "overheat":
load_mw = random.uniform(60.0, 70.0)
transformer_temp_c = random.uniform(90.0, 105.0)
elif incident == "blackout":
load_mw = 0.0
transformer_temp_c = random.uniform(95.0, 110.0)
elif incident == "voltage_variation":
voltage_kv = random.uniform(8.0, 14.0)
elif incident == "outage":
load_mw = 0.0
voltage_kv = 0.0
power_status = "OUTAGE"
data = {
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"sensor_type": SENSOR_TYPE,
"location": LOCATION,
"load_mw": round(load_mw,2),
"transformer_temp_c": round(transformer_temp_c,2),
"voltage_kv": round(voltage_kv,2),
"power_status": power_status
}
return data
# simulate continuous sensor streaming
while True:
sensor_data = generate_sensor_data()
print(sensor_data)
# simulate sensor update every 5 seconds
time.sleep(5)