def aw_calculateKPI(self): self.aw_writeRow(['DeviceSN', 'DBM', 'Cn0Mean'], 'Summary') testData = pd.read_excel(self.caseReportPath, sheet_name='Detail', dtype=str) for index, row in testData.iterrows(): dbm = row['DBM'] startTime = time.mktime( time.strptime(row['StartTime'], '%Y-%m-%d %H:%M:%S')) endTime = time.mktime( time.strptime(row['EndTime'], '%Y-%m-%d %H:%M:%S')) for nmeaLogName in os.listdir(getLbsCaseLogPath()): if 'COM' in nmeaLogName and nmeaLogName.endswith('.txt'): deviceSn = nmeaLogName.split('_')[0] cn0List = [] rmcStamp = None startFlag = False with open(os.path.join(getLbsCaseLogPath(), nmeaLogName), 'rb') as rf: for line in rf: if "RMC" in str(line): rmcList = str(line).split('RMC')[-1].split(',') rmcTime = rmcList[1] rmcDate = rmcList[9] if rmcTime and rmcDate: rmcTimeTuple = time.strptime( rmcDate + rmcTime.split('.')[0], '%d%m%y%H%M%S') rmcStamp = time.mktime(rmcTimeTuple) + 18 elif 'GSV' in str(line): if rmcStamp is None: continue if startTime > rmcStamp: continue elif startTime < rmcStamp < endTime: startFlag = True cn0List.extend( self.__calculateViewSatellite( str(line))) elif rmcStamp > endTime: if startFlag: break if cn0List: dataList = [ deviceSn, dbm, round(sum(cn0List) / len(cn0List), 2) ] else: dataList = [deviceSn, dbm, -1] self.aw_writeRow(dataList, 'Summary') return SUC, 'OK'
def getnovatelMatchTime(self, mType, expect): ''' @summary: 匹配符合期望高度或速度的时间 @param mType: speed或alt @param expect: 速度或高度极限值 @attention: 适用于高速和探空场景 ''' novatel = os.path.join(getLbsCaseLogPath(), 'novatel.txt') if not os.path.exists(novatel): return FAIL, 'novatel.txt不存在' novatelDict = {'speed': 0, 'alt': 0} with open(novatel, 'r') as fileObj: utc = None startTime = None for line in fileObj: if 'RMC' in line: rmcList = line.split(',') if not (rmcList[1] and rmcList[9]): continue utc = rmcList[1] if startTime is None: startTime = (rmcList[9], rmcList[1]) if rmcList[7]: novatelDict['speed'] = float(rmcList[7]) * 0.514444 elif 'GGA' in line: ggaList = line.split(',') utc = ggaList[1] if not utc: continue if ggaList[9]: novatelDict['alt'] = float(ggaList[9]) + float( ggaList[10]) if novatelDict[mType] > expect: dataList = [utc, novatelDict['alt'], novatelDict['speed']] self.aw_writeRow('Novatel', dataList) return SUC, (utc, startTime) return FAIL, '最大值:%s' % str(novatelDict[mType])
def aw_copySceneSpanFromServer(self, sceneData, fileName): filePath = os.path.join(SCENE_PATH, sceneData['memoryLocation'], 'span', fileName, 'span') fileList = os.listdir(filePath) spanPath = None if sceneData['sapnPath'] == '': for file in fileList: if file.endswith('.kmz'): spanPath = os.path.join(filePath, file) isSuc(self.aw_copyFile2dstPath(spanPath, getLbsCaseLogPath())) return SUC, 'ok' else: spanPath = os.path.join(filePath, sceneData['sapnPath'] + '.kmz') isSuc(self.aw_copyFile2dstPath(spanPath, getLbsCaseLogPath())) return SUC, 'ok' return FAIL, 'has no found this span.'
def aw_GSS7000GetStandardNMEA(self, sceneId, rmSrcFlag=True): ''' @summary: 获取6700/7000模拟器生成的标准nmea文件 @param sceneId: 场景编号 @param rmSrcFlag: 获取后是否删除标准nmea文件 @return: (SUC, success info) or (FAIL, fail info) @see: self.lbs.aw_checkCepTtffStandard({'COM1':19},20) @author: shaochanghong @attention: ''' posAppLogPath = getInstruments().get('Gss7000', {}).get('posAppLogPath') gssType = getInstruments().get('Gss7000', {}).get('type') if not os.path.exists(posAppLogPath): return FAIL, 'please check posAppLogPath.' if '7000' in gssType: ip = posAppLogPath.split(os.sep)[2] isSuc(self.sendMsg2Gss7000Server({'sceneId': sceneId}, ip, 9998)) srcPath = os.path.join(posAppLogPath, sceneId, 'nmea.txt') dstPath = os.path.join(getLbsCaseLogPath(), 'novatel.txt') if not os.path.exists(srcPath): return FAIL, 'has no nmea.txt' shutil.copyfile(srcPath, dstPath) if rmSrcFlag: os.remove(os.path.join(posAppLogPath, sceneId, 'nmea.txt')) return SUC, dstPath
def getTestNmeaData(self, device, startTime): snFixDict = OrderedDict() # {'utc':} fileName = device.get('sn') + 'nmea.txt' startFlag = False with open(os.path.join(getLbsCaseLogPath(), fileName), 'rb') as rf: for line in rf: if startFlag is False: if (startTime[0] in line) and (startTime[1] in line): startFlag = True continue if re.search('G.GGA', str(line)): ggaList = str(line).split('GGA,')[1] utc = ggaList[1] if not utc: continue if ggaList[5] == '1': ggaData = { 'Lat': ggaList[2], 'Lon': ggaList[4], 'Alt': float(ggaList[9]) + float(ggaList[10]), 'FixFlag': SUC } else: ggaData = { 'Lat': -1, 'Lon': -1, 'Alt': -1, 'FixFlag': FAIL } if utc not in snFixDict: snFixDict[utc] = ggaData else: snFixDict[utc].update(ggaData) elif re.search('G.RMC', str(line)): rmcList = str(line).split('RMC,')[1] utc = rmcList[1] if not utc: continue speed = float(rmcList[7]) * 0.514444 if rmcList[7] else -1 if utc in snFixDict: snFixDict[utc]['speed'] = speed else: snFixDict[utc] = {'speed': speed} for utc, msgDict in snFixDict.items(): dataList = [ device.get('sn'), utc, msgDict['Lat'], msgDict['Lon'], msgDict['Alt'], speed, msgDict['FixFlag'] ] self.aw_writeRow('MaxSpeedAlt', dataList) self.aw_save()
def aw_nmeanalysis(self, starttime, endtime, sceneId=None, lonRef=None, latRef=None, altRef=None, isSingle=False): ''' @summary: 调用分析工具分析 @param starttime:场景开始 @param endtime:场景结束时间 @param isSingle:是否单点分析 @param sceneId:场景编号 @param latRef: 经度值 @param lonRef: 纬度值 @param altRef: 高度值 ''' config = isSuc( self._getnmeanalysisconfig(starttime, endtime, lonRef, latRef, altRef, isSingle)) path = getLbsCaseLogPath() if not sceneId: sceneId = getCurCaseName() try: configPath = os.path.join(getProjectPath(), 'aw', 'utils', 'nmeanalysis', 'config.py') with open(configPath, 'w') as f: f.write('#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n') f.write('config = ' + str(config)) f.close() nmeaAnalysisPath = os.path.join(getProjectPath(), 'aw', 'utils', 'nmeanalysis', 'AnalysisNMEA.py') cmd = r"python " + nmeaAnalysisPath + ' ' + path + ' ' + sceneId print(cmd) os.system(cmd) except Exception as e: return FAIL, e return SUC, 'OK'
def deviceLogPath(self): deviceLogPath = os.path.join(getLbsCaseLogPath()) if not os.path.exists(deviceLogPath): os.makedirs(deviceLogPath) return deviceLogPath
def caseReportPath(self): return os.path.join(getLbsCaseLogPath(), getCurCaseName() + '.xls')
def _getnmeanalysisconfig(self, starttime, endtime, lonRef=None, latRef=None, altRef=None, isSingle=False): ''' @summary: 分析工具写配置文件 @param starttime:场景开始 @param endtime:场景结束时间 @param latRef: 经度值 @param lonRef: 纬度值 @param altRef: 高度值 ''' path = getLbsCaseLogPath() comDict = isSuc(self._getSerialConfig()) config = { 'timeSlicing': { 'starttime': '2020-01-07 06:26:18', 'endtime': '2020-01-07 09:35:39' }, 'is_need_single_analysis': False, 'is_need_static_kpi': False, 'singleReportPath': '', 'static_kpi_values': { 'ref_longitude': 116, 'ref_alt': 0, 'ref_speed': 0, 'ref_heading': 0, 'ref_latitude': 40 }, 'satelliteInfo': {}, 'deviceInfo': [] } config['timeSlicing']['starttime'] = starttime config['timeSlicing']['endtime'] = endtime config['satelliteInfo'] = comDict if latRef and lonRef and altRef: config['is_need_static_kpi'] = True config['static_kpi_values']['ref_longitude'] = lonRef config['static_kpi_values']['ref_latitude'] = latRef config['static_kpi_values']['ref_alt'] = altRef if os.path.exists(os.path.join(path, getCurCaseName() + '.xls')): config['singleReportPath'] = os.path.join( path, getCurCaseName() + '.xls') if isSingle == True: config['is_need_single_analysis'] = True if os.path.exists(os.path.join(path, getCurCaseName() + '.xls')): config['singleReportPath'] = os.path.join( path, getCurCaseName() + '.xls') file_list = os.listdir(path) deviceInfo = {} for temp in file_list: deviceInfo = {} if temp.endswith('.kmz'): deviceInfo['timeZone'] = -18 deviceInfo['feature'] = 'kmz' deviceInfo['tech'] = 'novatel' deviceInfo['type'] = 'standard' deviceInfo['file_path'] = os.path.join(path, temp) config['deviceInfo'].append(deviceInfo) elif temp.split('.')[0] == 'novatel': deviceInfo['timeZone'] = 0 deviceInfo['feature'] = 'nmea' deviceInfo['tech'] = 'novatel' deviceInfo['type'] = 'standard' deviceInfo['file_path'] = os.path.join(path, temp) config['deviceInfo'].append(deviceInfo) elif temp.endswith('.txt') and temp.split('.')[0] != 'novatel': deviceInfo['timeZone'] = 0 deviceInfo['feature'] = 'nmea' if temp[:2].isdigit(): deviceInfo['tech'] = 'ip' + temp.split('_')[0].split( '.')[-1] + '_' + temp.split('_')[1] else: deviceInfo['tech'] = temp.split('_')[0] deviceInfo['type'] = 'test' deviceInfo['file_path'] = os.path.join(path, temp) config['deviceInfo'].append(deviceInfo) else: continue return SUC, config
def caseReportPath(self): return os.path.join(getLbsCaseLogPath(), 'CnrLinearityReport.xls')