def rate_route(request):
"""
Adds the rating to all edges in a route, and saves it both in the structure and in the database.
Query args:
rid -- the id for the rated route
rating -- a float between 0 and 5
"""
try:
tag = request.POST.get('visited_path')
new_rating = float(request.POST.get('rating'))
path = from_string(GRAPH, tag)
edgecoords = [(s, e) for s, e in zip(path, path[1:])]
def update_rating(edge):
for edge in GRAPH.get_edges():
for s, e in edgecoords:
if s == edge.id and e == edge.to:
edge._rating = (edge._rating + new_rating) / 2
update_edge_in_db(edge)
return edge
GRAPH.map_graph(lambda _: _, update_rating)
return HttpResponse('')
except:
return HttpResponseNotFound("Something went wrong while rating your route.")
评论列表
文章目录