Skip to content

Commit

Permalink
Host is a parameter which defaults to the city.media.mit.edu address
Browse files Browse the repository at this point in the history
  • Loading branch information
doorleyr committed Jul 7, 2020
1 parent 7d94ea8 commit 6dd66da
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
10 changes: 5 additions & 5 deletions buildings_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 12 additions & 6 deletions listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -84,4 +86,8 @@ def main():
H.listen()

if __name__ == '__main__':
main()
if len(sys.argv)>1:
host=sys.argv[1]
main(host=host)
else:
main()
4 changes: 2 additions & 2 deletions proximity_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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},
Expand Down
8 changes: 4 additions & 4 deletions toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6dd66da

Please sign in to comment.