Add mapzen config and integrate into legacy code
This commit is contained in:
parent
8ad2434b1d
commit
3a6cc4c364
@ -147,6 +147,7 @@ RETURNS Geometry AS $$
|
|||||||
from cartodb_services.refactor.tools.logger import LoggerConfigBuilder
|
from cartodb_services.refactor.tools.logger import LoggerConfigBuilder
|
||||||
from cartodb_services.refactor.storage.redis_config import RedisMetadataConnectionConfigBuilder
|
from cartodb_services.refactor.storage.redis_config import RedisMetadataConnectionConfigBuilder
|
||||||
from cartodb_services.refactor.storage.redis_connection import RedisConnectionBuilder
|
from cartodb_services.refactor.storage.redis_connection import RedisConnectionBuilder
|
||||||
|
from cartodb_services.refactor.service.mapzen_geocoder import MapzenGeocoderConfigBuilder
|
||||||
|
|
||||||
server_config_storage = InDbServerConfigStorage()
|
server_config_storage = InDbServerConfigStorage()
|
||||||
|
|
||||||
@ -158,7 +159,9 @@ RETURNS Geometry AS $$
|
|||||||
user_config_storage = UserConfigStorageFactory(redis_metadata_connection, username).get()
|
user_config_storage = UserConfigStorageFactory(redis_metadata_connection, username).get()
|
||||||
org_config_storage = OrgConfigStorageFactory(redis_metadata_connection, orgname).get()
|
org_config_storage = OrgConfigStorageFactory(redis_metadata_connection, orgname).get()
|
||||||
|
|
||||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
# TODO rename this variable
|
||||||
|
user_geocoder_config = MapzenGeocoderConfigBuilder(server_config_storage, user_config_storage, org_config_storage, username, orgname).get()
|
||||||
|
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,113 @@
|
|||||||
|
from dateutil.parser import parse as date_parse
|
||||||
|
|
||||||
|
# TODO: rename this file
|
||||||
|
class MapzenGeocoderConfig(object):
|
||||||
|
"""
|
||||||
|
Value object that represents the configuration needed to operate the mapzen service.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
geocoding_quota,
|
||||||
|
soft_geocoding_limit,
|
||||||
|
period_end_date,
|
||||||
|
cost_per_hit,
|
||||||
|
log_path,
|
||||||
|
mapzen_api_key,
|
||||||
|
username,
|
||||||
|
organization):
|
||||||
|
self._geocoding_quota = geocoding_quota
|
||||||
|
self._soft_geocoding_limit = soft_geocoding_limit
|
||||||
|
self._period_end_date = period_end_date
|
||||||
|
self._cost_per_hit = cost_per_hit
|
||||||
|
self._log_path = log_path
|
||||||
|
self._mapzen_api_key = mapzen_api_key
|
||||||
|
self._username = username
|
||||||
|
self._organization = organization
|
||||||
|
|
||||||
|
# Kind of generic properties. Note which ones are for actually running the
|
||||||
|
# service and which ones are needed for quota stuff.
|
||||||
|
@property
|
||||||
|
def service_type(self):
|
||||||
|
return 'geocoder_mapzen'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def provider(self):
|
||||||
|
return 'mapzen'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_high_resolution(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def geocoding_quota(self):
|
||||||
|
return self._geocoding_quota
|
||||||
|
|
||||||
|
@property
|
||||||
|
def soft_geocoding_limit(self):
|
||||||
|
return self._soft_geocoding_limit
|
||||||
|
|
||||||
|
@property
|
||||||
|
def period_end_date(self):
|
||||||
|
return self._period_end_date
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cost_per_hit(self):
|
||||||
|
return self._cost_per_hit
|
||||||
|
|
||||||
|
# Server config, TODO: locate where this is actually used
|
||||||
|
@property
|
||||||
|
def log_path(self):
|
||||||
|
return self._log_path
|
||||||
|
|
||||||
|
# This is actually the specific one to run requests against the remote endpoitn
|
||||||
|
@property
|
||||||
|
def mapzen_api_key(self):
|
||||||
|
return self._mapzen_api_key
|
||||||
|
|
||||||
|
# These two identify the user
|
||||||
|
@property
|
||||||
|
def username(self):
|
||||||
|
return self._username
|
||||||
|
@property
|
||||||
|
def organization(self):
|
||||||
|
return self._organization
|
||||||
|
|
||||||
|
# TODO: for BW compat, remove
|
||||||
|
@property
|
||||||
|
def google_geocoder(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class MapzenGeocoderConfigBuilder(object):
|
||||||
|
|
||||||
|
def __init__(self, server_conf, user_conf, org_conf, username, orgname):
|
||||||
|
self._server_conf = server_conf
|
||||||
|
self._user_conf = user_conf
|
||||||
|
self._org_conf = org_conf
|
||||||
|
self._username = username
|
||||||
|
self._orgname = orgname
|
||||||
|
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
mapzen_server_conf = self._server_conf.get('mapzen_conf')
|
||||||
|
geocoding_quota = mapzen_server_conf['geocoder']['monthly_quota']
|
||||||
|
mapzen_api_key = mapzen_server_conf['geocoder']['api_key']
|
||||||
|
|
||||||
|
soft_geocoding_limit = self._user_conf.get('soft_geocoding_limit')
|
||||||
|
|
||||||
|
cost_per_hit=0
|
||||||
|
|
||||||
|
period_end_date_str = self._org_conf.get('period_end_date') or self._user_conf.get('period_end_date')
|
||||||
|
period_end_date = date_parse(period_end_date_str)
|
||||||
|
|
||||||
|
logger_conf = self._server_conf.get('logger_conf')
|
||||||
|
log_path = logger_conf['geocoder_log_path']
|
||||||
|
|
||||||
|
return MapzenGeocoderConfig(geocoding_quota,
|
||||||
|
soft_geocoding_limit,
|
||||||
|
period_end_date,
|
||||||
|
cost_per_hit,
|
||||||
|
log_path,
|
||||||
|
mapzen_api_key,
|
||||||
|
self._username,
|
||||||
|
self._orgname)
|
Loading…
Reference in New Issue
Block a user