Ejemplo n.º 1
0
def sbsubmitoriginal():
    data = request.form
    task = Task.getTask(data["prefix"])
    user = User.getUser(session["userid"])
    original = task.getOriginal(data["id"])

    try:
        if request.files["file"].filename[-3:] == "csv":
            csv = request.files["file"].stream
            original.loadcsv(
                user,
                csv,
                original.getNextnth(user),
                datetime.strptime(data["duration_start"], "%a %b %d %Y").date(),
                datetime.strptime(data["duration_end"], "%a %b %d %Y").date(),
            )
        elif request.files["file"].filename[-4:] == "xlsx":
            xlsx = request.files["file"].stream
            original.loadxlsx(
                user,
                xlsx,
                original.getNextnth(user),
                datetime.strptime(data["duration_start"], "%a %b %d %Y").date(),
                datetime.strptime(data["duration_end"], "%a %b %d %Y").date(),
            )

        else:
            return jsonify({"code": "err", "msg": "Wrong extension"})
    except:
        return jsonify({"code": "err", "msg": "Wrong extension"})

    return jsonify({"code": "success"})
Ejemplo n.º 2
0
	def parsecsv(self):
		csvread = io.StringIO(self.file.decode("utf8"))
		reader = csv.reader(utf_8_encoder(csvread), delimiter=',', quotechar="'")
		parsedlist = list()
		for row in reader:
			tsmodel = self.taskclass(User.getUser(self.submitterid).name, self.id)
			for (column, data) in zip(filter(lambda x: x.name[:3] == u"sch", inspect(self.taskclass).columns ), row):

				if type(column.type) == INTEGER:
					try :
						setattr(tsmodel,column.name, int(data))
					except :
						setattr(tsmodel,column.name, None)

				elif type(column.type) == DATETIME:
					try :
						setattr(tsmodel,column.name, datetime.strptime( data, "%Y-%m-%d %H:%M"))
					except :
						setattr(tsmodel,column.name, None)
	
				else :
					setattr(tsmodel,column.name, data)
			parsedlist.append(tsmodel)

		return parsedlist
Ejemplo n.º 3
0
	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
Ejemplo n.º 4
0
def sbparsedlist():
    data = request.get_json()
    task = Task.getTask(data["prefix"])
    user = User.getUser(session["userid"])
    parsedlist = task.getParsedBySubmitter(user)
    if task:
        return jsonify({"code": "success", "parsedlist": map(lambda x: x.dict(), parsedlist)})
    else:
        return jsonify({"code": "err", "msg": "No task"})
Ejemplo n.º 5
0
	def dict(self):

		return {
			"id" : self.id,
			"nth" : self.nth,
			"tuplenum" : self.tuplenum,
			"duplicatetuplenum" : self.duplicatetuplenum,
			"duration_start" : self.duration_start.isoformat(),
			"duration_end" : self.duration_end.isoformat(),
			"status" : self.status,
			"score" : self.score,
			"pnp" : self.pnp,
			"submitter" : User.getUser(self.submitterid).name,
			"original" : self.original.name,
			"evaluator": User.getUser(self.evaluatorid).name,
			"nullratio" : self.nullInfo()

		}
Ejemplo n.º 6
0
def usedit():
	data = request.get_json()
	user = User.getUser(session["userid"])

	if "password" in data :
		user.editInfo(name = data["name"],password = data["password"], gender= data["gender"], address= data["address"], birth= data["birth"], cellphone= data["cellphone"])
	else :
		user.editInfo(name = data["name"],password =  "", gender= data["gender"], address= data["address"], birth= data["birth"], cellphone= data["cellphone"])
	return jsonify({"code" : "success"})
Ejemplo n.º 7
0
def sboriginal():
    data = request.get_json()
    task = Task.getTask(data["prefix"])
    user = User.getUser(session["userid"])
    original = task.getOriginal(data["id"])

    if task:
        json = original.getInfoByUser(user)
        return jsonify({"code": "success", "original": json})
    else:
        return jsonify({"code": "err", "msg": "No task"})
