-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tracker.py
60 lines (51 loc) · 1.27 KB
/
test_tracker.py
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
51
52
53
54
55
56
57
58
59
60
import json
import urllib.request
from bs4 import BeautifulSoup
import time
import sqlite3
import cet_bus
from bus_history import BusHistory
from cet_bus.haversine import haversine
from cet_bus.geo import Point
from tracker import TransitSystemTracker
import math
# Simulate buses moving in separate circles, each sampled at 20 points
fake_bus_data = []
for t in range(60):
if t < 30:
x = 0.0003 * t / 30
else:
x = 0.0003 - (0.0003 * (t - 30) / 30)
bus_1 = { 'latitude': 40 + x, 'longitude': 40.0, 'Route': '1', 'bus': '1' }
fake_bus_data.append([ bus_1 ])
route_1_stops = [40, 40.0001, 40.0002, 40.0003, 40.0002, 40.0001]
stops_info = { '1': [] }
for t, x in enumerate(route_1_stops):
stop_1 = {
'stop_lat': x,
'stop_lon': 40.0,
'direction_id': 0 if t < 3 else 1,
'stop_id': t
}
stops_info['1'].append(stop_1)
print(fake_bus_data)
print(stops_info)
i = 0
def get_fake_bus_data():
global i
res = fake_bus_data[i]
i += 1
i %= 20
return res
class Route:
def __init__(self, **kwargs):
self.start = kwargs['start']
self.end = kwargs['end']
routes =\
{ '1': Route(start=0, end=3),
'2': Route(start=0, end=-1)
}
transit = TransitSystemTracker(get_fake_bus_data, stops_info, routes)
while True:
transit.update()
time.sleep(1)