[fix] conditions in place config

This commit is contained in:
Al
2016-07-31 03:09:51 -04:00
parent cec4914233
commit 99333d58ca

View File

@@ -32,6 +32,12 @@ class PlaceConfig(object):
AddressFormatter.COUNTRY, AddressFormatter.COUNTRY,
} }
numeric_ops = (('lte', operator.le),
('gt', operator.gt),
('lt', operator.lt),
('gte', operator.ge),
)
def __init__(self, config_file=PLACE_CONFIG_FILE): def __init__(self, config_file=PLACE_CONFIG_FILE):
self.cache = {} self.cache = {}
place_config = yaml.load(open(config_file)) place_config = yaml.load(open(config_file))
@@ -76,13 +82,20 @@ class PlaceConfig(object):
population = 0 population = 0
for exc in population_exceptions: for exc in population_exceptions:
funcs = [] support = 0
for k, op in (('lte', operator.le), ('gt', operator.gt), ('lt', operator.lt), ('gte', operator.ge)):
if k in exc and not op(exc[k], population): for k, op in self.numeric_ops:
if k not in exc:
continue
res = op(exc[k], population)
if not res:
support = 0
break break
else:
probability = exc.get('probability', 0.0) if support > 0:
return random.random() < probability probability = exc.get('probability', 0.0)
return random.random() < probability
probability = self.get_property(('components', component, 'probability'), country=country, default=0.0) probability = self.get_property(('components', component, 'probability'), country=country, default=0.0)