Ejemplo n.º 8
0
def index():
    if "logged_in" in session and session["logged_in"]:
        user = User.getUser(session["userid"])
        if user.role == u"관리자":
            return render_template("admin.html")

        elif user.role == u"제출자":
            return render_template("submitter.html")
        elif user.role == u"평가자":
            return render_template("evaluator.html")

    return render_template("home.html")
Ejemplo n.º 9
0
def evsubmitevaluate():
    data = request.get_json()
    task = Task.getTask(data["prefix"])

    parsed = task.getParsed(data["id"])

    if data["pass"]:
        parsed.evaluate(data["score"], "Pass")
        user = User.getUser(parsed.submitterid).setScore()
        parsed.insertcsv()
    else:
        parsed.evaluate(data["score"], "Nonpass")

    return jsonify({"code": "success"})
Ejemplo n.º 10
0
def sbapply():
    data = request.get_json()
    task = Task.getTask(data["prefix"])
    user = User.getUser(session["userid"])

    if task:
        task.addUser(user)
        json = task.dict()
        json["originals"] = map(lambda x: x.dict(), task.getOriginals())
        json["originalnum"] = len(json["originals"])
        json["enrolled"] = task.checkUser(session["userid"])
        return jsonify({"code": "success", "task": json})
    else:
        return jsonify({"code": "err", "msg": "No task"})
Ejemplo n.º 11
0
	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
Ejemplo n.º 12
0
def sbtask():
    data = request.get_json()
    task = Task.getTask(data["prefix"])
    user = User.getUser(session["userid"])
    if task:
        json = task.dict()

        status = task.checkUserStatus(session["userid"])
        if task.status == "Stop":
            status = "Stop"
        json["originals"] = map(lambda x: x.dict(), task.getOriginals())
        json["originalnum"] = len(json["originals"])
        json["enrolled"] = task.checkUser(session["userid"])
        json["status"] = status
        json["parsednum"] = task.getParsedNumBySubmitter(user)
        json["submitok"] = status == "Approved"
        return jsonify({"code": "success", "task": json})
    else:
        return jsonify({"code": "err", "msg": "No task"})
Ejemplo n.º 13
0
def login():

    data = request.get_json()
    if "loginid" not in data or "password" not in data:
        session["logged_in"] = False
        abort(401)
        return jsonify(dict(msg=u"정보가 일치하지 않습니다."))

    if "logged_in" in session and session["logged_in"]:
        session["logged_in"] = True
        return jsonify(dict(msg=u"이미 로그인 되어 있습니다."))

    user = User.login(data["loginid"], data["password"])

    if user:
        session["logged_in"] = True
        session["userid"] = user.id
        return jsonify(dict(name=user.name, loginid=user.loginid, msg=u"로그인 성공"))

    else:
        session["logged_in"] = False
        abort(401)
Ejemplo n.º 14
0
def usinfo():

	user = User.getUser(session["userid"])
	return jsonify({"code" : "success", "user" : user.dict()})
Ejemplo n.º 15
0
def sbgetinfo():
    user = User.getUser(session["userid"])
    return jsonify({"user": user.getSubmitInfo()})
Ejemplo n.º 16
0
def sbsubmit(start=0, end=10):
    user = User.getUser(session["userid"])

    return jsonify({"tasks": user.enrollStatus()})
Ejemplo n.º 17
0
def users():
	userlist = User.getUsers()
	return jsonify({"users" : map(lambda x : x.dict(),userlist)})
Ejemplo n.º 18
0
#-*- 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()
Ejemplo n.º 19
0
def user():

	data = request.get_json()
	user = User.getUser(data["id"])
	return jsonify({"user" : user.dict()})
Ejemplo n.º 20
0
def usjoin():
	data = request.get_json()
	user = User.newUser(data["loginid"], data["password"], data["name"],data["gender"],data["address"],data["role"],data["birth"],data["cellphone"])
	return jsonify({"code" : "success"})
Ejemplo n.º 21
0
def usdelete():

	user = User.getUser(session["userid"])
	User.deleteUser(user)

	return logout()
Ejemplo n.º 22
0
#-*- coding: utf-8 -*-

from DBP.models import Base,engine, session
from sqlalchemy import  MetaData
from datetime import datetime
from DBP.models.task import Task
from DBP.models.user import User, Enroll
import io


print User.login(u"admin", u"1234")