From 43907d9d905b8c7bb43ceaae68da1554e96b34ca Mon Sep 17 00:00:00 2001 From: Subeka M Date: Thu, 3 Feb 2022 20:42:16 -0500 Subject: [PATCH 1/4] Added components as property --- topside/procedures/procedure.py | 21 +++++++++++++++++++++ topside/procedures/tests/test_procedure.py | 12 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/topside/procedures/procedure.py b/topside/procedures/procedure.py index 922b1a4..50806c3 100644 --- a/topside/procedures/procedure.py +++ b/topside/procedures/procedure.py @@ -109,6 +109,7 @@ class ProcedureStep: operator: str The person who performs the step + """ step_id: str action: Action @@ -143,11 +144,19 @@ def __init__(self, procedure_id, steps): steps: iterable An iterable of ProcedureStep objects ordered from first step to last step. + + Members + ------- + + components: set + An unordered collection of components used from each of the + steps from before. Added to set if the action contains a component """ self.procedure_id = procedure_id self.steps = {} self.step_list = list(steps) self.step_id_to_idx = {} + self.components = set() for i, step in enumerate(steps): if step.step_id in self.steps: @@ -155,6 +164,8 @@ def __init__(self, procedure_id, steps): f'duplicate step ID {step.step_id} encountered in Procedure initialization') self.steps[step.step_id] = step self.step_id_to_idx[step.step_id] = i + if step.action: + self.components.add(step.action[0]) def index_of(self, step_id): """ @@ -226,9 +237,18 @@ def __init__(self, procedures, starting_procedure_id='main'): The procedure ID for the starting procedure used when this procedure suite is executed. Defaults to "main" if not specified. + + Members + ------- + + components: set + An unordered collection of components used from each of the + Procedures passed into it. Components are received from the property + within ProcedureStep """ self.starting_procedure_id = starting_procedure_id self.procedures = {} + self.components = set() # TODO(jacob): Allow invalid procedure suites to be created, but # keep track of the invalid reasons (same way plumbing code @@ -239,6 +259,7 @@ def __init__(self, procedures, starting_procedure_id='main'): raise ValueError(f'duplicate procedure ID {proc.procedure_id} encountered in ' + 'ProcedureSuite initialization') self.procedures[proc.procedure_id] = proc + self.components.update(proc.components) if self.starting_procedure_id not in self.procedures: raise ValueError(f'starting procedure ID {self.starting_procedure_id} not found in ' diff --git a/topside/procedures/tests/test_procedure.py b/topside/procedures/tests/test_procedure.py index 39f2a50..5f54068 100644 --- a/topside/procedures/tests/test_procedure.py +++ b/topside/procedures/tests/test_procedure.py @@ -244,3 +244,15 @@ def test_action_types(): assert isinstance(a1, top.Action) assert isinstance(a2, top.Action) + + +def test_components(): + s1 = top.ProcedureStep('s1', ('p1', 'open'), [], 'PRIMARY') + s2 = top.ProcedureStep('s2', ('p2', 'open'), [], 'PRIMARY') + s3 = top.ProcedureStep('s3', ('p3', 'open'), [], 'PRIMARY') + + proc_1 = top.Procedure('p1', [s1, s2, s3]) + + components_1 = proc_1.components + + assert components_1 == {'p1', 'p2', 'p3'} From 7cf77ce9281e6556ece2e865d6246d4af662147d Mon Sep 17 00:00:00 2001 From: Subeka M Date: Thu, 3 Feb 2022 23:44:36 -0500 Subject: [PATCH 2/4] Updated Procedures --- topside/procedures/procedure.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/topside/procedures/procedure.py b/topside/procedures/procedure.py index 50806c3..ba1c8ae 100644 --- a/topside/procedures/procedure.py +++ b/topside/procedures/procedure.py @@ -11,7 +11,8 @@ class ExportFormat(enum.Enum): # TODO(jacob): Investigate whether this would be better as a variant # rather than a base class. class Action: - pass + def get_action_type(self): + pass @dataclass @@ -35,6 +36,9 @@ class StateChangeAction(Action): component: str state: str + def get_action_type(self): + return self.component + def export(self, fmt): if fmt == top.ExportFormat.Latex: if self.state == 'open': @@ -59,6 +63,9 @@ class MiscAction(Action): """ action_type: str + def get_action_type(self): + return self.action_type + def export(self, fmt): if fmt == top.ExportFormat.Latex: return self.action_type @@ -164,8 +171,11 @@ def __init__(self, procedure_id, steps): f'duplicate step ID {step.step_id} encountered in Procedure initialization') self.steps[step.step_id] = step self.step_id_to_idx[step.step_id] = i - if step.action: + if type(step.action) is tuple: self.components.add(step.action[0]) + elif step.action: + print (step.action) + self.components.add(step.action.get_action_type()) def index_of(self, step_id): """ From 8d189b4e6c6d4b1df6a1808b110d17f210c55dde Mon Sep 17 00:00:00 2001 From: Subeka M Date: Thu, 3 Feb 2022 23:51:58 -0500 Subject: [PATCH 3/4] Removed debug print statement --- topside/procedures/procedure.py | 1 - 1 file changed, 1 deletion(-) diff --git a/topside/procedures/procedure.py b/topside/procedures/procedure.py index ba1c8ae..b9c75ed 100644 --- a/topside/procedures/procedure.py +++ b/topside/procedures/procedure.py @@ -174,7 +174,6 @@ def __init__(self, procedure_id, steps): if type(step.action) is tuple: self.components.add(step.action[0]) elif step.action: - print (step.action) self.components.add(step.action.get_action_type()) def index_of(self, step_id): From 3144c06227d5c51d0ed673d80b8a8348de6be4fb Mon Sep 17 00:00:00 2001 From: Subeka M Date: Thu, 3 Feb 2022 23:56:26 -0500 Subject: [PATCH 4/4] Updated Action class --- topside/procedures/procedure.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/topside/procedures/procedure.py b/topside/procedures/procedure.py index b9c75ed..a21adb6 100644 --- a/topside/procedures/procedure.py +++ b/topside/procedures/procedure.py @@ -11,8 +11,7 @@ class ExportFormat(enum.Enum): # TODO(jacob): Investigate whether this would be better as a variant # rather than a base class. class Action: - def get_action_type(self): - pass + pass @dataclass