def scraper_test_update(request,id): #get parameters index=int(request.REQUEST["index"]) fields={} for field in ['merchantItemTitle','pricePlusTax','priceEft','modelNameView','brand','mpnValue','shipping','inStock']: if field in request.REQUEST: fields[field]=request.REQUEST[field] #create merchantItem item=MerchantItem() for field in vars(item): if field in fields.keys(): setattr(item,field,fields[field]) else: setattr(item,field,None) #get test case data=TestCase.get(id=id) #update data.data[index]["meta.refitem"]=item.to_dict() data.save() #return authentication return HttpResponse( AIResponse().serialize() )
def test_check(request,id,tid): #get controller api api=ControllerAPI(request) report=api.gettaskresults(tid) #if ready, get urls if report[0]["status"]=="complete": #get test case data=TestCase.get(id=id) #set data data.data=report[0]["result"] #if batch, prepare the reference items if data.batch is not None: for index in range(len(data.data)): #find the batch reference data for this item xmlitem=data.data[index]['meta.xmlitem'] for batch in data.batch: if batch['merchant']['merchantId']==xmlitem['merchant']['merchantId'] and batch['merchantItemId']==xmlitem['merchantItemId']: #create merchantItem with values from the xml as reference item=MerchantItem() item.merchantItemTitle=xmlitem["merchantItemTitle"] item.brand=xmlitem["brand"] item.mpnValue=xmlitem["mpnValue"] item.item={"itemId":batch["item"]["itemId"]} data.data[index]["meta.refitem"]=item.to_dict() #update data.status=TestCase.STATUS_READY data.save() #return authentication return HttpResponse( AIResponse(data=data.data).serialize() )
def matcher_test_update(request,id): #get parameters index=int(request.REQUEST["index"]) fields={} for field in ['merchantItemTitle','brand','mpnValue','item.itemId']: if field in request.REQUEST: tokens=field.split(".") if len(tokens)>1: fields[tokens[0]]={} fields[tokens[0]][tokens[1]]=request.REQUEST[field] else: fields[field]=request.REQUEST[field] #create merchantItem item=MerchantItem() for field in vars(item): if field in fields.keys(): setattr(item,field,fields[field]) else: setattr(item,field,None) #get test case data=TestCase.get(id=id) #update data.data[index]["meta.refitem"]=item.to_dict() data.save() #return authentication return HttpResponse( AIResponse().serialize() )
def test_new(request): #get merchants api=ControllerAPI(request) merchants=api.getmerchants() #create? if "action" in request.REQUEST and request.REQUEST["action"]=="update": #get parameters auto=int(request.REQUEST["auto"]) label=request.REQUEST["label"] module=request.REQUEST["module"] merchantid=request.REQUEST["merchant"] items=request.REQUEST["items"] #autogenerate samples? if auto==1: #find merchant name mname="*" if merchantid!="*": for merchant in merchants: if merchantid==merchant["id"]: merchantname=merchant["name"] #create data=TestCase() data.owner=request.session["user"].id data.label=label data.module=module data.op="match" if module.endswith("Matcher") else "scrap" data.target={"merchant":{"id":merchantid,"name":merchantname}} data.create() #create task to generate samples for the training data tasks=[] task=Task() task.target="cimri.module.automation.controller.Controller" task.op="controller.schedule" task.threadtags="test: "+label tasks.append(task) task=Task() task.target="cimri.module.crawler.productxml.ProductXMLCrawler" task.op="sample" if merchantid!="*": task.meta["merchants.id"]=int(merchantid) task.meta["sample.size"]=40 tasks.append(task) #create samples based on the provided list of item IDs else: #get items input=eval(items.replace("\n","")) items=[] for it in input: item=MerchantItem() item.merchant={"merchantId":str(it[0]).strip()} item.merchantItemId=str(it[1]).strip() item.item={"itemId":str(it[2]).strip()} items.append(item) #create data=TestCase() data.owner=request.session["user"].id data.label=label data.module=module data.op="match" if module.endswith("Matcher") else "scrap" data.target={} data.batch=[item.to_dict() for item in items] data.create() #create task to generate samples for the training data tasks=[] task=Task() task.target="cimri.module.automation.controller.Controller" task.op="controller.schedule" task.threadtags="test: "+label tasks.append(task) task=Task() task.target="cimri.module.crawler.productxml.ProductXMLCrawler" task.op="get" task.data=items task.meta={"workers":8} tasks.append(task) #schedule api=ControllerAPI(request) res=api.schedule(tasks) #get task id tid=res[1] #template context context=_get_context(request,section="common",content="content_test_created",test=data,tid=tid) else: #template context context=_get_context(request,section="common",content="content_test_new",merchants=merchants) #render return HttpResponse( get_template('template_content.html').render(Context(context)) )