def getMaxMinTimeinLocation(self, loc, defectsList): op = operations.Operate() if len(defectsList) == 0: return dict() op = operations.Operate() minTimeVal = op.stringToDatetime(defectsList[0].detectionTime) maxTimeVal = op.stringToDatetime(defectsList[0].resolutionTime) # it is possible that an error happens in one position and has been resolved in another # so we should only consider that event of the error [Res, Det] which happened in the # current position. that is why we use d[detectionTime, resolutionTime] == loc in the following code for d in defectsList: # find the min and max times dt_ts = op.stringToDatetime(d.detectionTime) rt_ts = op.stringToDatetime(d.resolutionTime) if minTimeVal > dt_ts and d.detectionLocationOrder == loc: minTimeVal = dt_ts if minTimeVal > rt_ts and d.resolutionLocationOrder == loc: minTimeVal = rt_ts if maxTimeVal < dt_ts and d.detectionLocationOrder == loc: maxTimeVal = dt_ts if maxTimeVal < rt_ts and d.resolutionLocationOrder == loc: maxTimeVal = rt_ts result = dict() result["max"] = op.Cast(maxTimeVal, str) result["min"] = op.Cast(minTimeVal, str) return result
def readRawData(self): op = operations.Operate() # self.dataFrame() self.source = op.dataFrame(self.rawSource) carsDict = dict() op = operations.Operate() for inxDefect in range(len(self.source)): row = self.source.iloc[inxDefect, ] dfObj = df.DefectProfile(row) dfObj.populate() carID = dfObj.carID carObj = carsDict.get(carID, Car(row).populate()) # check if the defect is represented in 2 rows siblingDf = self.findSibling(carObj, dfObj) if siblingDf == False: # only record the partial defect self.updateCarDefects(carObj, dfObj) else: # Extend it # update close/open device of the sibiling defect self.mergeSiblings(siblingDf, dfObj) # set extra device related info for this defect siblingDf.extend() innerDefects = siblingDf.innerDefects() if len(innerDefects) != 0: carObj.defects.extend(innerDefects) if carID not in carsDict: carObj.ID = carID carsDict[carID] = carObj return carsDict
def populate(self): op = operations.Operate() self.source = op.dataFrame(self.rawSource) # self.dataFrame() out = dict() op = operations.Operate() for inx in range(len(self.source)): defectID = op.Cast(self.source['defectid'].iloc[inx,], str) if defectID not in out: out[defectID] = op.Cast(self.source['Unique_ID'].iloc[inx,], str) return out
def populate(self): op = operations.Operate() self.uniqueID = op.Cast(self.rawSource['Unique_ID_Combination'], str) self.groupID = op.Cast(self.rawSource['Objektgruppe_ID'], str) self.locationID = op.Cast(self.rawSource['Fehlerobjekt - location_ID'], str) self.typeID = op.Cast(self.rawSource['Fehlerart - type_ID'], str) self.verursacher = op.Cast(self.rawSource['Verursacher'], str) return
def populate(self): op = operations.Operate() self.carID = op.Cast(self.rawSource['KANR'], str) self.ID = op.Cast(self.rawSource['DEFECT_ID'], str) self.detectionTime = self.rawSource['DEFECT_TS'] self.resolutionTime = self.rawSource['REGISTER_TS'] self.detectionDeviceName = self.rawSource['OPEN_DEVICE'] self.resolutionDeviceName = self.rawSource['CLOSE_DEVICE'] self.groupID = self.rawSource['GROUP_ID'] self.locationID = self.rawSource['LOC_ID'] self.typeID = self.rawSource['TYPE_ID'] self.verursacher = self.rawSource['OWNER_TEXT'] return
def findParents(self, cDefect, defectsList): op = operations.Operate() # there is no paretnhood relationship btw defects after ZP6b cDefect_rl = op.Cast(cDefect.resolutionLine, str) if cDefect_rl in ["zp7", "outofline"]: return cDefect_dl = op.Cast(cDefect.detectionLine, str) cDefect_ol = op.Cast(cDefect.occurranceLine, str) cDefect_ot = op.Cast(cDefect.occurranceTakt, int) cDefect_dt = op.Cast(cDefect.detectionTakt, int) parentsList = [] for pDefect in defectsList: if op.Cast(pDefect.status, int) == defectStatus.multiLine.value: continue if cDefect.ID == pDefect.ID: continue pDefect_rl = op.Cast(pDefect.resolutionLine, str) if pDefect_rl == cDefect_rl and pDefect_rl is not None: # cDefect and pDefect are resolved in the same line pDefect_ol = op.Cast(pDefect.occurranceLine, str) pDefect_dl = op.Cast(pDefect.detectionLine, str) pDefect_rt = op.Cast(pDefect.resolutionTakt, int) #print "pDefect: %s has pDefect_rl: %s and pDefect_ol: %s and pDefect_dl: %s" % (pDefect["ID, pDefect_rl, pDefect_ol, pDefect_dl) if cDefect_ol == pDefect_ol and pDefect_ol is not None: # cDefect and pDefect are occurred in the same line # So, cDefect and pDefect are took place in the same line pDefect_ot = op.Cast(pDefect.occurranceTakt, int) #print "pDefect: %s, ot=%s, rt:%s, cDefect_ot:%s)" % (pDefect.ID, pDefect_ot, pDefect_rt, cDefect_ot) if cDefect_ot is not None and pDefect_ot is not None and pDefect_rt is not None: if pDefect.resolutionIsReal == True: if cDefect_ot >= pDefect_ot and cDefect_ot < pDefect_rt: parentsList.append(pDefect.ID) else: if cDefect_ot >= pDefect_ot: parentsList.append(pDefect.ID) elif cDefect_dl == pDefect_dl and pDefect_dl is not None: # cDefect and pDefect are detected in the same line # So, cDefect and pDefect are took place in the same line pDefect_dt = op.Cast(pDefect.detectionTakt, int) #print "pDefect: %s, dt=%s, rt:%s, cDefect_dt:%s)" % (pDefect.ID, pDefect_dt, pDefect_rt, cDefect_dt) if cDefect_dt is not None and pDefect_dt is not None and pDefect_rt is not None: if pDefect.resolutionIsReal == True: if cDefect_dt >= pDefect_dt and cDefect_dt < pDefect_rt: parentsList.append(pDefect.ID) else: if cDefect_dt >= pDefect_dt: # pDetect is a parent of cDefect parentsList.append(pDefect.ID) #print "-----------------------" return parentsList
def getDefectsInaLocation(self, loc, processedLoc): if loc is None or loc in processedLoc: return [] stat = dfct.defectStatus op = operations.Operate() dList = [] processedLoc.append(loc) # Find all defects detected or resolved in this position and store them for d in self.defects: # Read all errors detected or resolved in this position and store them if op.Cast(d.status, int) == stat.multiLine.value: continue if (d.detectionLocationOrder == loc) or (d.resolutionLocationOrder == loc): dList.append(d) return dList
def defectsTaktResolution(self): op = operations.Operate() processedLoc = [] stat = dfct.defectStatus for d in self.defects: if op.Cast(d.status, int) == stat.multiLine.value: continue dList = [] loc = d.detectionLocationOrder dList = self.getDefectsInaLocation(loc, processedLoc) self.mapTimeToTakt(loc, dList) loc = d.resolutionLocationOrder dList = self.getDefectsInaLocation(loc, processedLoc) self.mapTimeToTakt(loc, dList) return
def fetchSDGL(self, key): out = dict() op = operations.Operate() rawData = op.dataFrame(sdgl.globalRawSDGLs) for inx in range(len(rawData)): rawSDGL = rawData.iloc[inx, ] Obj = sdgl.StationDeviceGroupLocation(rawSDGL) if key.lower() == "g": Obj.getGroup() elif key.lower() == "l": Obj.getLocation() elif key.lower() == "s": Obj.getStation() elif key.lower() == "d": Obj.getDevice() if Obj.ID not in out: out[Obj.ID] = Obj return out
def populate(self): op = operations.Operate() self.ID = op.Cast(self.rawSource['KANR'], str) self.model = self.rawSource['MODELL'] self.motorType = self.rawSource['MOTORKB'] self.gearType = self.rawSource['GETRIEBEKB'] self.FGSTTM = self.rawSource['FGSTTM'] self.FGSTPZ = self.rawSource['FGSTPZ'] self.FGSTMJ = self.rawSource['FGSTMJ'] self.FGSTWK = self.rawSource['FGSTWK'] self.FGSTLFD = self.rawSource['FGSTLFD'] self.F500_TS = self.rawSource['F500'] self.F510_TS = self.rawSource['F510'] self.F590_TS = self.rawSource['F590'] self.F600_TS = self.rawSource['F600'] self.G200_TS = self.rawSource['G200'] self.G300_TS = self.rawSource['G300'] self.ELFIS = self.rawSource['ELFIS'] return
def findSibling(self, carObj, dfObj): # in case that the defect has been detected and resolved once, # then its resolution and detection time will be the same and # it contains resolution device. Then there will be only 1 corresponding row op = operations.Operate() df_dt = op.stringToDatetime(dfObj.detectionTime) df_rt = op.stringToDatetime(dfObj.resolutionTime) # this defect has no sibling in the current list of car's defects # add it to the current list if df_dt == df_rt and (dfObj.resolutionDeviceName != None or len(dfObj.resolutionDeviceName) > 0): self.updateCarDefects(carObj, dfObj) # otherwise, the defect is represeted in 2 rows currentDefectID = dfObj.ID # we check if this defect is already recorded for this car # if yes, its means: # 1. The defect is represented in 2 rows and has a sibiling # 2. The defect is represented in 1 row and will be fetched itself for d in carObj.defects: if currentDefectID == op.Cast(d.ID, str): return d return False
def populate(self, key): op = operations.Operate() self.firstTakt = op.Cast(self.rawSource['FirstTakt'], str) self.lastTakt = op.Cast(self.rawSource['LastTakt'], str) self.locationOrder = op.Cast(self.rawSource['LocationOrder'], str) self.length = op.Cast(self.rawSource['Length'], str) self.line = op.Cast(self.rawSource['Line'], str) #self.stationID = op.Cast(self.rawSource['StationID'], str) self.stationName = op.Cast(self.rawSource['StationName'], str) #self.groupID = op.Cast(self.rawSource['GroupID'], str) self.groupName = op.Cast(self.rawSource['GroupName'], str) #self.deviceID = op.Cast(self.rawSource['DeviceID'], str) self.deviceName = op.Cast(self.rawSource['DeviceName'], str) if key == "device": self.ID = op.Cast(self.rawSource['DeviceName'], str) elif key == "group": self.ID = op.Cast(self.rawSource['GroupName'], str) elif key == "station": self.ID = op.Cast(self.rawSource['StationName'], str) elif key == "location": self.ID = op.Cast(self.rawSource['LocationOrder'], str) return
def generate(self, defectsList): #defectsList = car.get("defects", []) if len(defectsList) == 0: return # Parenthood matrix represents relationship btw all errors # X axis represents children and Y axis represents Parents # SP = Start Point # F1 | F2 | SP # F1| | | # F2| | | # order of defects in columns and rows should be the same # to do it, we creat a primary order of defects and keep this order in rows and columns op = operations.Operate() stat = defectStatus self.generateColumns(defectsList) self.rows = self.emptyRow(len(self.columns) - 1) # #rows[] length = #cols without SP for cDefect in defectsList: if op.Cast(cDefect.status, int) == stat.multiLine.value: continue # to check parenthood, we only compare the real occurrance or detection event of a defect # with other defects # it means if a defect has a set of inner defects, we only inspect the inner defect of that # which represents the real occurrance or detection of the defect if op.Cast( cDefect.status, int ) == stat.inner.value and cDefect.occurranceIsReal == False and cDefect.detectionIsReal == False: continue cDefectInx = self.getColumnInx(cDefect) row = self.fillRow(cDefect, defectsList) # rows contain a list of all rows. As said, order of defects in rows and columns are the same # so we insert a defect's row in the it's corresponding vertical location. # cDefectInx shows the vertical(row) and horizontal(column) location of a defect self.rows[cDefectInx] = row return
def normalize(self, minVal, maxVal, positionStart, positionEnd, value): # print "Min: %s, Max: %s, Start: %s, End: %s, val: %s" % (minVal, maxVal, positionStart, positionEnd, value) op = operations.Operate() if minVal is None or maxVal is None or value is None: return None if op.Cast(positionStart, int, None) is None: return None if op.Cast(positionEnd, int, None) is None: return None pf = __import__('profile') maxVal = op.datetimeDiffinSec(maxVal, pf.minPossibleTime) minVal = op.datetimeDiffinSec(minVal, pf.minPossibleTime) value = op.datetimeDiffinSec(value, pf.minPossibleTime) if maxVal == minVal: maxVal = maxVal + 1 if positionEnd == positionStart: positionEnd = int(positionEnd) + 1 newVal = float(value - minVal) / float(maxVal - minVal) * ( int(positionEnd) - int(positionStart)) + int(positionStart) if int(newVal) == positionEnd: newVal = newVal - 1 return int(newVal)
def setDeviceRelatedData(self): op = operations.Operate() DvDict = self.fetchSDGL("d") DvObj = None # Detection device---------------- # fetch required data from corresponding device profile if self.detectionDeviceName in DvDict: # it is detected before the end of line DvObj = DvDict.get(self.detectionDeviceName, sdgl.StationDeviceGroupLocation()) else: # it is not detected by the end of line DvObj = DvDict.get(sdgl.oufOfLineStationDeviceGroupID, sdgl.StationDeviceGroupLocation()) self.detectionLine = DvObj.line self.detectionDeviceName = DvObj.deviceName self.detectionStationName = DvObj.stationName self.detectionLocationOrder = DvObj.locationOrder # Resolution device---------------- # check if the error is open after ZP6b if self.resolutionDeviceName in DvDict: # it is resolved by the end of line # fetch required data from corresponding device profile DvObj = DvDict.get(self.resolutionDeviceName, sdgl.StationDeviceGroupLocation()) else: DvObj = DvDict.get(sdgl.oufOfLineStationDeviceGroupID, sdgl.StationDeviceGroupLocation()) self.resolutionLine = DvObj.line self.resolutionDeviceName = DvObj.deviceName self.resolutionStationName = DvObj.stationName self.resolutionLocationOrder = DvObj.locationOrder # error is resolved before it has been detected if op.Cast(self.resolutionLocationOrder, int) < op.Cast(self.detectionLocationOrder, int): self.abnormal = True if op.Cast(self.resolutionLocationOrder, int) >= 900: # loc 900 is beginning of ZP7 self.openAfterZP6b = True if op.Cast(self.resolutionLocationOrder, int) < 1000: # loc 1000 is after ZP7 self.resolvedInZP7 = True return