Пример #1
0
def Subject_Score(url_Subject_id, url_Year, url_user_id):
    g.SubjectID = url_Subject_id
    g.year = url_Year
    g.UserID = url_user_id
    g.user = User(g.UserID)
    subject = Subject(g.SubjectID, g.year)
    subjectWork = sorted(subject.get_work(), key=itemgetter(2))
    g.work = []
    g.all_user_ID = []
    g.score = []
    if g.user.Profile['Role'] == 'teacher':
        g.workID = []
        connect = sqlite3.connect("Data.db")
        c = connect.cursor()
        all_user_ID = c.execute(
            "SELECT ID FROM Enrol WHERE Subject_ID = ? AND  subject_Year = ?",
            (g.SubjectID, g.year))
        all_user_ID = all_user_ID.fetchall()
        all_user_ID = sorted([x[0] for x in all_user_ID])
        for x in all_user_ID:
            if str(x) != str(g.UserID):
                g.all_user_ID.append(x)
        c.close()
        for x in subjectWork:
            for selectUser in g.all_user_ID:
                try:
                    submitwork = submitWork(x[2], g.year, g.SubjectID,
                                            selectUser)
                    address = submitwork.Address

                except Exception:
                    address = None
                work = Work(g.SubjectID, g.year, x[2])
                g.work.append([selectUser, x[2], address, work.Fullmark])
                if submitwork.Mark != 0:
                    g.score.append(
                        [selectUser, g.SubjectID, x[2], submitwork.Mark])
                else:
                    g.score.append([selectUser, g.SubjectID, x[2], [
                        0,
                    ]])
                if [x[2], work.Fullmark] not in g.workID:
                    g.workID.append([x[2], work.Fullmark])
        print g.workID
        return render_template("Score2.html")

    else:
        for x in subjectWork:
            submitwork = submitWork(x[2], g.year, g.SubjectID, g.UserID)
            work = Work(g.SubjectID, g.year, x[2])
            if submitwork.Get_Mark() == 0:
                g.work.append([x[2], [
                    submitwork.Mark,
                ], work.Fullmark])
            else:
                g.work.append([x[2], submitwork.Mark, work.Fullmark])
        g.workID = [x[0] for x in g.work]
        return render_template("Score2.html")
Пример #2
0
def CurrentScore(url_user_id):
    year = datetime.date.today()
    if year.month <= 4:
        year = int(str(year.year + 542)[0:4])
    else:
        year = int(str(year.year + 543)[0:4])

    g.id = url_user_id
    g.user = User(g.id)
    # get subject
    g.subject = []
    g.work = []
    g.fullmark = []
    g.subject_list = g.user.Subject['current']
    g.subject_list = sorted(g.subject_list)
    g.total_mark = []
    for subject in g.subject_list:
        total = 0
        full_total = 0
        # g.subject.append(subject.get_work())
        for work in sorted(subject.get_work(), key=itemgetter(2)):
            fullmark = Work(work[0], year, work[2])
            if work[0] not in g.subject:
                # get subject id 1 time / 1 subject
                g.subject.append(work[0])
            try:
                position = work[2]
                workID = work[0]
                work = submitWork(work[2], year, work[0], g.id)
                total = total + int(work.Get_Mark()[0])
                g.work.append([
                    workID, position,
                    work.Get_Mark(),
                    fullmark.Get_fullmark()
                ])
            except Exception:
                g.work.append(
                    [workID, position, [
                        0,
                    ], fullmark.Get_fullmark()])
                total = total + 0
            full_total = full_total + fullmark.Get_fullmark()
        g.total_mark.append([subject.Subject_Id, int(total), int(full_total)])
    # create a being that process data (go get filter etc.)
    g.subject = sorted(g.subject)
    return render_template('Score.html')
Пример #3
0
def Subject_Score(url_Subject_id, url_Year, url_user_id):
    g.SubjectID = url_Subject_id
    g.year = url_Year
    g.UserID = url_user_id
    g.user = User(g.UserID)
    subject = Subject(g.SubjectID, g.year)
    subjectWork = subject.get_work()
    g.work = []
    g.all_user_ID = []
    if g.user.Profile['Role'] == 'teacher':
        g.workID = []
        connect = sqlite3.connect("Data.db")
        c = connect.cursor()
        all_user_ID = c.execute(
            "SELECT ID FROM Enrol WHERE Subject_ID = ? AND  subject_Year = ?",
            (g.SubjectID, g.year))
        all_user_ID = all_user_ID.fetchall()
        for x in all_user_ID:
            if str(x[0]) != str(g.UserID):
                g.all_user_ID.append(x[0])
        c.close()
        for x in subjectWork:
            for selectUser in g.all_user_ID:
                submitwork = submitWork(x[2], g.year, g.SubjectID, selectUser)
                work = Work(g.SubjectID, g.year, x[2])
                g.work.append(
                    [selectUser, x[2], submitwork.Mark, work.Fullmark])
                if [x[2], work.Fullmark] not in g.workID:
                    g.workID.append([x[2], work.Fullmark])

        return render_template("Score2.html")

    else:
        for x in subjectWork:
            submitwork = submitWork(x[2], g.year, g.SubjectID, g.UserID)
            work = Work(g.SubjectID, g.year, x[2])
            g.work.append([x[2], submitwork.Mark, work.Fullmark])
        return render_template("Score2.html")
