You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.3 KiB
66 lines
2.3 KiB
1 year ago
|
import requests
|
||
|
import time
|
||
|
import json
|
||
|
import sys
|
||
|
|
||
|
start = int(sys.argv[1])
|
||
|
destination = int(sys.argv[2])
|
||
|
position = start
|
||
|
road = start
|
||
|
route = (start % 10000) / 1000
|
||
|
|
||
|
res = requests.get("http://cloud_computing_project_api:8080/vehicles/subscribe?start=" + str(start) + "&destination=" + str(destination))
|
||
|
|
||
|
ID = json.loads(res.text)["insertedId"]
|
||
|
|
||
|
while position != destination:
|
||
|
|
||
|
res = requests.get("http://cloud_computing_project_api:8080/vehicles/look?position=" + str(position))
|
||
|
|
||
|
if res.text == "":
|
||
|
|
||
|
if route == 1:
|
||
|
if position > (start + 44):
|
||
|
position += 1
|
||
|
requests.get("http://cloud_computing_project_api:8080/vehicles/update?id=" + str(ID) + "&position=" + str(position))
|
||
|
|
||
|
else:
|
||
|
res = requests.get("http://cloud_computing_project_api:8080/traffic_lights/look?road=" + str(road))
|
||
|
greenLight = json.loads(res.text)["greenLight"]
|
||
|
|
||
|
if greenLight == 1 or position < (start + 44):
|
||
|
position += 1
|
||
|
requests.get("http://cloud_computing_project_api:8080/vehicles/update?id=" + str(ID) + "&position=" + str(position))
|
||
|
|
||
|
|
||
|
elif route == 2:
|
||
|
if position > (start + 44):
|
||
|
if position == (start + 85):
|
||
|
position = destination - 71
|
||
|
else:
|
||
|
position += 1
|
||
|
|
||
|
requests.get("http://cloud_computing_project_api:8080/vehicles/update?id=" + str(ID) + "&position=" + str(position))
|
||
|
|
||
|
else:
|
||
|
res = requests.get("http://cloud_computing_project_api:8080/traffic_lights/look?road=" + str(road))
|
||
|
greenLight = json.loads(res.text)["greenLight"]
|
||
|
|
||
|
if greenLight == 1 or position < (start + 44):
|
||
|
position += 1
|
||
|
requests.get("http://cloud_computing_project_api:8080/vehicles/update?id=" + str(ID) + "&position=" + str(position))
|
||
|
|
||
|
|
||
|
elif(route == 3):
|
||
|
if position == (start + 56):
|
||
|
position = destination - 60
|
||
|
else:
|
||
|
position += 1
|
||
|
|
||
|
requests.get("http://cloud_computing_project_api:8080/vehicles/update?id=" + str(ID) + "&position=" + str(position))
|
||
|
|
||
|
|
||
|
|
||
|
time.sleep(0.2)
|
||
|
|
||
|
requests.get("http://cloud_computing_project_api:8080/vehicles/delete?id=" + str(ID))
|