diff --git a/buildings_indicator.py b/buildings_indicator.py index aafb81e..46f7419 100644 --- a/buildings_indicator.py +++ b/buildings_indicator.py @@ -140,15 +140,15 @@ def year_con_to_age(year_con, base_year): class BuildingsIndicator(Indicator): - def setup(self,*args,**kwargs): + def setup(self,host='https://cityio.media.mit.edu/', *args,**kwargs): self.category='numeric' self.table_name=kwargs['table_name'] self.fitted_model_object_loc='./tables/buildings_data/fitted_comm_model.p' self.train_data_loc='./tables/buildings_data' - GEOGRID_props_loc='https://cityio.media.mit.edu/api/table/{}/GEOGRID/properties'.format(self.table_name) - with urllib.request.urlopen(GEOGRID_props_loc) as url: - geogrid_props=json.loads(url.read().decode()) - self.cell_size=geogrid_props['header']['cellSize'] + GEOGRID_loc='{}api/table/{}/GEOGRID'.format(host, self.table_name) + with urllib.request.urlopen(GEOGRID_loc) as url: + geogrid=json.loads(url.read().decode()) + self.cell_size=geogrid['properties']['header']['cellSize'] self.max_result_per_worker=100000 self.min_result_per_worker=50000 diff --git a/listen.py b/listen.py index 7fe111e..905e5a3 100644 --- a/listen.py +++ b/listen.py @@ -7,15 +7,17 @@ from buildings_indicator import BuildingsIndicator from diversity_indicator import DiversityIndicator +import sys + from statistics import mean -def main(): +def main(host='https://cityio.media.mit.edu/'): # Individual Indicators I = InnoIndicator() - P = ProxIndicator(name='proximity', indicator_type_in='numeric', table_name='corktown') - P_hm = ProxIndicator(name='proximity_heatmap', indicator_type_in='heatmap', table_name='corktown') + P = ProxIndicator(name='proximity', host=host, indicator_type_in='numeric', table_name='corktown') + P_hm = ProxIndicator(name='proximity_heatmap', host=host, indicator_type_in='heatmap', table_name='corktown') M = MobilityIndicator(name='mobility', table_name='corktown') - B= BuildingsIndicator(name='buildings', table_name='corktown') + B= BuildingsIndicator(name='buildings', host=host,table_name='corktown') D= DiversityIndicator(name='diversity', table_name='corktown') # 2nd order individual indicators @@ -29,7 +31,7 @@ def main(): D]: indicator.viz_type='bar' - H = Handler('corktown', quietly=False) + H = Handler('corktown', quietly=False, host=host) H.add_indicators([ I, @@ -84,4 +86,8 @@ def main(): H.listen() if __name__ == '__main__': - main() \ No newline at end of file + if len(sys.argv)>1: + host=sys.argv[1] + main(host=host) + else: + main() \ No newline at end of file diff --git a/proximity_indicator.py b/proximity_indicator.py index d00dc06..d59a414 100644 --- a/proximity_indicator.py +++ b/proximity_indicator.py @@ -31,7 +31,7 @@ def approx_shape_centroid(geometry): print('Unknown geometry type') class ProxIndicator(Indicator): - def setup(self,*args,**kwargs): + def setup(self,host='https://cityio.media.mit.edu/', *args,**kwargs): # self.viz_type = kwargs['viz_type_in'] self.indicator_type = kwargs['indicator_type_in'] self.table_name= kwargs['table_name'] @@ -49,7 +49,7 @@ def setup(self,*args,**kwargs): assert(all(poi in self.scalers for poi in self.all_poi_types)) self.radius=15 # minutes self.dummy_link_speed_met_min=2*1000/60 - self.host='https://cityio.media.mit.edu/' + self.host=host # self.pois_per_lu={ # 'Residential': {'housing': 200}, # 'Office Tower': {'employment': 1200}, diff --git a/toolbox.py b/toolbox.py index 2709908..61b5871 100644 --- a/toolbox.py +++ b/toolbox.py @@ -41,9 +41,9 @@ class Handler: quietly : boolean (default=True) If True, it will show the status of every API call. ''' - def __init__(self, table_name, GEOGRIDDATA_varname = 'GEOGRIDDATA', GEOGRID_varname = 'GEOGRID', quietly=True): + def __init__(self, table_name, GEOGRIDDATA_varname = 'GEOGRIDDATA', GEOGRID_varname = 'GEOGRID', quietly=True, host = 'https://cityio.media.mit.edu/'): - self.host = 'https://cityio.media.mit.edu/' + self.host = host self.table_name = table_name self.quietly = quietly @@ -416,9 +416,9 @@ def get_geogrid_props(self): These properties are not dynamic and include things such as the NAICS and LBCS composition of each lego type. ''' if self.geogrid_props is None: - r = self._get_url(self.cityIO_get_url+'/GEOGRID/properties') + r = self._get_url(self.cityIO_get_url+'/GEOGRID') if r.status_code==200: - self.geogrid_props = r.json() + self.geogrid_props = r.json()['properties'] else: warn('Cant access cityIO type definitions') sleep(1)