Skip to content

Commit

Permalink
ability to compare version with x.y.z format
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragos0000 committed Apr 25, 2022
1 parent bd22467 commit 4cb51f1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
17 changes: 15 additions & 2 deletions ted_sws/notice_eligibility/services/notice_eligibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ def check_package(mapping_suite: MappingSuite, notice_metadata: NormalisedMetada
return True if not filtered_df.empty else False


def transform_version_string_into_int(version_string: str) -> int:
"""
Transforming a version string into a number. (example_version = "1.2.3")
:param version_string:
:return:
"""
version_numbers = [int(x) for x in version_string.split(".")]
assert len(version_numbers) == 3
return ((version_numbers[0] * 100) + version_numbers[1]) * 100 + version_numbers[2]


def notice_eligibility_checker(notice: Notice, mapping_suite_repository: MappingSuiteRepositoryABC) -> Tuple:
"""
Check if notice in eligible for transformation
Expand All @@ -51,9 +62,11 @@ def notice_eligibility_checker(notice: Notice, mapping_suite_repository: Mapping
possible_mapping_suites.append(mapping_suite)

if possible_mapping_suites:
best_version = max([mapping_suite.version for mapping_suite in possible_mapping_suites])
best_version = max([transform_version_string_into_int(version_string=mapping_suite.version) for mapping_suite in
possible_mapping_suites])
mapping_suite_identifier = next((mapping_suite.identifier for mapping_suite in possible_mapping_suites if
mapping_suite.version == str(best_version)), None)
transform_version_string_into_int(
version_string=mapping_suite.version) == best_version), None)
notice.set_is_eligible_for_transformation(eligibility=True)
return notice.ted_id, mapping_suite_identifier
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "no_title",
"created_at": "2022-03-20T19:46:14.069518",
"identifier": "test_package",
"version": "0.1",
"version": "0.1.1",
"ontology_version": "3.0.0.alpha",
"xsd_version": "R2.0.9.S05.E01",
"metadata_constraints": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "no_title",
"created_at": "2022-04-20T19:46:14.069518",
"identifier": "test_package2",
"version": "2.1",
"version": "2.1.6",
"ontology_version": "3.0.0.alpha",
"metadata_constraints": {
"constraints": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"title": "no_title",
"created_at": "2022-04-20T19:46:14.069518",
"identifier": "test_package2",
"version": "2.1",
"identifier": "test_package3",
"version": "2.0.1",
"ontology_version": "3.0.0.alpha",
"metadata_constraints": {
"constraints": {
Expand Down
9 changes: 8 additions & 1 deletion tests/unit/notice_eligibility/test_eligibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ted_sws.data_manager.adapters.mapping_suite_repository import MappingSuiteRepositoryInFileSystem
from ted_sws.metadata_normaliser.services.metadata_normalizer import MetadataNormaliser
from ted_sws.notice_eligibility.services.notice_eligibility import create_eligibility_df, check_package, \
notice_eligibility_checker, notice_eligibility_checker_by_id
notice_eligibility_checker, notice_eligibility_checker_by_id, transform_version_string_into_int


def test_non_eligibility_by_notice(file_system_repository_path, raw_notice):
Expand Down Expand Up @@ -59,3 +59,10 @@ def test_check_mapping_suite(file_system_repository_path, normalised_metadata_ob
is_valid = check_package(mapping_suite=mapping_suite_repository.get("test_package"),
notice_metadata=normalised_metadata_object)
assert not is_valid


def test_transform_version_string_into_int():
funky_version_string = "5.7.6"
funky_version_int = transform_version_string_into_int(version_string=funky_version_string)
assert isinstance(funky_version_int, int)
assert funky_version_int == 50706

0 comments on commit 4cb51f1

Please sign in to comment.