Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

82 add reporter plugins #121

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions onair/config/reporter_config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[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 = {'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
Dev_Flag = false
Viz_Flag = false
12 changes: 6 additions & 6 deletions onair/src/reasoning/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Empty file added plugins/reporter/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions plugins/reporter/reporter_plugin.py
Original file line number Diff line number Diff line change
@@ -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

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 self.verbose_mode:
print(f" : headers {self.headers}")
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):
"""
Reporter outputs that it is reasoning and gives its known low and
high level data.
"""
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}")
97 changes: 97 additions & 0 deletions test/plugins/reporter/test_reporter_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# 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}", )
Loading