Newer
Older
from itertools import takewhile
import numpy as np
import pandas as pd
def invalidate_records(frame, check_name):
for index,percent in frame.ix[frame[check_name] > 0, check_name].iteritems():
invalidate_record(frame, index, check_name, percent)
return frame
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
def invalidate_record(frame, index, check_name, value):
frame.ix[frame.index[index], check_name] = value
corrupt_view = frame.iloc[index].sceneMirrorPosition
if corrupt_view in [ord('H'),ord('A')]:
# Corrupt calibration view, must also invalidate neighboring scenes
_idx = index + 1
while _idx < len(frame):
if frame.sceneMirrorPosition.iloc[_idx] == corrupt_view:
# Made one cycle
break
elif frame.sceneMirrorPosition.iloc[_idx] in [ord('H'), ord('A')]:
# Skip opposite calibration views
_idx += 1
continue
else:
# Invalidate non-calibration views
frame.ix[frame.index[_idx], check_name] = value
_idx += 1
_idx = index - 1
while _idx >= 0:
if frame.sceneMirrorPosition.iloc[_idx] == corrupt_view:
# Made one cycle
break
elif frame.sceneMirrorPosition.iloc[_idx] in [ord('H'), ord('A')]:
# Skip opposite calibration views
_idx -= 1
continue
else:
# Invalidate non-calibration views
frame.ix[frame.index[_idx], check_name] = value
_idx -= 1
return frame
class BaseCheckList:
def __init__(self, *args, **kwargs):
self.check_results = {}
self.parameters = {}
def set_params(self, parameters):
self.parameters = parameters
def update_qc_percent(self, frame):
for check_func in self.checks:
name = check_func.__name__
if name in frame.columns:
results = frame[name].fillna(0)
# Compute P(A U B)
previous_percent = frame['qc_percent']
frame['qc_percent'] = previous_percent + results - previous_percent*results
return frame
def compute(self, frame):
# Filter bad records from previous level
filtered_frame = frame.ix[frame.qc_percent < 1].copy()
filtered_frame = check(filtered_frame, self.parameters)
return self.update_qc_percent(frame.combine_first(filtered_frame))