-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrect_data.py
More file actions
87 lines (62 loc) · 2.49 KB
/
correct_data.py
File metadata and controls
87 lines (62 loc) · 2.49 KB
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
86
87
from configurations import data_dir, corrected_data_dir, validation_results_dir, col_names
import os
import pandas as pd
import inspect
from test_rle import readAndCreateRle
import pdb
ee = execfile
poing = inspect.getabsfile(inspect.currentframe())
class CorrectCollisions(object):
def __init__(self, data_file, validated_results, rle):
self.data_file = data_file
self.validated_results = validated_results
self.rle = rle
self.correctedData = None
self.yes_valuesL = self.validated_results[self.validated_results.icol(1) == "y"].values[:,0]
def getCorrectedData(self):
if self.correctedData == None:
self.correctedData = 5 # fix this.
return self.correctedData
def get_switched_frames(self):
valuesL = []
for i in range(0, len(self.yes_valuesL), 2):
startingBound = self.yes_valuesL[i]
upperBound = self.yes_valuesL[i+1]
print startingBound
print upperBound
valuesL += range(startingBound, upperBound)
return valuesL
def __repr__(self):
return "No. of rows: %s" % len(self.data_file)
def flipFrameIdentities(dataFrame):
dataFrameCopy = dataFrame.copy()
dataFrameCopy.iloc[0, 2:] = dataFrame.iloc[1, 2:]
dataFrameCopy.iloc[1, 2:] = dataFrame.iloc[0, 2:]
return dataFrameCopy
if __name__ == "__main__":
dataFileS = "data_shortcoll.csv"
dataFilePathS = os.path.join(data_dir, dataFileS)
rleFileS = "csv.csv"
rleFilePathS = os.path.join(data_dir, rleFileS)
validatedFileS = "identity.csv"
validatedFilePathS = os.path.join(validation_results_dir, validatedFileS)
# reading the files
rle = readAndCreateRle(rleFilePathS)
raw_data = pd.read_csv(dataFilePathS, header=None)
results = pd.read_csv(validatedFilePathS, header=None)
getYes = results[results.icol(1) == "y"]
raw_data_copy = raw_data.copy()
yesValuesL = getYes.values[:, 0]
for i in range(0, len(yesValuesL), 2):
startingBound = yesValuesL[i]
upperBound = yesValuesL[i+1]
print startingBound
print upperBound
for j in range(startingBound, upperBound):
matchingRow = raw_data_copy [raw_data_copy.icol(0) == j]
indexes = matchingRow.index
flipped = flipFrameIdentities(matchingRow)
raw_data_copy.iloc[indexes[0]:indexes[1]+1] = flipped
print indexes
# trying class
a = CorrectCollisions(raw_data, results, rle)