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

add args to conversion to be returnable as json #1512

Merged
merged 8 commits into from
Oct 28, 2024
Merged

Conversation

JL-Brothers
Copy link
Contributor

Closes Issue #698

Copy link

sonarcloud bot commented Sep 4, 2024

Copy link

codecov bot commented Sep 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.51%. Comparing base (6b5acfc) to head (e8bf78f).
Report is 36 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1512      +/-   ##
==========================================
+ Coverage   76.44%   76.51%   +0.07%     
==========================================
  Files         618      618              
  Lines       46891    46894       +3     
  Branches      849      849              
==========================================
+ Hits        35844    35881      +37     
+ Misses      10952    10918      -34     
  Partials       95       95              
Flag Coverage Δ
frontend 56.14% <ø> (-0.11%) ⬇️
python 83.89% <ø> (-0.06%) ⬇️
ruby-api 48.82% <ø> (+1.22%) ⬆️
ruby-backend 82.52% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ryanmelt ryanmelt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need look through all the existing conversion classes and if they take arguments make sure the @params variable gets filled with those arguments.

If possible remove subclass as_json methods where they would do the same thing as the base class if @params is filled out.

@@ -67,6 +70,7 @@ def as_json(*_a)
result['converted_type'] = @converted_type if @converted_type
result['converted_bit_size'] = @converted_bit_size if @converted_bit_size
result['converted_array_size'] = @converted_array_size if @converted_array_size
result['args'] = JSON.generate(@args) if @args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as_json shouldn't call JSON.generate. The goal is return objects that are ready to be converted to JSON, but not return an actual JSON string yet. Change to "= @params.as_json(*a)" and remove underscore from the existing _a

@@ -61,4 +63,6 @@ def as_json(self):
result["converted_bit_size"] = self.converted_bit_size
if self.converted_array_size is not None:
result["converted_array_size"] = self.converted_array_size
if self.args is not None:
result["args"] = json.dumps(self.args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in Ruby.

openc3/templates/conversion/conversion.py Outdated Show resolved Hide resolved
@@ -30,12 +30,15 @@ class Conversion
attr_reader :converted_bit_size
# @return [Integer] The size in bits of the converted array value
attr_reader :converted_array_size
# @return [] The Array of arguments passed in
attr_reader :args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably rename to params. If you look at the as_json method in a lot of our existing conversion classes they already are reporting their arguments as 'params'

@@ -12,6 +12,8 @@ def initialize
# Size of the converted type in bits
# Use 0 for :STRING or :BLOCK where the size can be variable
@converted_bit_size = 0
# return the arguments used
@args = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should default to nil, like in the base class.

@jmthomas jmthomas marked this pull request as ready for review October 17, 2024 23:45
@@ -40,6 +40,7 @@ def initialize(processor_name, result_name, converted_type = nil, converted_bit_
end
@converted_bit_size = Integer(converted_bit_size) if ConfigParser.handle_nil(converted_bit_size)
@converted_array_size = Integer(converted_array_size) if ConfigParser.handle_nil(converted_array_size)
@params = [@processor_name, @result_name]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MIssing converted_ params

Copy link
Member

@jmthomas jmthomas Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base class records those ... they are output in the to_config method. as_json outputs them separately and the remaining parameters get put into params.

@@ -25,12 +25,14 @@ class Conversion:
# attr_reader :converted_bit_size
# # self.return [Integer] The size in bits of the converted array value
# attr_reader :converted_array_size
# attr_reader :args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be params

@@ -45,6 +45,7 @@ def __init__(
self.converted_bit_size = int(converted_bit_size)
if ConfigParser.handle_none(converted_array_size):
self.converted_array_size = int(converted_array_size)
self.params = [self.processor_name, self.result_name]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing converted_ params

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base class records those ... they are output in the to_config method. as_json outputs them separately and the remaining parameters get put into params.

@@ -17,6 +17,7 @@ def __init__(self):
# a string, integer, float, or array of values.
# @param packet [Packet] The packet object where the conversion is defined
# @param buffer [String] The raw packet buffer
# @param args [Array] The arguments to return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove args

@ryanmelt
Copy link
Member

This ticket still needs to capture all params.

Copy link

sonarcloud bot commented Oct 28, 2024

@ryanmelt ryanmelt merged commit 70c8d56 into main Oct 28, 2024
27 checks passed
@ryanmelt ryanmelt deleted the conversion_args_json branch October 28, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants