forked from movsim/traffic-simulation-de
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME_exportDataFromJs
More file actions
50 lines (38 loc) · 1.73 KB
/
README_exportDataFromJs
File metadata and controls
50 lines (38 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(2019-06-12)
Re: [movsim/traffic-simulation-de] Library / Wrapper for offline use? (#4)
Ran K
12.6.2019 21:13
An movsim/traffic-simulation-de Kopie MTGermany, Comment
SchnellantwortAllen antwortenWeiterleitenLöschenZur Whitelist hinzufügenZur Blacklist hinzufügen
Sure!
what I did was basically modifying road.prototype.writeVehicles in road.js so that instead of writing the data to console.log it just sent it to a local endpoint like this: (log is a string which holds a CSV line for each vehicle status)
var url = 'http://localhost:8000';
var xhr = new XMLHttpRequest();
xhr.open('POST', url, false);
xhr.send(log);
Separately, I wrote this basic HTTP server in python which I run locally:
from http.server import HTTPServer, BaseHTTPRequestHandler
from io import BytesIO
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def log_message(self, format, *args):
return
def do_POST(self):
content_length = int(self.headers['Content-Length'])
body = self.rfile.read(content_length).decode("utf-8")
reader = csv.reader(body.split('\n'), delimiter=',')
for row in reader:
print(','.join(row))
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.send_header("Access-Control-Allow-Origin", "*")
self.end_headers()
response = BytesIO()
response.write(b'This is POST request. ')
response.write(b'Received: ')
self.wfile.write(response.getvalue())
httpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)
httpd.serve_forever()
I hope this makes sense... I just used it to export the data so that I can run some computation in python
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.