Skip to content

Commit

Permalink
Merge pull request #305 from AsherGlick/compound_examples
Browse files Browse the repository at this point in the history
Adding examples for compound fields based on their components
  • Loading branch information
AsherGlick authored May 27, 2024
2 parents 6f60bcb + d17792c commit f449e95
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
6 changes: 5 additions & 1 deletion xml_converter/doc/rotation/euler_rotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ components:
type: Float32
xml_fields: [RotateX]
protobuf_field: "x"
examples: ["180", "90", "0", "85", "-90", "0.01"]

- name: Y Rotation
type: Float32
xml_fields: [RotateY]
protobuf_field: "y"
examples: ["10", "-18", "0", "-1.5", "20", "359"]

- name: Z Rotation
type: Float32
xml_fields: [RotateZ]
protobuf_field: "z"
examples: ["-38", "-10.55", "-0.65", "123", "53.5", "-75"]

---
Euler X Y Z rotation.
Euler X Y Z rotation in degrees.
Can be any floating point value but will be modulo 360 when applied

Notes
=====
Expand Down
35 changes: 31 additions & 4 deletions xml_converter/generators/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,27 @@ def generate_auto_docs(self, metadata: Dict[str, MetadataType], content: Dict[st
valid_values += "</table>"

elif fieldval.variable_type == "CompoundValue":
print(" Unknown examples for {} {}".format(fieldval.variable_type, fieldkey))
subcomponent_examples = [
self.get_examples(
field_type=x.subcomponent_type.value,
field_key=fieldkey + "[" + x.name + "]",
examples=x.examples
) for x in fieldval.components
]

compound_examples = build_combinations(
subcomponent_examples
)

# TODO: the get_examples function above is not great because it puts quotes around everything and we need to remove them before joining
examples = ["\"" + ",".join([y.strip("\"") for y in x]) + "\"" for x in compound_examples]

example = self.build_example(
type=fieldval.variable_type,
applies_to=fieldval.applies_to_as_str(),
xml_field=fieldval.xml_fields[0],
examples=["???TODO???"]
examples=examples
)
# ",".join( [ self.get_examples(x['type'], fieldval['applies_to'], fieldval['xml_fields'][0]) for x in fieldval['components'] ])
else:
example = self.build_example(
type=fieldval.variable_type,
Expand All @@ -225,7 +238,6 @@ def generate_auto_docs(self, metadata: Dict[str, MetadataType], content: Dict[st
field_key=fieldkey,
)
)
# self.get_examples(fieldval['type'], fieldval['applies_to'], fieldval['xml_fieldsval'][0])

proto_field_type: str = ""
for marker_type in fieldval.applies_to_as_str():
Expand Down Expand Up @@ -290,6 +302,21 @@ def generate_auto_docs(self, metadata: Dict[str, MetadataType], content: Dict[st
return template.render(field_rows=field_rows), field_rows


def build_combinations(inputs: List[List[str]]) -> List[List[str]]:
output_list: List[List[str]] = []

longest_input_list = max([len(x) for x in inputs])

for i in range(longest_input_list):
inner_list: List[str] = []
for input_list in inputs:
inner_list.append(input_list[i % len(input_list)])

output_list.append(inner_list)

return output_list


################################################################################
# main
#
Expand Down

0 comments on commit f449e95

Please sign in to comment.