Skip to content

Commit

Permalink
avoid repeated requests
Browse files Browse the repository at this point in the history
  • Loading branch information
vroland committed Nov 12, 2019
1 parent 35cae05 commit 96af69f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
15 changes: 9 additions & 6 deletions obst/tspopt/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def solution_to_json(data, manager, routing, assignment):
answer["round_time"] = route_time
print("round_time:", route_time)
print(route_output)
return json.dumps(answer, indent=4)
return json.dumps(answer)


def find_route(graph, start, timeout, time_per_stop):
Expand Down Expand Up @@ -249,17 +249,20 @@ def do_GET(self):
self.wfile.write("invalid graph".encode("utf-8"))
return

self.send_response(200)
self.send_header('Content-type', 'application/json')
self.send_header('Access-Control-Allow-Origin', '*')
self.end_headers()
print ("path:", self.path)
timeout = int(timeout)
time_per_stop = int(time_per_stop)
lonlat = list(map(float, lonlat.split(";")))
graph = graphs[graph_name]
print ("using timeout:", timeout)
self.wfile.write(find_route(graph, lonlat, timeout, time_per_stop).encode("utf-8"))
answer = find_route(graph, lonlat, timeout, time_per_stop).encode("utf-8")

self.send_response(200)
self.send_header('Content-type', 'application/json')
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header("Content-Length", str(len(answer)))
self.end_headers()
self.wfile.write(answer)

if __name__ == '__main__':

Expand Down
23 changes: 9 additions & 14 deletions obst/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
#mapid {
float: right;
width: 80%;
height: 1200px;
height: 1080px;
padding: 15px;
border-style: solid;
}
Expand Down Expand Up @@ -492,21 +492,10 @@ <h1 style="margin-bottom:30px;" ><i class="fas fa-apple-alt" style="font-size:
var popup = L.popup();
sm = markerList.push(sm);

function onMapClick(e) {
start_position = [e.latlng.lng, e.latlng.lat];
find_route();
console.log("map click!");
/*
popup
.setLatLng(e.latlng)
.setContent("You clicked the map at " + e.latlng.toString())
.openOn(mymap);
*/
}


var group = new L.featureGroup(markerList);
mymap.fitBounds(group.getBounds());
mymap.on('click', onMapClick);
}


Expand Down Expand Up @@ -539,7 +528,13 @@ <h1 style="margin-bottom:30px;" ><i class="fas fa-apple-alt" style="font-size:
xmlhttp.open("GET", "http://localhost:8000/" + dataset + "/" + start_position[0] + ";" + start_position[1] + "/"+max_route_length + "/" + stop_time, true);
xmlhttp.send();
}


function onMapClick(e) {
start_position = [e.latlng.lng, e.latlng.lat];
find_route();
}

mymap.on('click', onMapClick);
find_route();
</script>

Expand Down

0 comments on commit 96af69f

Please sign in to comment.