def evaluate(self, score,pnp): self.status = "Evaluated" self.score = 5 * score + 25 *( 1.0 - self.duplicatetuplenum/(self.tuplenum * 1.0) ) + 25 * (1.0 - sum(map(lambda x : x['ratio'] ,self.nullInfo()))/(len(self.nullInfo())*1.0)) self.pnp = pnp session.commit()
def insertcsv(self): if self.pnp != "Pass": return False session.bulk_save_objects(self.parsecsv()) session.commit() return True
def loadxlsx(self,submitter,xlsxread,nth,duration_start,duration_end): wb = load_workbook(xlsxread) ws = wb.active csvwrite = io.BytesIO() writer = csv.writer(csvwrite, delimiter=',', quotechar="'") maplist = self.mapList() counter = 0 dupset = set() dupcounter = 0 nullcount = dict() schema = self.getSchema() for col in schema: nullcount[col.name] = 0 for rrow in ws.rows: crow = list() for mapnum, col in zip(maplist, schema): if type(rrow[mapnum].value) == datetime: crow.append(rrow[mapnum].value.strftime("%Y-%m-%d %H:%M")) else : crow.append(rrow[mapnum].value) if rrow[mapnum].value == "": nullcount[col.name] +=1 dupset.add(unicode(crow)) utfrow = list () for x in crow: if type(x) == unicode : utfrow.append(x.encode("utf8")) else : utfrow.append(x) writer.writerow(utfrow) counter += 1 evaluator = User.randomEvaluator() parsedmodel = self.parsedclass(nth,duration_start,duration_end,csvwrite,counter, counter - len(dupset)) parsedmodel.submitterid = submitter.id parsedmodel.evaluatorid = evaluator.id self.taskrow.addUser(evaluator) for col in schema : setattr(parsedmodel,"null_" + col.name[4:] , nullcount[col.name] / (counter*1.0) ) self.parseds.append(parsedmodel) session.commit() return parsedmodel
def addUser(self, user): if self.enroll.filter(Enroll.userid == user.id).count() == 0: enroll = Enroll() enroll.user = user self.enroll.append(enroll) session.commit()
def newUser(loginid, password, name, gender, address , role, birth,cellphone): user = User(loginid, name, password) user.gender = gender user.address = address user.role = role user.birth = datetime.strptime(birth, "%a %b %d %Y").date() user.cellphone = cellphone session.add(user) session.commit()
def editInfo(self, name, password, gender, address, birth, cellphone): if password.strip() != "": self.password = generate_password_hash(password) self.name = name self.gender = gender self.address = address self.birth = datetime.strptime(birth, "%a %b %d %Y").date() self.cellphone = cellphone session.commit()
def newTask(data): task = Task(data["name"], data["duration"], data["prefix"]) task.information = data["information"] session.add(task) if task.generateTables(data["schemas"]): session.commit() return task
def deleteUser(user): for en in user.enrolls: en.task.setTables() ps = session.query(en.task.parsed).filter(en.task.parsed.submitterid == user.id).all() for p in ps: for t in p.tasks: session.delete(t) session.delete(p) for e in user.enrolls : session.delete(e) session.delete(user) session.commit()
def loadcsv(self,submitter,csvread,nth,duration_start,duration_end): reader = csv.reader(csvread, delimiter=',', quotechar="'") csvwrite = io.BytesIO() writer = csv.writer(csvwrite, delimiter=',', quotechar="'") maplist = self.mapList() counter = 0 dupset = set() dupcounter = 0 nullcount = dict() schema = self.getSchema() for col in schema: nullcount[col.name] = 0 for rrow in reader: crow = list() for mapnum, col in zip(maplist, schema): crow.append(rrow[mapnum]) if rrow[mapnum] == "": nullcount[col.name] +=1 dupset.add(unicode(crow)) writer.writerow(crow) counter += 1 evaluator = User.randomEvaluator() parsedmodel = self.parsedclass(nth,duration_start,duration_end,csvwrite,counter, counter - len(dupset)) parsedmodel.submitterid = submitter.id parsedmodel.evaluatorid = evaluator.id self.taskrow.addUser(evaluator) for col in schema : setattr(parsedmodel,"null_" + col.name[4:] , nullcount[col.name] / (counter*1.0) ) self.parseds.append(parsedmodel) session.commit() return parsedmodel
def setStatus(self,status): self.status = status session.commit()
def changeSubmitterStatus(self, userid, status): self.enroll.filter(Enroll.userid == userid).first().status = status session.commit()
def newOriginal(self, length, name, mappinginfo): originalmodel = self.original(length, name, mappinginfo) session.add(originalmodel) session.commit() return originalmodel
#-*- coding: utf-8 -*- from DBP.models import Base,engine, session from DBP.models.user import User admin = User(u"admin",u"관리자",u"1234") admin.role = u"관리자" session.add(admin) session.commit()