-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_scenario.py
65 lines (50 loc) · 2.1 KB
/
demo_scenario.py
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
60
61
62
63
64
65
from src import typhoon_automator
import random
# Create an example scenario
class DemoScenario(object):
SCADA_SWITCH_NAME = "Sw_ctrl"
def __init__(
self,
duration: float):
self._duration = duration
def close_switch(simulation: typhoon_automator.Simulation):
simulation.set_scada_value(name = DemoScenario.SCADA_SWITCH_NAME, value = 1)
def open_switch(simulation: typhoon_automator.Simulation):
simulation.set_scada_value(name = DemoScenario.SCADA_SWITCH_NAME, value = 0)
def set_up_scenario(
self,
simulation: typhoon_automator.Simulation):
""" Set up the demo scenaro
"""
simulation.set_data_logging_signals([
"I_ind",
"V_cap"])
simulation.set_capture_signals(
analog_signals = [
"I_ind",
"V_cap"],
digital_signals = [])
CAPTURE_DURATION = 0.1
# Create and schedule switch close and open events
close_event = typhoon_automator.Utility.create_callback_event(
message = "Closing switch",
callback = DemoScenario.close_switch)
close_time = random.uniform(CAPTURE_DURATION / 2, self._duration / 2)
open_event = typhoon_automator.Utility.create_callback_event(
message = "Opening switch",
callback = DemoScenario.open_switch)
open_time = random.uniform((self._duration / 2), self._duration - CAPTURE_DURATION)
simulation.schedule_event(close_time, close_event)
simulation.schedule_event(open_time, open_event)
# Schedule a 100 millisecond capture starting 50 milliseconds before the switch opens
simulation.schedule_capture(
start_time = open_time - (CAPTURE_DURATION / 2),
duration = CAPTURE_DURATION)
# Set scenario duration
simulation.set_scenario_duration(self._duration)
# Initialize switch as open
DemoScenario.open_switch(simulation)
def tear_down_scenario(
self,
simulation: typhoon_automator.Simulation):
pass