11import datetime
22from typing import Tuple
33
4+ import semantic_version
5+
46from ted_sws .core .model .metadata import NormalisedMetadata
57from ted_sws .core .model .notice import Notice
68from ted_sws .core .model .transform import MappingSuite
@@ -35,17 +37,6 @@ def check_package(mapping_suite: MappingSuite, notice_metadata: NormalisedMetada
3537 return True if in_date_range and in_version_range and covered_eform_type else False
3638
3739
38- def transform_version_string_into_int (version_string : str ) -> int :
39- """
40- Transforming a version string into a number. (example_version = "1.2.3")
41- :param version_string:
42- :return:
43- """
44- version_numbers = [int (x ) for x in version_string .split ("." )]
45- assert len (version_numbers ) == 3
46- return ((version_numbers [0 ] * 100 ) + version_numbers [1 ]) * 100 + version_numbers [2 ]
47-
48-
4940def notice_eligibility_checker (notice : Notice , mapping_suite_repository : MappingSuiteRepositoryABC ) -> Tuple :
5041 """
5142 Check if notice in eligible for transformation
@@ -60,11 +51,13 @@ def notice_eligibility_checker(notice: Notice, mapping_suite_repository: Mapping
6051 possible_mapping_suites .append (mapping_suite )
6152
6253 if possible_mapping_suites :
63- best_version = max ([transform_version_string_into_int (version_string = mapping_suite .version ) for mapping_suite in
64- possible_mapping_suites ])
65- mapping_suite_identifier = next ((mapping_suite .identifier for mapping_suite in possible_mapping_suites if
66- transform_version_string_into_int (
67- version_string = mapping_suite .version ) == best_version ), None )
54+ best_version = possible_mapping_suites [0 ].version
55+ mapping_suite_identifier = possible_mapping_suites [0 ].identifier
56+ for mapping_suite in possible_mapping_suites [1 :]:
57+ if semantic_version .Version (mapping_suite .version ) > semantic_version .Version (best_version ):
58+ best_version = mapping_suite .version
59+ mapping_suite_identifier = mapping_suite .identifier
60+
6861 notice .set_is_eligible_for_transformation (eligibility = True )
6962 return notice .ted_id , mapping_suite_identifier
7063 else :
0 commit comments