forked from eclipse/kuksa.val
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_replay.py
85 lines (66 loc) · 2.1 KB
/
_replay.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
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys, os
import time, datetime
import traceback
import configparser
import csv
import string
scriptDir= os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(scriptDir, "..", ".."))
from kuksa_viss_client import *
def workaround_dict(a,b):
pass
rowIDs = [
"timestamp",
"ID",
"action",
"path",
"value"
]
try:
config = configparser.ConfigParser()
config.read('config.ini')
except:
print("Unable to read config file")
os._exit(0)
args=config['replay'] #get replay data
vsscfg = config['vss'] #get Client data from config file
csv_path = args.get('path')
try:
commThread = KuksaClientThread(vsscfg) #make new thread
commThread.start()
commThread.authorize(token=commThread.tokenfile)
print("Connected successfully")
except:
print("Could not connect successfully")
sys.exit(-1)
try:
actionFunctions = {
"get": commThread.getValue,
"set": commThread.setValue
}
if args.get('mode') == 'Set':
actionFunctions["get"] = workaround_dict #don't call get functions when getValue is not specified
elif args.get('mode') == 'SetGet':
pass
else:
raise AttributeError
with open(csv_path,"r") as recordFile:
fileData = csv.DictReader(recordFile,rowIDs,delimiter=';')
timestamp_pre = 0
for row in fileData:
timestamp_curr = row["timestamp"]
if timestamp_pre != 0:
curr = datetime.datetime.strptime(timestamp_curr, '%Y-%b-%d %H:%M:%S.%f')
pre = datetime.datetime.strptime(timestamp_pre, '%Y-%b-%d %H:%M:%S.%f')
delta = (curr-pre).total_seconds() #get time delta between the timestamps
else:
delta=0
timestamp_pre = timestamp_curr
time.sleep(delta)
actionFunctions.get(row['action'])(row['path'],row['value'])
print("Replay successful")
except AttributeError:
print("Wrong attributes used. Please check config.ini")
except:
traceback.print_exc()
os._exit(1)