From 873da28667b7697fab3592d8ac57ecc7457959fc Mon Sep 17 00:00:00 2001 From: Alan Gibson Date: Wed, 29 Nov 2023 12:43:24 -0500 Subject: [PATCH 1/5] Adding reporters for each plugin type Reporters will state who they are and what method is running also outputs the arguments, their types, and values Added reporter_config.ini that uses one of each kind in the config dicts --- onair/config/reporter_config.ini | 16 ++++++++++++ .../reporter_of_complexity/__init__.py | 0 .../reporter_of_complexity_plugin.py | 26 +++++++++++++++++++ .../reporter_of_knowledge/__init__.py | 0 .../reporter_of_knowledge_plugin.py | 26 +++++++++++++++++++ .../reporter_of_learning/__init__.py | 0 .../reporter_of_learning_plugin.py | 26 +++++++++++++++++++ .../reporter_of_planning/__init__.py | 0 .../reporter_of_planning_plugin.py | 26 +++++++++++++++++++ 9 files changed, 120 insertions(+) create mode 100644 onair/config/reporter_config.ini create mode 100644 plugins/reporters/reporter_of_complexity/__init__.py create mode 100644 plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py create mode 100644 plugins/reporters/reporter_of_knowledge/__init__.py create mode 100644 plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py create mode 100644 plugins/reporters/reporter_of_learning/__init__.py create mode 100644 plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py create mode 100644 plugins/reporters/reporter_of_planning/__init__.py create mode 100644 plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py diff --git a/onair/config/reporter_config.ini b/onair/config/reporter_config.ini new file mode 100644 index 00000000..3c1b97d8 --- /dev/null +++ b/onair/config/reporter_config.ini @@ -0,0 +1,16 @@ +[DEFAULT] +TelemetryDataFilePath = onair/data/raw_telemetry_data/data_physics_generation/Errors +TelemetryFile = 700_crash_to_earth_1.csv +TelemetryMetadataFilePath = onair/data/telemetry_configs/ +MetaFile = data_physics_generation_CONFIG.json +ParserFileName = onair/data_handling/csv_parser.py + +KnowledgeRepPluginDict = {'reporter_of_knowledge':'plugins/reporters/reporter_of_knowledge/__init__.py'} +LearnersPluginDict = {'reporter_of_learning':'plugins/reporters/reporter_of_learning/__init__.py'} +PlannersPluginDict = {'reporter_of_planning':'plugins/reporters/reporter_of_planning/__init__.py'} +ComplexPluginDict = {'reporter_of_complexity':'plugins/reporters/reporter_of_complexity/__init__.py'} + +[RUN_FLAGS] +IO_Flag = true +Dev_Flag = false +Viz_Flag = false diff --git a/plugins/reporters/reporter_of_complexity/__init__.py b/plugins/reporters/reporter_of_complexity/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py b/plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py new file mode 100644 index 00000000..07c41996 --- /dev/null +++ b/plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py @@ -0,0 +1,26 @@ +# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform" +# +# Copyright © 2023 United States Government as represented by the Administrator of +# the National Aeronautics and Space Administration. No copyright is claimed in the +# United States under Title 17, U.S. Code. All Other Rights Reserved. +# +# Licensed under the NASA Open Source Agreement version 1.3 +# See "NOSA GSC-19165-1 OnAIR.pdf" + +from onair.src.ai_components.ai_plugin_abstract.core import AIPlugIn + +class Plugin(AIPlugIn): + def update(self,low_level_data=[], high_level_data={}): + """ + Given streamed data point, system should update internally + """ + print(f"COMPLEXITY: UPDATE") + print(f" : low_level_data {low_level_data.__class__} = '{low_level_data}'") + print(f" : high_level_data {high_level_data.__class__} = '{high_level_data}'") + + def render_reasoning(self): + """ + System should return its diagnosis + """ + print("COMPLEXITY: REASONING") + print(" : No args") \ No newline at end of file diff --git a/plugins/reporters/reporter_of_knowledge/__init__.py b/plugins/reporters/reporter_of_knowledge/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py b/plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py new file mode 100644 index 00000000..ff61e96c --- /dev/null +++ b/plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py @@ -0,0 +1,26 @@ +# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform" +# +# Copyright © 2023 United States Government as represented by the Administrator of +# the National Aeronautics and Space Administration. No copyright is claimed in the +# United States under Title 17, U.S. Code. All Other Rights Reserved. +# +# Licensed under the NASA Open Source Agreement version 1.3 +# See "NOSA GSC-19165-1 OnAIR.pdf" + +from onair.src.ai_components.ai_plugin_abstract.core import AIPlugIn + +class Plugin(AIPlugIn): + def update(self, low_level_data=[], high_level_data={}): + """ + Given streamed data point, system should update internally + """ + print(f" KNOWLEDGE: UPDATE") + print(f" : low_level_data {low_level_data.__class__} = '{low_level_data}'") + print(f" : high_level_data {high_level_data.__class__} = '{high_level_data}'") + + def render_reasoning(self): + """ + System should return its diagnosis + """ + print(" KNOWLEDGE: REASONING") + print(" : No args") \ No newline at end of file diff --git a/plugins/reporters/reporter_of_learning/__init__.py b/plugins/reporters/reporter_of_learning/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py b/plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py new file mode 100644 index 00000000..fd9d5e1c --- /dev/null +++ b/plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py @@ -0,0 +1,26 @@ +# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform" +# +# Copyright © 2023 United States Government as represented by the Administrator of +# the National Aeronautics and Space Administration. No copyright is claimed in the +# United States under Title 17, U.S. Code. All Other Rights Reserved. +# +# Licensed under the NASA Open Source Agreement version 1.3 +# See "NOSA GSC-19165-1 OnAIR.pdf" + +from onair.src.ai_components.ai_plugin_abstract.core import AIPlugIn + +class Plugin(AIPlugIn): + def update(self,low_level_data=[], high_level_data={}): + """ + Given streamed data point, system should update internally + """ + print(f" LEARNING: UPDATE") + print(f" : low_level_data {low_level_data.__class__} = '{low_level_data}'") + print(f" : high_level_data {high_level_data.__class__} = '{high_level_data}'") + + def render_reasoning(self): + """ + System should return its diagnosis + """ + print(" LEARNING: REASONING") + print(" : No args") \ No newline at end of file diff --git a/plugins/reporters/reporter_of_planning/__init__.py b/plugins/reporters/reporter_of_planning/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py b/plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py new file mode 100644 index 00000000..419c24dc --- /dev/null +++ b/plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py @@ -0,0 +1,26 @@ +# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform" +# +# Copyright © 2023 United States Government as represented by the Administrator of +# the National Aeronautics and Space Administration. No copyright is claimed in the +# United States under Title 17, U.S. Code. All Other Rights Reserved. +# +# Licensed under the NASA Open Source Agreement version 1.3 +# See "NOSA GSC-19165-1 OnAIR.pdf" + +from onair.src.ai_components.ai_plugin_abstract.core import AIPlugIn + +class Plugin(AIPlugIn): + def update(self,low_level_data=[], high_level_data={}): + """ + Given streamed data point, system should update internally + """ + print(f" PLANNING: UPDATE") + print(f" : low_level_data {low_level_data.__class__} = '{low_level_data}'") + print(f" : high_level_data {high_level_data.__class__} = '{high_level_data}'") + + def render_reasoning(self): + """ + System should return its diagnosis + """ + print(" PLANNING: REASONING") + print(" : No args") \ No newline at end of file From 646ff5d74743102566bb5904eaf29905f67d96ae Mon Sep 17 00:00:00 2001 From: Alan Gibson Date: Thu, 1 Feb 2024 13:13:29 -0500 Subject: [PATCH 2/5] Updates to get reporters running after rebase agent.py removed some trailing whitespaces reporters fixed naming of AIPlugin to match new usage --- onair/src/reasoning/agent.py | 12 ++++++------ .../reporter_of_complexity_plugin.py | 4 ++-- .../reporter_of_knowledge_plugin.py | 4 ++-- .../reporter_of_learning_plugin.py | 4 ++-- .../reporter_of_planning_plugin.py | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/onair/src/reasoning/agent.py b/onair/src/reasoning/agent.py index 3725d92c..f85d3b25 100644 --- a/onair/src/reasoning/agent.py +++ b/onair/src/reasoning/agent.py @@ -32,22 +32,22 @@ def render_reasoning(self): return self.complex_reasoning_systems.render_reasoning() def reason(self, frame): - self.vehicle_rep.update(frame) + self.vehicle_rep.update(frame) self.learning_systems.update(self.vehicle_rep.curr_data, self.vehicle_rep.get_state_information()) - self.planning_systems.update(self.vehicle_rep.get_state_information()) - + self.planning_systems.update(self.vehicle_rep.get_state_information()) + aggregate_high_level_info = {'vehicle_rep' : self.vehicle_rep.get_state_information(), 'learning_systems' : self.learning_systems.render_reasoning(), 'planning_systems' : self.planning_systems.render_reasoning()} self.complex_reasoning_systems.update(aggregate_high_level_info) - + return self.render_reasoning() - + def diagnose(self, time_step): """ Grab the mnemonics from the """ learning_system_results = self.learning_systems.render_reasoning() - diagnosis = Diagnosis(time_step, + diagnosis = Diagnosis(time_step, learning_system_results, self.bayesian_status, self.vehicle_rep.get_current_faulting_mnemonics()) diff --git a/plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py b/plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py index 07c41996..248713d0 100644 --- a/plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py +++ b/plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py @@ -7,9 +7,9 @@ # Licensed under the NASA Open Source Agreement version 1.3 # See "NOSA GSC-19165-1 OnAIR.pdf" -from onair.src.ai_components.ai_plugin_abstract.core import AIPlugIn +from onair.src.ai_components.ai_plugin_abstract.ai_plugin import AIPlugin -class Plugin(AIPlugIn): +class Plugin(AIPlugin): def update(self,low_level_data=[], high_level_data={}): """ Given streamed data point, system should update internally diff --git a/plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py b/plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py index ff61e96c..11c94653 100644 --- a/plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py +++ b/plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py @@ -7,9 +7,9 @@ # Licensed under the NASA Open Source Agreement version 1.3 # See "NOSA GSC-19165-1 OnAIR.pdf" -from onair.src.ai_components.ai_plugin_abstract.core import AIPlugIn +from onair.src.ai_components.ai_plugin_abstract.ai_plugin import AIPlugin -class Plugin(AIPlugIn): +class Plugin(AIPlugin): def update(self, low_level_data=[], high_level_data={}): """ Given streamed data point, system should update internally diff --git a/plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py b/plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py index fd9d5e1c..50423e12 100644 --- a/plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py +++ b/plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py @@ -7,9 +7,9 @@ # Licensed under the NASA Open Source Agreement version 1.3 # See "NOSA GSC-19165-1 OnAIR.pdf" -from onair.src.ai_components.ai_plugin_abstract.core import AIPlugIn +from onair.src.ai_components.ai_plugin_abstract.ai_plugin import AIPlugin -class Plugin(AIPlugIn): +class Plugin(AIPlugin): def update(self,low_level_data=[], high_level_data={}): """ Given streamed data point, system should update internally diff --git a/plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py b/plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py index 419c24dc..8f47ec36 100644 --- a/plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py +++ b/plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py @@ -7,9 +7,9 @@ # Licensed under the NASA Open Source Agreement version 1.3 # See "NOSA GSC-19165-1 OnAIR.pdf" -from onair.src.ai_components.ai_plugin_abstract.core import AIPlugIn +from onair.src.ai_components.ai_plugin_abstract.ai_plugin import AIPlugin -class Plugin(AIPlugIn): +class Plugin(AIPlugin): def update(self,low_level_data=[], high_level_data={}): """ Given streamed data point, system should update internally From 556b85f0e6bd4a419f2fdad7b200aab5bd01ea08 Mon Sep 17 00:00:00 2001 From: Alan Gibson Date: Tue, 13 Feb 2024 11:52:23 -0500 Subject: [PATCH 3/5] Reduction to single reporter class Now that multiple use of same plugin can be done, only 1 reporter class required Now reports out via its name Reports function and data, low and high update reports data it was given and records it render_reasoning reports known data Added VERBOSITY constant for easy on/off of data reporting when True, all outputs when False, reporter only states function --- onair/config/reporter_config.ini | 12 ++++--- .../__init__.py | 0 plugins/reporter/reporter_plugin.py | 36 +++++++++++++++++++ .../reporter_of_complexity_plugin.py | 26 -------------- .../reporter_of_knowledge/__init__.py | 0 .../reporter_of_knowledge_plugin.py | 26 -------------- .../reporter_of_learning/__init__.py | 0 .../reporter_of_learning_plugin.py | 26 -------------- .../reporter_of_planning/__init__.py | 0 .../reporter_of_planning_plugin.py | 26 -------------- 10 files changed, 44 insertions(+), 108 deletions(-) rename plugins/{reporters/reporter_of_complexity => reporter}/__init__.py (100%) create mode 100644 plugins/reporter/reporter_plugin.py delete mode 100644 plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py delete mode 100644 plugins/reporters/reporter_of_knowledge/__init__.py delete mode 100644 plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py delete mode 100644 plugins/reporters/reporter_of_learning/__init__.py delete mode 100644 plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py delete mode 100644 plugins/reporters/reporter_of_planning/__init__.py delete mode 100644 plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py diff --git a/onair/config/reporter_config.ini b/onair/config/reporter_config.ini index 3c1b97d8..539af535 100644 --- a/onair/config/reporter_config.ini +++ b/onair/config/reporter_config.ini @@ -5,10 +5,14 @@ TelemetryMetadataFilePath = onair/data/telemetry_configs/ MetaFile = data_physics_generation_CONFIG.json ParserFileName = onair/data_handling/csv_parser.py -KnowledgeRepPluginDict = {'reporter_of_knowledge':'plugins/reporters/reporter_of_knowledge/__init__.py'} -LearnersPluginDict = {'reporter_of_learning':'plugins/reporters/reporter_of_learning/__init__.py'} -PlannersPluginDict = {'reporter_of_planning':'plugins/reporters/reporter_of_planning/__init__.py'} -ComplexPluginDict = {'reporter_of_complexity':'plugins/reporters/reporter_of_complexity/__init__.py'} +KnowledgeRepPluginDict = {'Knowledge Reporter 1':'plugins/reporter', + 'Knowledge Reporter 2':'plugins/reporter'} +LearnersPluginDict = {'Learners Reporter 1':'plugins/reporter', + 'Learners Reporter 2':'plugins/reporter'} +PlannersPluginDict = {'Planner Reporter 1':'plugins/reporter', + 'Planner Reporter 2':'plugins/reporter'} +ComplexPluginDict = {'Complex Reporter 1':'plugins/reporter', + 'Complex Reporter 2':'plugins/reporter'} [RUN_FLAGS] IO_Flag = true diff --git a/plugins/reporters/reporter_of_complexity/__init__.py b/plugins/reporter/__init__.py similarity index 100% rename from plugins/reporters/reporter_of_complexity/__init__.py rename to plugins/reporter/__init__.py diff --git a/plugins/reporter/reporter_plugin.py b/plugins/reporter/reporter_plugin.py new file mode 100644 index 00000000..4b82960a --- /dev/null +++ b/plugins/reporter/reporter_plugin.py @@ -0,0 +1,36 @@ +# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform" +# +# Copyright © 2023 United States Government as represented by the Administrator of +# the National Aeronautics and Space Administration. No copyright is claimed in the +# United States under Title 17, U.S. Code. All Other Rights Reserved. +# +# Licensed under the NASA Open Source Agreement version 1.3 +# See "NOSA GSC-19165-1 OnAIR.pdf" + +from onair.src.ai_components.ai_plugin_abstract.ai_plugin import AIPlugin + +VERBOSE = False + +class Plugin(AIPlugin): + def update(self, low_level_data=[], high_level_data={}): + """ + Reporter outputs that it is updating and outputs known headers and + given low and high level data. + """ + print(f"{self.component_name}: UPDATE") + if VERBOSE: + print(f" : headers {self.headers}") + print(f" : low_level_data {low_level_data.__class__} = '{low_level_data}'") + self.low_level_data = low_level_data + print(f" : high_level_data {high_level_data.__class__} = '{high_level_data}'") + self.high_level_data = high_level_data + + def render_reasoning(self): + """ + Reporter outputs that it is reasoning and gives its known low and + high level data. + """ + print(f"{self.component_name}: RENDER_REASONING") + if VERBOSE: + print(f" : My low_level_data is {self.low_level_data}") + print(f" : My high_level_data is {self.high_level_data}") \ No newline at end of file diff --git a/plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py b/plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py deleted file mode 100644 index 248713d0..00000000 --- a/plugins/reporters/reporter_of_complexity/reporter_of_complexity_plugin.py +++ /dev/null @@ -1,26 +0,0 @@ -# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform" -# -# Copyright © 2023 United States Government as represented by the Administrator of -# the National Aeronautics and Space Administration. No copyright is claimed in the -# United States under Title 17, U.S. Code. All Other Rights Reserved. -# -# Licensed under the NASA Open Source Agreement version 1.3 -# See "NOSA GSC-19165-1 OnAIR.pdf" - -from onair.src.ai_components.ai_plugin_abstract.ai_plugin import AIPlugin - -class Plugin(AIPlugin): - def update(self,low_level_data=[], high_level_data={}): - """ - Given streamed data point, system should update internally - """ - print(f"COMPLEXITY: UPDATE") - print(f" : low_level_data {low_level_data.__class__} = '{low_level_data}'") - print(f" : high_level_data {high_level_data.__class__} = '{high_level_data}'") - - def render_reasoning(self): - """ - System should return its diagnosis - """ - print("COMPLEXITY: REASONING") - print(" : No args") \ No newline at end of file diff --git a/plugins/reporters/reporter_of_knowledge/__init__.py b/plugins/reporters/reporter_of_knowledge/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py b/plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py deleted file mode 100644 index 11c94653..00000000 --- a/plugins/reporters/reporter_of_knowledge/reporter_of_knowledge_plugin.py +++ /dev/null @@ -1,26 +0,0 @@ -# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform" -# -# Copyright © 2023 United States Government as represented by the Administrator of -# the National Aeronautics and Space Administration. No copyright is claimed in the -# United States under Title 17, U.S. Code. All Other Rights Reserved. -# -# Licensed under the NASA Open Source Agreement version 1.3 -# See "NOSA GSC-19165-1 OnAIR.pdf" - -from onair.src.ai_components.ai_plugin_abstract.ai_plugin import AIPlugin - -class Plugin(AIPlugin): - def update(self, low_level_data=[], high_level_data={}): - """ - Given streamed data point, system should update internally - """ - print(f" KNOWLEDGE: UPDATE") - print(f" : low_level_data {low_level_data.__class__} = '{low_level_data}'") - print(f" : high_level_data {high_level_data.__class__} = '{high_level_data}'") - - def render_reasoning(self): - """ - System should return its diagnosis - """ - print(" KNOWLEDGE: REASONING") - print(" : No args") \ No newline at end of file diff --git a/plugins/reporters/reporter_of_learning/__init__.py b/plugins/reporters/reporter_of_learning/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py b/plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py deleted file mode 100644 index 50423e12..00000000 --- a/plugins/reporters/reporter_of_learning/reporter_of_learning_plugin.py +++ /dev/null @@ -1,26 +0,0 @@ -# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform" -# -# Copyright © 2023 United States Government as represented by the Administrator of -# the National Aeronautics and Space Administration. No copyright is claimed in the -# United States under Title 17, U.S. Code. All Other Rights Reserved. -# -# Licensed under the NASA Open Source Agreement version 1.3 -# See "NOSA GSC-19165-1 OnAIR.pdf" - -from onair.src.ai_components.ai_plugin_abstract.ai_plugin import AIPlugin - -class Plugin(AIPlugin): - def update(self,low_level_data=[], high_level_data={}): - """ - Given streamed data point, system should update internally - """ - print(f" LEARNING: UPDATE") - print(f" : low_level_data {low_level_data.__class__} = '{low_level_data}'") - print(f" : high_level_data {high_level_data.__class__} = '{high_level_data}'") - - def render_reasoning(self): - """ - System should return its diagnosis - """ - print(" LEARNING: REASONING") - print(" : No args") \ No newline at end of file diff --git a/plugins/reporters/reporter_of_planning/__init__.py b/plugins/reporters/reporter_of_planning/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py b/plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py deleted file mode 100644 index 8f47ec36..00000000 --- a/plugins/reporters/reporter_of_planning/reporter_of_planning_plugin.py +++ /dev/null @@ -1,26 +0,0 @@ -# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform" -# -# Copyright © 2023 United States Government as represented by the Administrator of -# the National Aeronautics and Space Administration. No copyright is claimed in the -# United States under Title 17, U.S. Code. All Other Rights Reserved. -# -# Licensed under the NASA Open Source Agreement version 1.3 -# See "NOSA GSC-19165-1 OnAIR.pdf" - -from onair.src.ai_components.ai_plugin_abstract.ai_plugin import AIPlugin - -class Plugin(AIPlugin): - def update(self,low_level_data=[], high_level_data={}): - """ - Given streamed data point, system should update internally - """ - print(f" PLANNING: UPDATE") - print(f" : low_level_data {low_level_data.__class__} = '{low_level_data}'") - print(f" : high_level_data {high_level_data.__class__} = '{high_level_data}'") - - def render_reasoning(self): - """ - System should return its diagnosis - """ - print(" PLANNING: REASONING") - print(" : No args") \ No newline at end of file From b4ac8e13235a6baffdde9b9bf4aef34392651c71 Mon Sep 17 00:00:00 2001 From: Alan Gibson Date: Fri, 23 Feb 2024 14:37:50 -0500 Subject: [PATCH 4/5] Updates for reporter plugin Reporter Plugin changed VERBOSE to verbose_mode attribute update moved setting of values to outside of verbose_mode printing Test full coverage testing for both functions in verbose and not verbose --- plugins/reporter/reporter_plugin.py | 12 +-- test/plugins/reporter/test_reporter_plugin.py | 98 +++++++++++++++++++ 2 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 test/plugins/reporter/test_reporter_plugin.py diff --git a/plugins/reporter/reporter_plugin.py b/plugins/reporter/reporter_plugin.py index 4b82960a..e0e84661 100644 --- a/plugins/reporter/reporter_plugin.py +++ b/plugins/reporter/reporter_plugin.py @@ -9,21 +9,21 @@ from onair.src.ai_components.ai_plugin_abstract.ai_plugin import AIPlugin -VERBOSE = False - class Plugin(AIPlugin): + verbose_mode = False + def update(self, low_level_data=[], high_level_data={}): """ Reporter outputs that it is updating and outputs known headers and given low and high level data. """ + self.low_level_data = low_level_data + self.high_level_data = high_level_data print(f"{self.component_name}: UPDATE") - if VERBOSE: + if self.verbose_mode: print(f" : headers {self.headers}") print(f" : low_level_data {low_level_data.__class__} = '{low_level_data}'") - self.low_level_data = low_level_data print(f" : high_level_data {high_level_data.__class__} = '{high_level_data}'") - self.high_level_data = high_level_data def render_reasoning(self): """ @@ -31,6 +31,6 @@ def render_reasoning(self): high level data. """ print(f"{self.component_name}: RENDER_REASONING") - if VERBOSE: + if self.verbose_mode: print(f" : My low_level_data is {self.low_level_data}") print(f" : My high_level_data is {self.high_level_data}") \ No newline at end of file diff --git a/test/plugins/reporter/test_reporter_plugin.py b/test/plugins/reporter/test_reporter_plugin.py new file mode 100644 index 00000000..097bafa5 --- /dev/null +++ b/test/plugins/reporter/test_reporter_plugin.py @@ -0,0 +1,98 @@ +# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform" +# +# Copyright © 2023 United States Government as represented by the Administrator of +# the National Aeronautics and Space Administration. No copyright is claimed in the +# United States under Title 17, U.S. Code. All Other Rights Reserved. +# +# Licensed under the NASA Open Source Agreement version 1.3 +# See "NOSA GSC-19165-1 OnAIR.pdf" + +""" Test Reporter Plugin Functionality """ +import pytest +from unittest.mock import MagicMock +import onair + +from plugins.reporter import reporter_plugin +from plugins.reporter.reporter_plugin import Plugin as Reporter + +# test update +def test_Reporter_update_saves_given_args_and_only_outputs_update_when_not_verbose_mode(mocker): + # Arrange + arg_low_level_data = MagicMock(name='arg_low_level_data') + arg_high_level_data = MagicMock(name='arg_high_level_data') + + cut = Reporter.__new__(Reporter) + cut.component_name = MagicMock(name='fake.cut.component_name') + + mocker.patch(reporter_plugin.__name__ + '.print') + + # Act + cut.update(arg_low_level_data, arg_high_level_data) + + # Assert + assert reporter_plugin.print.call_count == 1 + assert reporter_plugin.print.call_args_list[0].args == (f"{cut.component_name}: UPDATE", ) + assert cut.low_level_data == arg_low_level_data + assert cut.high_level_data == arg_high_level_data + +def test_Reporter_update_saves_given_args_and_outputs_all_info_when_verbose_mode(mocker): + # Arrange + arg_low_level_data = MagicMock(name='arg_low_level_data') + arg_high_level_data = MagicMock(name='arg_high_level_data') + + cut = Reporter.__new__(Reporter) + cut.component_name = MagicMock(name='fake.cut.component_name') + cut.headers = MagicMock(name='fake.cut.headers') + cut.verbose_mode = True + + mocker.patch(reporter_plugin.__name__ + '.print') + + # Act + cut.update(arg_low_level_data, arg_high_level_data) + + # Assert + assert reporter_plugin.print.call_count == 4 + assert reporter_plugin.print.call_args_list[0].args == (f"{cut.component_name}: UPDATE", ) + assert reporter_plugin.print.call_args_list[1].args == (f" : headers {cut.headers}", ) + assert reporter_plugin.print.call_args_list[2].args == (f" : low_level_data {arg_low_level_data.__class__} = '{arg_low_level_data}'", ) + assert reporter_plugin.print.call_args_list[3].args == (f" : high_level_data {arg_high_level_data.__class__} = '{arg_high_level_data}'", ) + assert cut.low_level_data == arg_low_level_data + assert cut.high_level_data == arg_high_level_data + +# test render_reasoning +def test_Reporter_render_reasoning_only_outputs_render_reasoning_when_not_verbose_mode(mocker): + # Arrange + cut = Reporter.__new__(Reporter) + cut.component_name = MagicMock(name='fake.cut.component_name') + cut.verbose_mode = False + + mocker.patch(reporter_plugin.__name__ + '.print') + + # Act + cut.render_reasoning() + + # Assert + assert reporter_plugin.print.call_count == 1 + assert reporter_plugin.print.call_args_list[0].args == (f"{cut.component_name}: RENDER_REASONING", ) + +def test_Reporter_render_reasoning_outputs_all_info_when_verbose_mode(mocker): + # Arrange + cut = Reporter.__new__(Reporter) + cut.component_name = MagicMock(name='fake.cut.component_name') + fake_low_level_data = MagicMock(name='fake_low_level_data') + cut.low_level_data = fake_low_level_data + fake_high_level_data = MagicMock(name='fake_high_level_data') + cut.high_level_data = fake_high_level_data + cut.verbose_mode = True + + mocker.patch(reporter_plugin.__name__ + '.print') + + # Act + cut.render_reasoning() + + # Assert + assert reporter_plugin.print.call_count == 3 + assert reporter_plugin.print.call_args_list[0].args == (f"{cut.component_name}: RENDER_REASONING", ) + assert reporter_plugin.print.call_args_list[1].args == (f" : My low_level_data is {fake_low_level_data}", ) + assert reporter_plugin.print.call_args_list[2].args == (f" : My high_level_data is {fake_high_level_data}", ) + From 667030d8d5a689e515668ef49a4a2dedc885d7ed Mon Sep 17 00:00:00 2001 From: "Marshall, James C 459937851" Date: Fri, 22 Mar 2024 13:25:09 -0400 Subject: [PATCH 5/5] Nitpicking newlines at the end of files. Whitespace only --- plugins/reporter/reporter_plugin.py | 2 +- test/plugins/reporter/test_reporter_plugin.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/reporter/reporter_plugin.py b/plugins/reporter/reporter_plugin.py index e0e84661..986ba942 100644 --- a/plugins/reporter/reporter_plugin.py +++ b/plugins/reporter/reporter_plugin.py @@ -33,4 +33,4 @@ def render_reasoning(self): print(f"{self.component_name}: RENDER_REASONING") if self.verbose_mode: print(f" : My low_level_data is {self.low_level_data}") - print(f" : My high_level_data is {self.high_level_data}") \ No newline at end of file + print(f" : My high_level_data is {self.high_level_data}") diff --git a/test/plugins/reporter/test_reporter_plugin.py b/test/plugins/reporter/test_reporter_plugin.py index 097bafa5..f3f4498a 100644 --- a/test/plugins/reporter/test_reporter_plugin.py +++ b/test/plugins/reporter/test_reporter_plugin.py @@ -95,4 +95,3 @@ def test_Reporter_render_reasoning_outputs_all_info_when_verbose_mode(mocker): assert reporter_plugin.print.call_args_list[0].args == (f"{cut.component_name}: RENDER_REASONING", ) assert reporter_plugin.print.call_args_list[1].args == (f" : My low_level_data is {fake_low_level_data}", ) assert reporter_plugin.print.call_args_list[2].args == (f" : My high_level_data is {fake_high_level_data}", ) -