Skip to content

Commit

Permalink
Merge pull request #18 from synthicity/serving-reports
Browse files Browse the repository at this point in the history
Serving reports
  • Loading branch information
fscottfoti committed Apr 8, 2014
2 parents 37af154 + 59e12b9 commit 29c9fc8
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions urbansim/server/urbansimd.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,12 @@ def resp():

@route('/report_data/<item>', method="GET")
def return_data(item):
recs = None
config = None
template = None

def isChart(i):
return True
return "chart" in i

if isChart(item):
config = open(os.path.join(misc.charts_dir(), item)).read()
Expand All @@ -266,33 +270,43 @@ def chart_type(c):
if chart_type(item) == "bar-chart":
recs = get_chart_data(config)
template = """
<h2>%s</h2>
<h2 style="text-align: center;">%s</h2>
<nvd3-multi-bar-chart
data="report_data['%s'].data"
id="%s"
height="300"
margin="{top: 10, right: 10, bottom: 10 , left: 80}"
height="500"
margin="{top: 10, right: 10, bottom: 50 , left: 80}"
interactive="true"
tooltips="true"
showxaxis="true"
xaxislabel="%s"
yaxislabel="%s in thousands"
showyaxis="true"
xaxisrotatelabels="0"
width="600"
nodata="an error occurred in the chart"
>
<svg></svg>
</nvd3-multi-bar-chart>
""" % (config['desc'], item, item[:-5],
config['groupby'], config['metric'])
# ids wouldnt work without [:-5]
s = simplejson.dumps(
{'template': template, 'data': [{'key': '', 'values': recs}]},
use_decimal=True
)
print "response: %s\n" % s
return jsonp(request, s)
# ids wouldn't not work without the [:-5]
else: # map
config = open(os.path.join(misc.maps_dir(), item)).read()
config = json.loads(config)
recs = get_chart_data(config)
template = """
<h2 style="text-align: center;">%s</h2>
<div id="%s" mapdirective style="height: 500px; width: 100%%;">
</div>
""" % (config['desc'], item)

s = simplejson.dumps(
{'template': template, 'data': [{'key': '', 'values': recs}],
'config': config},
use_decimal=True
)
print "response: %s\n" % s
return jsonp(request, s)


@route('/datasets')
Expand Down

0 comments on commit 29c9fc8

Please sign in to comment.