Merge branch 'issue_101' into 'master'

Allow to define the threshold between a housing and a station

Closes #101

See merge request Phyks/flatisfy!15
This commit is contained in:
Lucas Verney 2017-12-30 14:25:20 +01:00
commit 764689f83c
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)