From 1119bdbf0b024f1ef705c29b761e3ab56ebca19d Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Fri, 29 Dec 2017 22:58:05 +0100 Subject: [PATCH] Allow to define the threshold between a housing and a station Fix #101. --- doc/0.getting_started.md | 3 +++ flatisfy/config.py | 4 ++++ flatisfy/filters/metadata.py | 5 ++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/doc/0.getting_started.md b/doc/0.getting_started.md index e8f69bc..36be5af 100644 --- a/doc/0.getting_started.md +++ b/doc/0.getting_started.md @@ -121,6 +121,9 @@ List of configuration options: fetch personal data from housing posts and store them in database. Such personal data include contact phone number for instance. By default, Flatisfy does not store such personal data. +* `max_distance_housing_station` is the maximum distance (in meters) between + an housing and a public transport station found for this housing (default is + `1500`). This is useful to avoid false-positive. _Note:_ In production, you can either use the `serve` command with a reliable webserver instead of the default Bottle webserver (specifying a `webserver` diff --git a/flatisfy/config.py b/flatisfy/config.py index 37c10f2..2211944 100644 --- a/flatisfy/config.py +++ b/flatisfy/config.py @@ -44,6 +44,9 @@ DEFAULT_CONFIG = { # Whether or not to store personal data from housing posts (phone number # etc) "store_personal_data": False, + # Max distance between an housing and a found station, to avoid + # false-positive + "max_distance_housing_station": 1500, # Navitia API key "navitia_api_key": None, # Number of filtering passes to run @@ -140,6 +143,7 @@ def validate_config(config, check_with_data): assert config["smtp_to"] is None or isinstance(config["smtp_to"], list) assert isinstance(config["store_personal_data"], bool) + assert isinstance(config["max_distance_housing_station"], int) or isinstance(config["max_distance_housing_station"], float) # noqa: E501 # Ensure constraints are ok assert config["constraints"] diff --git a/flatisfy/filters/metadata.py b/flatisfy/filters/metadata.py index 55ad3e3..b8619d8 100644 --- a/flatisfy/filters/metadata.py +++ b/flatisfy/filters/metadata.py @@ -240,18 +240,17 @@ def guess_postal_code(flats_list, constraint, config, distance_threshold=20000): return flats_list -def guess_stations(flats_list, constraint, config, distance_threshold=1500): +def guess_stations(flats_list, constraint, config): """ Try to match the station field with a list of available stations nearby. :param flats_list: A list of flats dict. :param constraint: The constraint that the ``flats_list`` should satisfy. :param config: A config dict. - :param distance_threshold: Maximum distance (in meters) between the center - of the postal code and the station to consider it ok. :return: An updated list of flats dict with guessed nearby stations. """ + distance_threshold = config['max_distance_housing_station'] opendata = { "postal_codes": data.load_data(PostalCode, constraint, config), "stations": data.load_data(PublicTransport, constraint, config)