def select_goods(self, name, usesql): usesql = usesql sql = f''' select * from classification_add where classification_name='{name}' ''' data = usesql.userSql(sql) logger.info('挑选数据') return data
def add_goods(self, name, status, source, usesql): usesql = usesql sql = f''' INSERT INTO classification_add (classification_name,status,logo,url,parentId,source) VALUES('{name}','{status}','/resource/RETAIL/20211119/e8e6c8b16ef842a681e4054f53be2725.png','','0','{source}'); ''' usesql.userSql(sql) logger.info('添加数据')
def userSql(self,sql): try: self.cursor.execute(sql) text=self.cursor.fetchall() if text: return text else: self.db.commit() print('提交成功') logger.info('提交成功') except Exception as e: print(e) logger.info(e) self.db.rollback()
def test_classficationAdd_false(self,status,name,recommend,source,getLogo,getSession,getYaml): logo=getLogo data={ "parentId": "0", "status":status, "storeId": "1514e1d61686438f95fa46f19070c126", "name": name, "sequence": 1, "logo": logo, "recommend": recommend, "source":source } url='https://backstageservices.dreawer.com/gc/classification/add' s=getSession r=s.post(url=url,json=data).json() logger.info(f'此时的入参:\n{data} 和响应值{r}') assert r['comment'] == 'Completed successfully' assert r['code'] == '000000' id = r['data'] host = getYaml['host'] ClassficationDete(s, host).classficationDete(id)
def environment(request): os.environ['environment'] = request.config.getoption('--environment') print(environment) logger.info('当前运行环境:%s' % os.environ['environment']) return os.environ['environment']
def test_goodsAdd_true(self, name, stockType, status, recommend, source, stock, salesVolume, price, description, getSession, add_goods, select_goods, delete_goods): data = { "storeId": "1514e1d61686438f95fa46f19070c126", "name": name, "categoryId": "bedbdf24503b11e8a3bc7cd30abc", "stockType": stockType, "mainFigure": "/resource/RETAIL/20211117/914e6a7ac79841b19b6509cef6d953ef.png", "service": "Test", "status": status, "recommend": recommend, "source": source, "classificationIds": [ "ca90efc41743422a9e3fd6429a1e5bd2", "86f94b0b2c3e4c789409410db66c9517" ], "skus": [{ "stock": stock, "salesVolume": salesVolume, "originalPrice": "223", "price": price, 'description': description }], "goodsPropertyNames": [], "freightParam": { "type": "FIXED", "price": "12", "freightTemplateId": "" }, "allowRefund": True, "express": True, "cityDistribution": False, "selfPickUp": False, "detail": None } logger.info('{},{},{},{},{},{},{},{},{}'.format( name, stockType, status, recommend, source, stock, salesVolume, price, description)) s = getSession logger.info('s={}'.format(s)) url = 'https://backstageservices.dreawer.com/gc/goods/add' a = s.post(url=url, json=data) r = a.json() print(r) print(type(r)) logger.info('该接口执行花费了{}s'.format(a.elapsed.total_seconds())) data = select_goods[0] logger.info(data) assert r['comment'] == "Completed successfully" assert r['code'] == '000000' assert data['classification_name'] == name assert data['source'] == source assert data['status'] == status
def delete_goods(self, name, usesql): usesql = usesql sql = f'delete from classification_add where classification_name="{name}"' usesql.userSql(sql) logger.info('删除添加的数据')
def extractBatchContractFeature(self, dbsession: session, min_id: int = 0, max_id: int = 60000, batchSize: int = 500): processinglist:List[ProcessingState] = dbsession.query(ProcessingState)\ .filter(ProcessingState.id.between(min_id,max_id))\ .filter(ProcessingState.fullyextracted == 0)\ .limit(batchSize) if not processinglist: logger.warning( "All Smart Contracts Have Been Successfully Feature-Extracted") # SCid: int = 1 for processing in processinglist: # time.sleep(0.2) print("当前抽取特征的批次完成进度: %d / %d" % (SCid, batchSize)) contractAddr = processing.contractAddr logger.info("Extracting Features for Contract:{contract}".format( contract=contractAddr)) # cpmState = processing.complexityMetricExtracted ctmState = processing.countMetricExtracted oomState = processing.objectOrientedMetricExtracted lrmState = processing.languageRelatedMetricExtracted allState = all([cpmState, ctmState, oomState, lrmState]) rootNode: solcast.nodes.NodeBase = self._getRootNode( contractAddr=contractAddr, versionString=processing.solc_versions) print(processing) try: if not processing.complexityMetricExtracted: cpmState: bool = self._extractComplexityMetric( dbsession, contractAddr, rootNode=rootNode) if cpmState: logger.info( "|___Extracting ComplexityMetric for Contract:{contract} Successfully." .format(contract=contractAddr)) else: logger.error( "|___Extracting ComplexityMetric for Contract:{contract} Failed!." .format(contract=contractAddr)) assert cpmState == True if not processing.countMetricExtracted: ctmState: bool = self._extractCountMetric( dbsession, contractAddress=contractAddr, rootNode=rootNode) if ctmState: logger.info( "|___Extracting CountMetric Features for Contract:{contract} Successfully." .format(contract=contractAddr)) else: logger.error( "|___Extracting CountMetric Features for Contract:{contract} Failed!." .format(contract=contractAddr)) assert ctmState == True if not processing.objectOrientedMetricExtracted: oomState: bool = self._extractObjectOrientedMetric( dbsession, contractAddress=contractAddr, rootNode=rootNode) if oomState: logger.info( "|___Extracting ObjectOrientedMetric Features for Contract:{contract} Successfully." .format(contract=contractAddr)) else: logger.error( "|___Extracting ObjectOrientedMetric Features for Contract:{contract} Failed!." .format(contract=contractAddr)) assert oomState == True if not processing.languageRelatedMetricExtracted: lrmState: bool = self._extractLanguageRelatedMetric( dbsession, contractAddress=contractAddr, rootNode=rootNode) if lrmState: logger.info( "|___Extracting LanguageRelatedMetric Features for Contract:{contract} Successfully." .format(contract=contractAddr)) else: logger.error( "|___Extracting LanguageRelatedMetric Features for Contract:{contract} Failed!." .format(contract=contractAddr)) assert lrmState == True except Exception as e: logger.error( "|___Extracting Features for Contract:{contract} ERROR: {emsg}" .format(contract=contractAddr, emsg=e)) break else: allState = all([cpmState, ctmState, oomState, lrmState]) if allState: logger.success( "Extracting Features for Contract:{contract} Full SUCCESSFULLY!" .format(contract=contractAddr)) else: logger.warning( "Extracting Features for Contract:{contract} PARTIAL SUCCESSFULLY!" .format(contract=contractAddr)) finally: processing.fullyextracted = allState processing.complexityMetricExtracted = cpmState processing.countMetricExtracted = ctmState processing.objectOrientedMetricExtracted = oomState processing.languageRelatedMetricExtracted = lrmState dbsession.commit() dbsession.flush() logger.success( "Update Information on ProcessingState Table for Contract:{contract} successfully!" .format(contract=contractAddr)) SCid = SCid + 1