def create(self, validated_data): XRFs = validated_data.get('XRFs') devEviXRFId = validated_data.get('devEviXRF') # 新建重复也不可以覆盖!!否则就和修改一样了啊 # devEviXRFTestFiles = devEviXRFTestFile.objects.filter(devEviXRF = devEviXRF) # for devEviXRFTestFileUp in devEviXRFTestFiles: # devEviXRFTestFileUp.delete() # 差错检验 if len(XRFs) == 0: raise APIException("没有上传XRF文件,请上传") if devEviXRF.objects.filter(id=int(devEviXRFId)).count() != 1: raise APIException("填入的爆炸装置XRF序号不存在,请重新输入") for index, url in enumerate(XRFs): if os.path.splitext(url.name)[-1] != '.xlsx': raise APIException("有XRF文件不是excel格式,请检查。") result = [] devEviXRF1 = devEviXRF.objects.get(id=int(devEviXRFId)) for index, url in enumerate(XRFs): # 会自动填入devEviId XRF = devEviXRFTestFile.objects.create( excelURL=url, devEviXRF=devEviXRF1, devEviId=devEviXRF1.devEvi_id) result = preProcess('XRF', devEviXRF1.id, XRF.id, os.path.join(MEDIA_ROOT, str(XRF.excelURL))) if result[0] == '0': XRF.handledURL = result[1] XRF.save() else: raise APIException("预处理过程出错") return {}
def create(self, validated_data): XRDs = validated_data.get('XRDs') exploEviXRDId = validated_data.get('exploEviXRD') # 新建重复也不可以覆盖!!否则就和修改一样了啊 # exploEviXRDTestFiles = exploEviXRDTestFile.objects.filter(exploEviXRD = exploEviXRD) # for exploEviXRDTestFileUp in exploEviXRDTestFiles: # exploEviXRDTestFileUp.delete() # 差错检验 if len(XRDs) == 0: raise APIException("没有上传XRD文件,请上传") if exploEviXRD.objects.filter(id=int(exploEviXRDId)).count() != 1: raise APIException("填入的炸药XRD序号不存在,请重新输入") for index, url in enumerate(XRDs): if os.path.splitext(url.name)[-1] != '.txt': raise APIException("有XRD文件不是txt格式,请检查。") result = [] exploEviXRD1 = exploEviXRD.objects.get(id=int(exploEviXRDId)) for index, url in enumerate(XRDs): # 会自动填入exploEviId XRD = exploEviXRDTestFile.objects.create( txtURL=url, exploEviXRD=exploEviXRD1, exploEviId=exploEviXRD1.exploEvi_id) result = preProcess('XRD', exploEviXRD1.id, XRD.id, os.path.join(MEDIA_ROOT, str(XRD.txtURL))) if result[0] == '0': XRD.txtHandledURL = result[1] XRD.save() else: raise APIException("预处理过程出错") return {}
def create(self, validated_data): Ramans = validated_data.get('Ramans') devEviRamanId = validated_data.get('devEviRaman') # 新建重复也不可以覆盖!!否则就和修改一样了啊 # devEviRamanTestFiles = devEviRamanTestFile.objects.filter(devEviRaman = devEviRaman) # for devEviRamanTestFileUp in devEviRamanTestFiles: # devEviRamanTestFileUp.delete() if len(Ramans) == 0: raise APIException("没有上传Raman文件,请上传") if devEviRaman.objects.filter(id=int(devEviRamanId)).count() != 1: raise APIException("填入的爆炸装置Raman序号不存在,请重新输入") for index, url in enumerate(Ramans): if os.path.splitext(url.name)[-1] != '.txt': raise APIException("有Raman文件不是txt格式,请检查。") result = [] devEviRaman1 = devEviRaman.objects.get(id=int(devEviRamanId)) for index, url in enumerate(Ramans): # 会自动填入devEviId devEviId = devEviRaman1.devEvi_id Raman = devEviRamanTestFile.objects.create( txtURL=url, devEviRaman=devEviRaman1, devEviId=devEviId) # 文件预处理 # 新增一个物证文件时,该Raman表中此物证的匹配结果必然是空的,此外因为更新走的也是补录的路径 # 因此如果新增物证文件,要将综合表和报告表中的此物证的删去来提示用户进行重新匹配 result = preProcess('RAMAN', devEviRaman1.id, Raman.id, os.path.join(MEDIA_ROOT, str(Raman.txtURL))) if result[0] == '0': Raman.txtHandledURL = result[1] Raman.save() else: raise APIException("预处理过程出错") return {}
def create(self, validated_data): Ramans = validated_data.get('Ramans') exploEviRamanId = validated_data.get('exploEviRaman') # 新建重复也不可以覆盖!!否则就和修改一样了啊 if len(Ramans) == 0: raise APIException("没有上传Raman文件,请上传") if exploEviRaman.objects.filter(id=int(exploEviRamanId)).count() != 1: raise APIException("填入的炸药Raman序号不存在,请重新输入") for index, url in enumerate(Ramans): if os.path.splitext(url.name)[-1] != '.txt': raise APIException("有Raman文件不是txt格式,请检查。") result = [] exploEviRaman1 = exploEviRaman.objects.get(id=int(exploEviRamanId)) for index, url in enumerate(Ramans): # 会自动填入exploEviId Raman = exploEviRamanTestFile.objects.create( txtURL=url, exploEviRaman=exploEviRaman1, exploEviId=exploEviRaman1.exploEvi_id) result = preProcess('RAMAN', exploEviRaman1.id, Raman.id, os.path.join(MEDIA_ROOT, str(Raman.txtURL))) if result[0] == '0': Raman.txtHandledURL = result[1] Raman.save() else: raise APIException("预处理过程出错") return {}
def create(self, validated_data): XRFs = validated_data.get('XRFs') devPartSampleXRFId = validated_data.get('devPartSampleXRF') # 差错检验 if len(XRFs) == 0: raise APIException("没有上传XRF文件,请上传") if devPartSampleXRF.objects.filter(id=int(devPartSampleXRFId)).count() != 1: raise APIException("填入的爆炸装置XRF序号不存在,请重新输入") for index, url in enumerate(XRFs): if os.path.splitext(url.name)[-1] != '.xlsx': raise APIException("有XRF文件不是excel格式,请检查。") result = [] devPartSampleXRF1 = devPartSampleXRF.objects.get(id=int(devPartSampleXRFId)) for index, url in enumerate(XRFs): devPartSampleId = devPartSampleXRF1.devPartSample_id XRF = devPartSampleXRFTestFile.objects.create(excelURL=url,devPartSampleXRF = devPartSampleXRF1) result = preProcess('XRF', devPartSampleXRF1.id, XRF.id, os.path.join(MEDIA_ROOT, str(XRF.excelURL))) if result[0] == '0': XRF.handledURL = result[1] XRF.save() # 文件预处理,更新XRF匹配表和综合匹配表的结果 # 样本库更新报告都得变 else: raise APIException("预处理过程出错") return {}
def create(self, validated_data): Ramans = validated_data.get('Ramans') devPartSampleRamanId = validated_data.get('devPartSampleRaman') if len(Ramans) == 0: raise APIException("没有上传Raman文件,请上传") if devPartSampleRaman.objects.filter(id=int(devPartSampleRamanId)).count() != 1: raise APIException("填入的爆炸装置Raman序号不存在,请重新输入") for index, url in enumerate(Ramans): if os.path.splitext(url.name)[-1] != '.txt': raise APIException("有Raman文件不是txt格式,请检查。") result = [] devPartSampleRaman1 = devPartSampleRaman.objects.get(id=int(devPartSampleRamanId)) for index, url in enumerate(Ramans): devPartSampleId = devPartSampleRaman1.devPartSample_id Raman = devPartSampleRamanTestFile.objects.create(txtURL=url,devPartSampleRaman = devPartSampleRaman1) result = preProcess('RAMAN',devPartSampleRaman1.id,Raman.id,os.path.join(MEDIA_ROOT,str(Raman.txtURL))) if result[0] == '0': Raman.txtHandledURL = result[1] Raman.save() # 文件预处理,更新Raman匹配表和综合匹配表的结果 else: raise APIException("预处理过程出错") return {}
def create(self, validated_data): FTIRs = validated_data.get('FTIRs') exploSampleFTIRId = validated_data.get('exploSampleFTIR') # 差错检验 if len(FTIRs) == 0: raise APIException("没有上传FTIR文件,请上传") if exploSampleFTIR.objects.filter(id=int(exploSampleFTIRId)).count() != 1: raise APIException("填入的炸药FTIR序号不存在,请重新输入") for index, url in enumerate(FTIRs): if os.path.splitext(url.name)[-1] != '.txt': raise APIException("有FTIR文件不是txt格式,请检查。") result = [] exploSampleFTIR1 = exploSampleFTIR.objects.get(id=int(exploSampleFTIRId)) for index, url in enumerate(FTIRs): FTIR = exploSampleFTIRTestFile.objects.create(txtURL=url,exploSampleFTIR = exploSampleFTIR1) result = preProcess('FTIR',exploSampleFTIR1.id,FTIR.id,os.path.join(MEDIA_ROOT,str(FTIR.txtURL))) if result[0] == '0' : FTIR.txtHandledURL = result[1] FTIR.save() # 文件预处理,更新FTIR匹配表和综合匹配表的结果 else: raise APIException("预处理过程出错") # 对上传的文档预处理取平均,再将取完平均的回填 return {}
def create(self, validated_data): XRDs = validated_data.get('XRDs') exploSampleXRDId = validated_data.get('exploSampleXRD') # 差错检验 if len(XRDs) == 0: raise APIException("没有上传XRD文件,请上传") if exploSampleXRD.objects.filter(id=int(exploSampleXRDId)).count() != 1: raise APIException("填入的炸药XRD序号不存在,请重新输入") for index, url in enumerate(XRDs): if os.path.splitext(url.name)[-1] != '.txt': raise APIException("有XRD文件不是txt格式,请检查。") result = [] exploSampleXRD1 = exploSampleXRD.objects.get(id=int(exploSampleXRDId)) for index, url in enumerate(XRDs): XRD = exploSampleXRDTestFile.objects.create(txtURL=url,exploSampleXRD = exploSampleXRD1) result = preProcess('XRD',exploSampleXRD1.id,XRD.id,os.path.join(MEDIA_ROOT,str(XRD.txtURL))) if result[0] == '0': XRD.txtHandledURL = result[1] XRD.save() # 文件预处理,更新XRD匹配表和综合匹配表的结果 else: raise APIException("预处理过程出错") return {}
def create(self, validated_data): FTIRs = validated_data.get('FTIRs') devEviFTIRId = validated_data.get('devEviFTIR') # 新建重复也不可以覆盖!!否则就和修改一样了啊 # devEviFTIRTestFiles = devEviFTIRTestFile.objects.filter(devEviFTIR = devEviFTIR) # for devEviFTIRTestFileUp in devEviFTIRTestFiles: # devEviFTIRTestFileUp.delete() # 差错检验 if len(FTIRs) == 0: raise APIException("没有上传FTIR文件,请上传") if devEviFTIR.objects.filter(id=int(devEviFTIRId)).count() != 1: raise APIException("填入的爆炸装置的FTIR序号不存在,请重新输入") for index, url in enumerate(FTIRs): if os.path.splitext(url.name)[-1] != '.txt': raise APIException("有FTIR文件不是txt格式,请检查。") result = [] devEviFTIR1 = devEviFTIR.objects.get(id=int(devEviFTIRId)) for index, url in enumerate(FTIRs): # 会自动填入devEviId devEviId = devEviFTIR1.devEvi_id FTIR = devEviFTIRTestFile.objects.create(txtURL=url, devEviFTIR=devEviFTIR1, devEviId=devEviId) # 文件预处理 # 新增一个物证文件时,该FTIR表中此物证的匹配结果必然是空的,此外因为更新走的也是补录的路径 # 因此如果新增物证文件,要将综合表和报告表中的此物证的删去来提示用户进行重新匹配 result = preProcess( 'FTIR', devEviFTIR1.id, FTIR.id, os.path.join(MEDIA_ROOT, str(FTIR.txtURL)), ) if result[0] == '0': FTIR.txtHandledURL = result[1] FTIR.save() else: raise APIException("预处理过程出错") return {}
def create(self, validated_data): GCMSs = validated_data.get('GCMSs') exploEviGCMSId = validated_data.get('exploEviGCMS') # type = validated_data.get('type') GCMS2s = [] result = [] filePath = "" TICId = 0 nameList = [] # 差错检验 if len(GCMSs) == 0: raise APIException("没有上传GC_MS文件,请上传") if exploEviGCMS.objects.filter(id=int(exploEviGCMSId)).count() != 1: raise APIException("填入的炸药GC_MS序号不存在,请重新输入") for index, url in enumerate(GCMSs): if os.path.splitext(url.name)[-1] != '.txt': raise APIException("有GC_MS文件不是txt格式,请检查。") name = url.name type = os.path.splitext(name)[0] nameList.append(type) if "TIC" not in nameList: raise APIException("上传的GC_MS文件中没有TIC.txt文档,请重新上传") exploEviGCMS1 = exploEviGCMS.objects.get(id=int(exploEviGCMSId)) for index, url in enumerate(GCMSs): # 会自动填入exploSampleId # 从url中知道type,如果是TIC的type,那么就创建一个以此id和样本id联合的文件夹用来存放这一批的文档, # 先存下来,再移动 GCMS = exploEviGCMSTestFile.objects.create( txtURL=url, exploEviGCMS=exploEviGCMS1, exploEviId=exploEviGCMS1.exploEvi_id) name = url.name type = os.path.splitext(name)[0] GCMS.type = type GCMS.save() if type == "TIC": filePath = os.path.join( MEDIA_ROOT, "file/exploEviGCMSTestFile/%d_%d/" % (GCMS.exploEviId, GCMS.id)) os.makedirs(filePath) TICId = GCMS.id GCMS2s.append(GCMS) for GCMS2 in GCMS2s: prePath = os.path.join(MEDIA_ROOT, str(GCMS2.txtURL)) name = os.path.basename(prePath) newPath = os.path.join(filePath, name) if os.path.exists(prePath) == False: raise APIException("上传的GC_MS文件夹路径被更改,找不到文件夹,无法进行预处理") #移动文件(目录) shutil.move(prePath, newPath) GCMS2.txtURL = newPath GCMS2.save() # 预处理方法,给filePath即为所在的文件夹 # blog = exploSampleGCMSFileSerializer(GCMS2, context=self.context) # GCMS3s.append(blog.data['handledData']) # 处理完一批我就删掉? # 对上传的文档预处理取平均,再将取完平均的回填到exploSampleGCMSAverFile GCMSFile = exploEviGCMSFile.objects.create( exploEviGCMS=exploEviGCMS1, exploEviId=exploEviGCMS1.exploEvi_id) result = preProcess('GCMS', exploEviGCMS1.id, GCMSFile.id, filePath) if result[0] == '0': GCMSFile.txtHandledURL = result[1] GCMSFile.save() # result = preProcess('GCMS', exploEviGCMS.id, TICId, filePath) # if result[0] == '0': # exploEviGCMSFile.objects.create(exploEviGCMS = exploEviGCMS,exploEviId =exploEviGCMS.exploEvi_id, txtHandledURL = result[1]) else: raise APIException("预处理过程出错") return {}