From c4a437db506f2404c0c0330538228408f489ab15 Mon Sep 17 00:00:00 2001 From: Dennis Priskorn Date: Wed, 7 Aug 2024 20:24:46 +0200 Subject: [PATCH] rewrite: Add skip option which does nothing and rename one option to make it clear you get more information. --- src/models/enrich_hiking_trails.py | 8 ++++--- src/models/questionary_return.py | 4 ++-- src/models/trail_item.py | 36 +++++++++++++++++------------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/models/enrich_hiking_trails.py b/src/models/enrich_hiking_trails.py index b7f3a25..e6800b1 100644 --- a/src/models/enrich_hiking_trails.py +++ b/src/models/enrich_hiking_trails.py @@ -99,9 +99,10 @@ def __lookup_in_osm_wikidata_link__(trail_item: TrailItem) -> TrailItem: @staticmethod def __lookup_in_waymarked_trails__(trail_item: TrailItem) -> None: trail_item.fetch_and_lookup_from_waymarked_trails_and_present_choice_to_user() - # if trail_item.questionary_return.quit: - # break - if trail_item.questionary_return.could_not_decide: + if trail_item.questionary_return.skip: + # return early + return + if trail_item.questionary_return.more_information: if not trail_item.item: raise NoItemError() console.print( @@ -144,6 +145,7 @@ def __iterate_items__(self): # geometry from Overpass API and checking if # each of them are in the right # 1) country 2) region 3) municipality + # or just how near the centeroid of the QID is to the OSM one self.__lookup_in_waymarked_trails__(trail_item=trail_item) else: logger.info( diff --git a/src/models/questionary_return.py b/src/models/questionary_return.py index e2a7c32..d1f61bf 100644 --- a/src/models/questionary_return.py +++ b/src/models/questionary_return.py @@ -3,6 +3,6 @@ class QuestionaryReturn(ProjectBaseModel): osm_id: int = 0 - could_not_decide: bool = False + more_information: bool = False no_match: bool = False - quit: bool = False + skip: bool = False diff --git a/src/models/trail_item.py b/src/models/trail_item.py index 3457a34..79bc9ae 100644 --- a/src/models/trail_item.py +++ b/src/models/trail_item.py @@ -181,6 +181,18 @@ def __parse_not_found_in_osm_last_update_statement__(self): except KeyError: logger.info("No 'not found in'-claims on this item") + def __set_no_match__(self): + if not self.item: + raise NoItemError() + console.print( + f"No choices from Waymarked Trials " + f"API = no match for " + f"{self.item.get_entity_url()}" + ) + return_ = QuestionaryReturn() + return_.no_match = True + self.questionary_return = return_ + def __lookup_label_on_waymarked_trails_and_ask_user_to_choose_a_match__( self, ) -> None: @@ -201,31 +213,25 @@ def __lookup_label_on_waymarked_trails_and_ask_user_to_choose_a_match__( self.__remove_waymaked_result_duplicates__() self.__get_details_from_waymarked_trails__() self.__prepare_choices__() - if len(self.choices) > 2: + # the last 3 choices are not matchable + if len(self.choices) > 3: self.questionary_return = self.__ask_question__() else: - if not self.item: - raise NoItemError() - console.print( - f"No choices from Waymarked Trials " - f"API = no match for " - f"{self.item.get_entity_url()}" - ) - return_ = QuestionaryReturn() - return_.no_match = True - self.questionary_return = return_ + # Assuming no match because we got nothing from WT API + self.__set_no_match__() def __prepare_choices__(self): self.__convert_waymarked_results_to_choices__() self.choices.append( Choice( - title="Unable to decide whether these match", - value=QuestionaryReturn(could_not_decide=True), + title="Unable to decide whether these match, show me more information", + value=QuestionaryReturn(more_information=True), ) ) self.choices.append( Choice(title="None of these match", value=QuestionaryReturn(no_match=True)) ) + self.choices.append(Choice(title="Skip", value=QuestionaryReturn(skip=True))) def __ask_question__(self) -> QuestionaryReturn: """This presents a choice and returns""" @@ -589,7 +595,7 @@ def __remove_not_found_in_osm_claim__(self) -> None: logger.debug("No NOT_FOUND_IN found on this item to remove") def try_matching_again(self): - if self.questionary_return.could_not_decide is True: + if self.questionary_return.more_information is True: result = questionary.select( "Do you want to match again after manually ", choices=[ @@ -607,7 +613,7 @@ def __verify_P402_claim_exists__(item: ItemEntity) -> bool: for claim in item.claims: property_numbers_found.append(claim.mainsnak.property_number) if claim.mainsnak.property_number == Property.OSM_RELATION_ID.value: - print("P402 found") + logger.debug("P402 found") found = True # print(property_numbers_found) return found