Esempio n. 1
0
def add_note(label, title, content, state):
    if state not in CONST_STATE:
        return Result(Status.StatusErr, msg='参数state有误')
    userid = session['userid']
    res = note.add_note(userid, label, title, content, state)
    return Result(Status.OK if res else Status.Error)
    pass
Esempio n. 2
0
def check():
    res = UserManager.get_userinfo(session['userid'])
    if res:
        del res['uid']
        del res['password']
        return Result(Status.OK, **res)
    else:
        return Result(Status.LoginReq)
Esempio n. 3
0
def view_note(noteid):
    res = note.get_note(noteid)
    if not res or res['state'] not in CONST_STATE:
        return Result(Status.Error)
    author = res['author']
    del res['author']
    if res['state'] == 'save' or session.get('userid', None) == author:
        return Result(Status.OK, **res)
    return Result(Status.AuthErr)  # 这里返回权限问题
Esempio n. 4
0
def login(account, password):
    res = UserManager.check_login(account, password)
    if res and 'uid' in res:
        session['userid'] = res['uid']
        session.permanent = True
        del res['uid']
        del res['password']
        return Result(Status.OK, **res)
    else:
        return Result(Status.Error, msg='账号或密码错误')
Esempio n. 5
0
def get_usernotes(state):
    if state == 'mine':
        res = note.get_usernotes_mine(session['userid'])
    elif state not in CONST_STATE:
        return Result(Status.StatusErr, msg='参数state有误')
    else:
        res = note.get_usernotes(session['userid'], state)
    for r in res:
        r['content'] = r['content'][0:200]
    return Result(Status.OK, notes=res)
 def getStudentGrade(self, studentID):
     global g_Database
     rows = g_Database.fetchAll('SELECT * FROM result where ExamID=' +
                                str(self.examID) + ' and studentID = ' +
                                str(studentID))
     if not len(rows):
         return None  # no row found
     result = Result()
     result.read_row(rows[0])
     return result
Esempio n. 7
0
def admin_register(admin, account, password):
    # 对注册接口进行管理权限验证
    if admin != CurConfig.ADMIN_PWD:
        return Result(Status.AuthErr, msg="权限错误")
    # 先判断account是否已经存在
    judge = UserManager.check_account(account)
    if judge:
        return Result(Status.AcctExist, msg="用户名已经存在")
    res = UserManager.add_user(account, password)
    if not res:
        return Result(Status.DBErr, msg="注册失败")
    return Result(Status.OK, msg="注册成功")
