Rename minimum_photos config option to minimum_nb_photos

This commit is contained in:
Lucas Verney 2017-10-29 20:03:39 +01:00
parent 5bce6369ec
commit f81deb9f13
3 changed files with 12 additions and 10 deletions

View File

@ -153,6 +153,8 @@ under the `constraints` key. The available constraints are:
`null`) from the place identified by the GPS coordinates `LAT` and `LNG` `null`) from the place identified by the GPS coordinates `LAT` and `LNG`
(latitude and longitude), and we call this place `foobar` in human-readable (latitude and longitude), and we call this place `foobar` in human-readable
form. Beware that `time` constraints are in **seconds**. form. Beware that `time` constraints are in **seconds**.
* `minimum_nb_photos` let you filter out posts with less than this number of
photos.
You can think of constraints as "a set of criterias to filter out flats". You You can think of constraints as "a set of criterias to filter out flats". You

View File

@ -34,7 +34,7 @@ DEFAULT_CONFIG = {
"cost": (None, None), # (min, max) in currency unit "cost": (None, None), # (min, max) in currency unit
"rooms": (None, None), # (min, max) "rooms": (None, None), # (min, max)
"bedrooms": (None, None), # (min, max) "bedrooms": (None, None), # (min, max)
"minimum_photos": None, "minimum_nb_photos": None, # min number of photos
"time_to": {} # Dict mapping names to {"gps": [lat, lng], "time_to": {} # Dict mapping names to {"gps": [lat, lng],
# "time": (min, max) } # "time": (min, max) }
# Time is in seconds # Time is in seconds
@ -139,10 +139,10 @@ def validate_config(config, check_with_data):
assert isinstance(constraint["type"], str) assert isinstance(constraint["type"], str)
assert constraint["type"].upper() in ["RENT", "SALE", "SHARING"] assert constraint["type"].upper() in ["RENT", "SALE", "SHARING"]
assert "minimum_photos" in constraint assert "minimum_nb_photos" in constraint
if constraint["minimum_photos"]: if constraint["minimum_nb_photos"]:
assert isinstance(constraint["minimum_photos"], int) assert isinstance(constraint["minimum_nb_photos"], int)
assert constraint["minimum_photos"] >= 0 assert constraint["minimum_nb_photos"] >= 0
assert "house_types" in constraint assert "house_types" in constraint
assert constraint["house_types"] assert constraint["house_types"]

View File

@ -80,7 +80,7 @@ def refine_with_housing_criteria(flats_list, constraint):
) )
def refine_with_minimum_photos(flats_list, constraint): def refine_with_minimum_nb_photos(flats_list, constraint):
""" """
Filter a list of flats according to the minimum number of photos criterion. Filter a list of flats according to the minimum number of photos criterion.
@ -99,7 +99,7 @@ def refine_with_minimum_photos(flats_list, constraint):
# Check number of pictures # Check number of pictures
has_enough_photos = tools.is_within_interval( has_enough_photos = tools.is_within_interval(
flat.get('photos', []), flat.get('photos', []),
constraint['minimum_photos'], constraint['minimum_nb_photos'],
None None
) )
if not has_enough_photos: if not has_enough_photos:
@ -107,7 +107,7 @@ def refine_with_minimum_photos(flats_list, constraint):
"Flat %s only has %d photos, it should have at least %d.", "Flat %s only has %d photos, it should have at least %d.",
flat["id"], flat["id"],
len(flat['photos']), len(flat['photos']),
constraint['minimum_photos'] constraint['minimum_nb_photos']
) )
is_ok[i] = False is_ok[i] = False
@ -203,7 +203,7 @@ def second_pass(flats_list, constraint, config):
constraint) constraint)
# Remove return housing posts which do not have enough photos # Remove return housing posts which do not have enough photos
flats_list, ignored_list = refine_with_minimum_photos(flats_list, flats_list, ignored_list = refine_with_minimum_nb_photos(flats_list,
constraint) constraint)
return { return {