aboutsummaryrefslogtreecommitdiff
path: root/tools/test-generator.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/test-generator.py')
-rwxr-xr-xtools/test-generator.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/tools/test-generator.py b/tools/test-generator.py
index b8a06ac32..ed135b4aa 100755
--- a/tools/test-generator.py
+++ b/tools/test-generator.py
@@ -1,9 +1,9 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
import sys
import math
import urllib
-import httplib
+import http.client as httplib
import time
import random
@@ -35,8 +35,8 @@ for i in range(0, len(waypoints)):
lon = lon1 + (lon2 - lon1) * j / count
points.append((lat, lon))
-def send(conn, lat, lon, course, speed, battery, alarm, ignition, accuracy, rpm, fuel, driverUniqueId):
- params = (('id', id), ('timestamp', int(time.time())), ('lat', lat), ('lon', lon), ('bearing', course), ('speed', speed), ('batt', battery))
+def send(conn, lat, lon, altitude, course, speed, battery, alarm, ignition, accuracy, rpm, fuel, driverUniqueId):
+ params = (('id', id), ('timestamp', int(time.time())), ('lat', lat), ('lon', lon), ('altitude', altitude), ('bearing', course), ('speed', speed), ('batt', battery))
if alarm:
params = params + (('alarm', 'sos'),)
if ignition:
@@ -51,7 +51,7 @@ def send(conn, lat, lon, course, speed, battery, alarm, ignition, accuracy, rpm,
params = params + (('fuel', fuel),)
if driverUniqueId:
params = params + (('driverUniqueId', driverUniqueId),)
- conn.request('GET', '?' + urllib.urlencode(params))
+ conn.request('GET', '?' + urllib.parse.urlencode(params))
conn.getresponse().read()
def course(lat1, lon1, lat2, lon2):
@@ -70,14 +70,15 @@ conn = httplib.HTTPConnection(server)
while True:
(lat1, lon1) = points[index % len(points)]
(lat2, lon2) = points[(index + 1) % len(points)]
+ altitude = 50
speed = device_speed if (index % len(points)) != 0 else 0
alarm = (index % 10) == 0
battery = random.randint(0, 100)
- ignition = (index % len(points)) != 0
+ ignition = (index / 10 % 2) != 0
accuracy = 100 if (index % 10) == 0 else 0
rpm = random.randint(500, 4000)
fuel = random.randint(0, 80)
driverUniqueId = driver_id if (index % len(points)) == 0 else False
- send(conn, lat1, lon1, course(lat1, lon1, lat2, lon2), speed, battery, alarm, ignition, accuracy, rpm, fuel, driverUniqueId)
+ send(conn, lat1, lon1, altitude, course(lat1, lon1, lat2, lon2), speed, battery, alarm, ignition, accuracy, rpm, fuel, driverUniqueId)
time.sleep(period)
index += 1