Esempio n. 8
0
    def predi(self, xo, yo, param):
        p = []
        j = 0
        print("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
        while (j <= len(xo) - 200):
            print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
            linie = []
            for i in range(j, j + 200):
                linie.append(xo[i])
                linie.append(yo[i])
            p.append(linie)
            j = j + 10

        loaded_model = pickle.load(open('finalized_model.sav', 'rb'))
        norm = sklearn.preprocessing.normalize(p)
        predict = loaded_model.predict(norm)
        print(predict)

        s = 0.0
        for i in range(0, len(predict)):
            s = s + predict[i]
        mean = s / len(predict)

        result = Result(date=date.today(),
                        results=predict,
                        mean=mean,
                        pacientId=param)
        return result
Esempio n. 9
0
    def confirm_submit():
        has_incorrect_grade = False
        for g in range(len(grade_point)):
            text_button = grade_point[g]
            grade = text_button.get(1.0, "end-1c")

            if int(grade) < 0 or int(grade) > 100:
                has_incorrect_grade = True

        if has_incorrect_grade:
            showerror(title="Error",
                      message="Invalid Grade Point!",
                      icon="error")
        else:
            result = askquestion(title="Confirmation",
                                 message="Do you want to confirm?")
            if result == "yes":
                exam_id = exam.examID
                for g in range(len(grade_point)):
                    student_id = studentIncourse[g].studentID
                    currentResult = exam.getStudentGrade(student_id)
                    grade = int(grade_point[g].get(1.0, "end-1c"))
                    if currentResult == None:  #no dubplicate grades for the same student / course. >> check db before adding it
                        result = Result()
                        result.grade = grade
                        result.examID = exam_id
                        result.studentID = student_id
                        result.insert()
                    else:
                        currentResult.grade = grade
                        currentResult.update()

                ui.AdminWindowStudyViewCourses.view_courses(
                    window, return_function, course.getStudy())
Esempio n. 10
0
 def wrapper():
     if not (args and request.data):
         return jsonifyResult(func())
     data = json.loads(request.data)
     res = {}
     for key in args:
         if key not in data:
             return jsonifyResult(
                 Result(Status.FormErr,
                        msg='Missing Parameters ' + key))
         res[key] = data[key]
     return jsonifyResult(func(**res))
    def calculate_result(self,
                         database_ratings,
                         user_id,
                         database_movies,
                         log=None):

        # RESULTADO GERAL
        sum_rsme = 0
        sum_mae = 0
        sum_mse = 0
        count = 0

        # PERCORRE AS RECOMENDAÇÕES GERADAS
        for movie in database_movies:

            # VERIFICA SE A RECOMENDAÇÃO GERADA JÁ FOI AVALIADA PELO USUÁRIO
            if movie[1] in database_ratings[str(user_id)]:
                # CALCULA DIFERENÇA
                dif = database_ratings[str(user_id)][movie[1]] - movie[0]

                # LOG DA DIFERENÇA ENTRE AVALIAÇÃO REAL E A GERADA
                '''if log is not None:
                    print(log + ": " + str(database_ratings[str(user_id)][movie[1]]) + " - " + str(
                        movie[0]) + " -> " + str(dif))'''
                Util.write_result(
                    "relatorio_50",
                    str(user_id) + ";" + log + ";" +
                    str(database_ratings[str(user_id)][movie[1]]) + ";" +
                    str(movie[0]) + ";" + str(dif))

                # RESULTADOS
                sum_rsme += pow(dif, 2)
                sum_mae += abs(dif)
                sum_mse += pow(dif, 2)

                # COUNT
                count += 1

        # RETORNA RESULTADO
        return Result(sum_rsme, sum_mae, sum_mse, count)
Esempio n. 12
0
def register(account, password, code):
    if not ('randimg' in session
            and session['randimg'].upper() == code.upper()):
        return Result(Status.RegImgErr, msg="验证码有误")
    # 检查参数
    if len(account) < 4 or re.match("[^a-zA-Z0-9]", account):
        return Result(Status.RegAccErr, msg="账号格式有误")
    if len(password) != 32:
        return Result(Status.RegPwdErr, msg="密码格式有误")
    # 先判断account是否已经存在
    judge = UserManager.check_account(account)
    if judge:
        return Result(Status.AcctExist, msg="用户名已经存在")
    res = UserManager.add_user(account, password)
    if not res:
        return Result(Status.DBErr, msg="注册失败")
    return Result(Status.OK, msg="注册成功")
Esempio n. 13
0
def set_name(name):
    res = UserManager.set_username(session['userid'], name)
    return Result(Status.OK if res else Status.Error)
Esempio n. 14
0
def get_catalogue():
    res = note.get_catalogue()
    return Result(Status.OK, notes=res)
    pass
Esempio n. 15
0
def get_allnotes():
    res = note.get_allnotes()
    for r in res:
        r['content'] = r['content'][0:200]  # 这里可以做内容缓存
    return Result(Status.OK, notes=res)
Esempio n. 16
0
def look_note(noteid):
    res = note.look_note(noteid)
    return Result(Status.OK)
Esempio n. 17
0
def add_label(value, color):
    res = note.add_label(session['userid'], value, color)
    if not res:
        return Result(Status.Error)
    return Result(Status.OK, lid=res['l_id'])
Esempio n. 18
0
 def wrapper(**args):
     if 'userid' not in session:
         return Result(Status.LoginReq, msg='Require Login')
     return func(**args)
Esempio n. 19
0
def all_url():
    res = note.all_url(session['userid'])
    return Result(Status.OK, lists=res)
Esempio n. 20
0
def logout():
    if 'userid' in session:
        del session['userid']
    return Result(Status.OK)
Esempio n. 21
0
def add_url(title, url, desc):
    res = note.add_url(session['userid'], title, url, desc)
    return Result(Status.OK if res else Status.Error)
Esempio n. 22
0
def del_label(lid):
    res = note.del_label(session['userid'], lid)
    return Result(Status.OK if res else Status.Error)
Esempio n. 23
0
def get_labels():
    res = note.get_labels(session['userid'])
    return Result(Status.OK, labels=res)
Esempio n. 24
0
def revise_state(noteid, state):
    if state not in CONST_STATE:
        return Result(Status.StatusErr, msg='参数state有误')
    res = note.revise_state(session['userid'], noteid, state)
    return Result(Status.OK if res else Status.Error)
Esempio n. 25
0
def delete_note(noteid):
    res = note.delete_note(session['userid'], noteid)
    return Result(Status.OK if res else Status.Error)
Esempio n. 26
0
def get_url(fid):
    res = note.get_url(fid, session['userid'])
    if not res:
        return Result(Status.Error)
    return Result(Status.OK, **res)
Esempio n. 27
0
def get_page_notes(user):
    res = note.get_page_notes(user)
    return Result(Status.OK, notes=res)
Esempio n. 28
0
def set_password(password):
    res = UserManager.set_password(session['userid'], password)
    return Result(Status.OK if res else Status.Error)
Esempio n. 29
0
def del_url(fid):
    res = note.del_url(fid, session['userid'])
    return Result(Status.OK if res else Status.Error)
    def realize_avaliation(self, fc_number, fbc_number, with_context=False):

        Util.write_result("relatorio_50",
                          "user;avaliacao_real;avaliacao_gerada;diferenca")

        # CARREGA BASE DE AVALIAÇÕES
        if with_context:
            database_ratings = MoviesDao.get_movies(True)
        else:
            database_ratings = MoviesDao.get_movies(False)

        # INICIALIZA AS VARIAVEIS DOS RESULTADOS
        result_total_hyb = Result(0, 0, 0, 0)
        result_total_fc = Result(0, 0, 0, 0)
        result_total_fbc = Result(0, 0, 0, 0)

        # PERCORRE CADA USUÁRIOS PARA CALCULAR OS MÉTODOS AVALIATIVOS
        for user_id in range(1, 11):
            print("AVALIANDO USUARIO: " + str(user_id))
            # GERA A RECOMENDAÇÃO POR MEIO DA FILTRAGEM COLABORATIVA PARA O USUARIO EM QUESTÃO
            result_fc = Recommender.recommender_collaborative(
                database_ratings, str(user_id))

            # INICIA A LISTA DE RECOMENDAÇÃO HIBRIDA
            result_hybrid = result_fc[0:fc_number]

            # RECUPERA AS AVALIAÇÕES REAIS DO USUÁRIO
            data_ratings = MoviesDao.get_user_ratings(str(user_id))

            # GERA A RECOMENDAÇÃO POR MEIO DA FILTRAGEM BASEADA EM CONTEÚDO
            data_movies = list(MoviesDao.get_all_movies())
            result_fbc = Recommender.recommender_content(
                result_hybrid, data_ratings, fbc_number, data_movies)

            # JUNTA OS RESULTADOS DA FC E FBC
            result_hybrid.extend(result_fbc)

            # DEFINE A LISTA DE RECOMENDAÇÃO FC LIMITADA A QUANTIDADE DE RECOMENDAÇÕES
            result_fc_analyze = self.incrementFC(result_hybrid, result_fc,
                                                 fc_number)

            # CALCULA AS MÉTRICAS AVALIATIVAS PARA CADA MODELO
            avaliation_hybrid = self.calculate_result(database_ratings,
                                                      user_id, result_hybrid,
                                                      "HIB")
            avaliation_fbc = self.calculate_result(database_ratings, user_id,
                                                   result_fbc, "FBC")
            avaliation_fc = self.calculate_result(database_ratings, user_id,
                                                  result_fc_analyze, "FC")

            # REALIZA A SOMA GERAL DAS MÉTRICAS
            result_total_hyb.increment(avaliation_hybrid)
            result_total_fc.increment(avaliation_fc)
            result_total_fbc.increment(avaliation_fbc)

        # APRESENTA OS RESULTADOS
        self.toString(result_total_hyb, "RSME")
        self.toString(result_total_fc, "FC")
        self.toString(result_total_fbc, "FBC")