22from typing import List
33from strenum import StrEnum
44
5- from converter import (ConversionResult , ConversionResults , ConversionPaths , Converter , conversion_path_to_string , ConversionsCache )
5+ from converter import (ConversionResult , ConversionResults , ConversionPaths , Converter , conversion_path_to_string ,
6+ ConversionsCache )
67from schema_types import SchemaLanguage
78
89DETAILED_ERROR_OUTPUT = False
10+ DETAILED_RESULT_OUTPUT = True
911
1012
1113class ConversionStrategy (StrEnum ):
@@ -20,7 +22,6 @@ def convert_with_strategy_least_character_loss(source: SchemaLanguage, target: S
2022 all_attempts : List [ConversionResult ] = []
2123 conversions_cache = {} # cache for all conversion sub-paths
2224 for path in paths :
23- result_schema = None
2425 try :
2526 result_schema , conversions_cache_update = attempt_conversion_path (source , target , path , schema ,
2627 conversions_cache )
@@ -40,6 +41,18 @@ def convert_with_strategy_least_character_loss(source: SchemaLanguage, target: S
4041 # sort all attempts by success: success first. Then by length of resulting schema (descending)
4142 all_attempts .sort (key = lambda x : (not x [0 ], - len (x [1 ]) if x [0 ] else float ('inf' )))
4243
44+ # print overall result: how many succeeded/failed and their character lengths
45+ success_count = sum (1 for attempt in all_attempts if attempt [0 ])
46+ failure_count = len (all_attempts ) - success_count
47+ print (f"Conversion attempts completed: { success_count } succeeded, { failure_count } failed." )
48+ for i , attempt in enumerate (all_attempts ):
49+ success , result_schema_or_error , path = attempt
50+ if success :
51+ print (
52+ f"- Attempt { i + 1 } ({ conversion_path_to_string (path )} ): Success, Resulting schema length: { len (result_schema_or_error )} characters." )
53+ else :
54+ print (f"- Attempt { i + 1 } ({ conversion_path_to_string (path )} ): Failure, Error: { result_schema_or_error } " )
55+
4356 return all_attempts
4457
4558
@@ -72,8 +85,9 @@ def attempt_conversion_path(source: str, target: str, path: List[Converter], sch
7285 else :
7386 # cache miss - perform conversion
7487 current_schema = conv .convert (current_schema )
75- print (
76- "Intermediate schema of format " + conv .target_format + " after conversion via " + conv .service_name + ": " + current_schema )
88+ if DETAILED_RESULT_OUTPUT :
89+ print (
90+ "\n \n Intermediate schema of format " + conv .target_format + " after conversion via " + conv .service_name + ": \n " + current_schema + "\n \n \n \n " )
7791 # store in cache
7892 conversions_cache [conversion_sub_path_hash ] = current_schema
7993
@@ -88,6 +102,6 @@ def attempt_conversion_path(source: str, target: str, path: List[Converter], sch
88102
89103
90104def print_conversion_path (source : str , target : str , path : List [Converter ]) -> None :
91- print ("Given the source format " + source + " and target format " + target + ", the best available path is :" )
105+ print ("Conversion path for source format ' " + source + "' and target format ' " + target + "' :" )
92106 for conv in path :
93- print (f"{ conv .source_format } -> { conv .target_format } via { conv .name } ( { conv .service_address } )" )
107+ print (f"- { conv .source_format } --( { conv .name } ( { conv .service_address } )--> { conv .target_format } )" )
0 commit comments