-
Notifications
You must be signed in to change notification settings - Fork 1
/
tubenghen-dataModify.py
70 lines (60 loc) · 1.63 KB
/
tubenghen-dataModify.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
"""
__author__ : kumar shubham
__desc__ : code for data formating of tubenghen dataset
"""
import os
import json
from sklearn import preprocessing
def scaleFn(inputData):
scaledOutput = preprocessing.scale(inputData)
return scaledOutput
def main():
Dir ="./tubenghen-anti-casual"
fileName = os.path.join(Dir,"README")
jsonFileSave = "tubehengenDataFormat.json"
with open(fileName,"r") as fileNameReader, open(jsonFileSave,"w") as tubenghenJsonWriter:
casualCount =0
antiCasualCount = 0
count = 0
errorFlag = False
for line in fileNameReader:
data = line.split()
if "->" in data:
label = 0
typeOfdata = "casual"
elif "<-" in data:
label = 1
typeOfdata = "anti-casual"
else:
label = None
pass
if label is not None:
fileName = data[0]
count+=1
print ("count processed : %d"%(count))
with open(os.path.join(Dir,fileName)+".txt","r") as tubFileReader:
xVal = []
yVal = []
for line in tubFileReader:
try:
x,y = line.split()
xVal.append(float(x))
yVal.append(float(y))
except Exception as e:
if not errorFlag:
print("error in : ",fileName)
print(e)
errorFlag = True
if errorFlag:
count-=1
errorFlag=False
continue
newXVal = scaleFn(xVal)
newYVal = scaleFn(yVal)
data = {"trainX": newXVal.ravel().tolist(), "trainY":newYVal.ravel().tolist(),"label":label,"type":typeOfdata}
json.dump(data,tubenghenJsonWriter)
tubenghenJsonWriter.write("\n")
else:
pass
if __name__=="__main__":
main()