Browse Source

Allow to define the threshold between a housing and a station

Fix #101.
merge-requests/15/head
Lucas Verney 5 years ago
parent
commit
1119bdbf0b
  1. 3
      doc/0.getting_started.md
  2. 4
      flatisfy/config.py
  3. 5
      flatisfy/filters/metadata.py

3
doc/0.getting_started.md

@ -121,6 +121,9 @@ List of configuration options: @@ -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`

4
flatisfy/config.py

@ -44,6 +44,9 @@ DEFAULT_CONFIG = { @@ -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): @@ -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"]

5
flatisfy/filters/metadata.py

@ -240,18 +240,17 @@ def guess_postal_code(flats_list, constraint, config, distance_threshold=20000): @@ -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)

Loading…
Cancel
Save