From d17792c741ac9bfdbbabeb4d73d800006344f6e4 Mon Sep 17 00:00:00 2001 From: Asher Glick Date: Sun, 26 May 2024 12:49:18 -0500 Subject: [PATCH] adding examples for compound fields based on their components --- xml_converter/doc/rotation/euler_rotation.md | 6 +++- xml_converter/generators/main.py | 35 +++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/xml_converter/doc/rotation/euler_rotation.md b/xml_converter/doc/rotation/euler_rotation.md index 6e65adb0..cfeff7ce 100644 --- a/xml_converter/doc/rotation/euler_rotation.md +++ b/xml_converter/doc/rotation/euler_rotation.md @@ -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 ===== diff --git a/xml_converter/generators/main.py b/xml_converter/generators/main.py index 873c4aaa..7e7f99e7 100644 --- a/xml_converter/generators/main.py +++ b/xml_converter/generators/main.py @@ -207,14 +207,27 @@ def generate_auto_docs(self, metadata: Dict[str, MetadataType], content: Dict[st valid_values += "" 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, @@ -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(): @@ -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 #