Пример #4
0
def insert_mark(url_Subject_id, url_Year, url_user_id):
    conn = sqlite3.connect('Data.db')  # connect Data.db
    c = conn.cursor()
    id_from_form = request.values.get('id')
    score_from_form = request.values.get('score')
    subject_id_from_form = url_Subject_id
    year_from_form = url_Year
    work_id_from_form = request.values.get('work_id')
    print id_from_form
    print score_from_form
    print work_id_from_form
    fullMark = Work(subject_id_from_form, year_from_form, work_id_from_form)
    print id_from_form
    print score_from_form
    # print
    submit = c.execute(
        "SELECT Status FROM SubmitWork WHERE Subject_ID = ? AND Year = ? AND WorkID = ? AND ID = ?",
        (subject_id_from_form, year_from_form, work_id_from_form,
         id_from_form))
    submit = submit.fetchone()
    print submit
    if int(score_from_form) <= int(fullMark.Fullmark):
        if submit != None:
            c.execute(
                "UPDATE SubmitWork SET Mark = ? WHERE Subject_ID = ? AND Year = ? AND ID = ? AND WorkID = ? ",
                (score_from_form, subject_id_from_form, year_from_form,
                 id_from_form, work_id_from_form))
        else:

            c.execute(
                """INSERT INTO `SubmitWork` (`Subject_ID`, `Year`, `WorkID`, `ID`, `Address`, `Status`, `Mark`) VALUES
                   (?,?,?,?,?,?,?);""",
                (subject_id_from_form, year_from_form, work_id_from_form,
                 id_from_form, 'http://google.com', 'sent', score_from_form))

    conn.commit()
    c.close()
    return jsonify(authen=True)
Пример #5
0
def Subject_work_score(url_Subject_id, url_Year, url_user_id, work_id):
    g.work_id = work_id
    connect = sqlite3.connect('Data.db')
    g.id = url_user_id
    c = connect.cursor()
    g.user = User(url_user_id)
    g.Subject_id = url_Subject_id
    g.Year = url_Year
    g.work = Work(g.Subject_id, g.Year, g.work_id)
    g.group_user = []
    if g.user.Profile['Role'] == 'teacher':
        ID_student = c.execute(
            "SELECT ID from Enrol WHERE  Subject_ID =  ? AND Subject_Year = ?",
            (url_Subject_id, url_Year))
        g.student1 = []
        g.student2 = []
        g.student3 = []
        g.single_score = []
        g.group_user = []
        ID_student1 = ID_student.fetchall()

        # find group_limit
        group_limit = c.execute(
            "SELECT lim_member from Work WHERE Subject_ID =  ? AND Year = ? AND WorkID = ?",
            (url_Subject_id, url_Year, g.work_id))
        g.group_limit = group_limit.fetchone()[0]

        for row in ID_student1:

            sudent = User(str(row[0]))

            if sudent.Profile['Role'] == 'student':
                NAME_student = c.execute(
                    "SELECT ID,Name from User WHERE  ID =" + str(row[0]))
                NAME_student = NAME_student.fetchall()

                # non group work
                single_score_student = c.execute(
                    "SELECT Mark from SubMitWork WHERE  ID = ? AND Subject_ID = ? AND WorkID = ?",
                    (str(row[0]), url_Subject_id, g.work_id))
                single_score_student = single_score_student.fetchall()
                # ID_student = ID_student.fetchall()
                try:
                    g.single_score.append(str(single_score_student[0][0]))
                except Exception:
                    g.single_score.append(0)
                g.student1.append(str(NAME_student[0][1]))
                g.student2.append(str(row[0]))

                # group work

                group_ID_student = c.execute(
                    "SELECT WorkID, ID, Group_ID from Groups WHERE ID = ? AND Subject_ID = ? AND Year = ? AND WorkID = ?",
                    (str(row[0]), g.Subject_id, g.Year, g.work_id))
                group_ID_student = group_ID_student.fetchone()

                print group_ID_student
                if group_ID_student != None:
                    user_group_score = c.execute(
                        "SELECT Mark from SubmitWork WHERE ID = ? AND WorkID = ? AND Subject_ID = ? AND Year = ?",
                        (str(group_ID_student[1]), str(
                            group_ID_student[0]), g.Subject_id, g.Year))
                    user_group_score = user_group_score.fetchone()
                    if user_group_score != None:
                        user_group_score = user_group_score[0]
                    else:
                        user_group_score = 0
                    g.group_user.append([
                        group_ID_student[2], group_ID_student[1],
                        NAME_student[0][1], user_group_score
                    ])
        g.a = range(len(g.student2))
        g.b = range(len(g.group_user))
        c.close()
        return render_template("score1.html", std2=map(json.dumps, g.student2))
    else:
        g.score = c.execute(
            "SELECT * from SubmitWork WHERE  Subject_ID =  ? AND Year = ? AND ID = ? AND WorkID = ?",
            (url_Subject_id, url_Year, url_user_id, work_id))
        g.score = g.score.fetchone()
        if g.score != None:
            if g.score[6] != None:
                g.score = g.score[6]
            else:
                g.score = 0
        else:
            g.score = 0
        print g.group_user
        c.close()

        return render_template("score1.html")