Allow to define the threshold between a housing and a station

Fix #101.
This commit is contained in:
Lucas Verney 2017-12-29 22:58:05 +01:00
parent b685a71eab
commit 1119bdbf0b
3 changed files with 9 additions and 3 deletions

View File

@ -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`

View File

@ -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"]

View File

@ -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)