def ping_today(request,station_id): pings = ET.Element("pings") for ping in Ping.today(station_id): pings.append(ET.Element('ping', hour=str(ping["time"]), bikes=str(ping['bikes']), free=str(ping['free']) )) return __XmlResponse(pings)
def ping_today(request,station_id): "csv view for today" response = HttpResponse(mimetype='text/csv') writer = csv.writer(response) writer.writerow(['bikes','free']) for ping in Ping.today(station_id): writer.writerow([ping['bikes'],ping['free']]) return response
def ping_today(request,station_id): "json view for today" max = ping_max(station_id) bikes = [] free = [] broken = [] for ping in Ping.today(station_id): bikes.append({ "y": float(ping['bikes']), "x": float(ping['time']) }) free.append({ "y": float(ping['free']), "x": float(ping['time']) }) broken.append({ "y": max['max']-float(ping['bikes'])-float(ping['free']), "x": float(ping['time']) }) elements = [ { "colour": "#ff0000", "type": "scatter_line", "values": bikes, "text": "bikes", "dot-size": 1, }, { "type": "scatter_line", "colour": "#00ff00", "values": free, "text": "free places", "dot-size": 1, }, { "type": "scatter_line", "colour": "#000000", "values": broken, "text": "maybe broken", "dot-size": 1, }, ] graph = { "title": { "text": "Average By Half Hour" }, "elements": elements, "y_axis": { "min": 0, "max": max['max'], "steps": 3 }, "x_axis": { "min": 0, "max": 24 } } return HttpResponse(json.dumps(graph))