-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·73 lines (62 loc) · 2 KB
/
test.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
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
import json
import numpy as np
import time as t
from random import random,gauss,seed
from random import randint
from ContData import *
from TrackData import TrackData
from mysql import DBLink
seed(1337)
debug=False
list_ID = [101,102,103,104,105,106,107,108]
conf = {
'ip': '138.246.40.44',
'user': 'hack',
'pw': 'Y7ABu',
'db': 'codefest',
}
query = "SELECT speed, speed_GPS, brlt, belt, stwa, ftgs, Node_Time from hackathon WHERE Track_VehicleID='{id}' ORDER BY NODE_TIME"# LIMIT {limit};"
db = DBLink(conf)
meta = {}
for i in list_ID:
db.query(query.format(id=i, limit=10))
meta[i] = []
speed_lim_cycle = 10;
curr_speed_lim_cycle = 1;
prev_speed_lim = randint(20, 160);
last_time=None
tracks = []
tracks.append(TrackData())
for x in db.fetch():
if curr_speed_lim_cycle == speed_lim_cycle:
prev_speed_lim = randint(40, 140);
curr_speed_lim_cycle = 1;
speed_lim_cycle = randint(2, 10);
else:
curr_speed_lim_cycle += 1
x['speed_lim'] = prev_speed_lim;
x['time'] = t.mktime(t.strptime(x["Node_Time"],"%Y-%m-%d %H:%M:%S"))
if randint(1,100) == 23:
x['ftgs'] = True
else:
x['ftgs'] = False
#print time
if not last_time:
last_time=x['time']
if np.abs(x['time']-last_time) > 1800 and len(tracks[-1].data)>1:
tracks[-1].end_track()
result = tracks[-1].export()
if result:# and result['force']['max']<200000 and result['duration']>10000:
meta[i].append(result)
tracks.append(TrackData())
try:
tracks[-1].add_data_point(ContData(x))
except InvalidDataException as e:
if debug:
print 'InvalidDataException: ', e.value, " Number: ", e.count
last_time=x['time']
if len(tracks) >1 and False:
break
with open("out.json","w") as f:
json.dump(meta, f)