Ejemplo n.º 1
0
def do_process(data):
    date = datetime.strptime(data['jdate'], '%Y-%m-%d').date()
    data['result'], data['attendance'] = {data['exam']: []}, {}
    exam = db.read('exams', data['exam'])['data'][0]['data']
    marks = int(len(exam) - int(data['marks']) / 100 * len(exam))
    for x in exam:
        i = random.randint(0, 3)
        x['choices']['wrong'].insert(i, x['choices']['correct'])
        data['result'][data['exam']].append({
            "que": x['que'],
            "choices": x['choices']['wrong'],
            "user_choice_index": i,
            "correct_choice_index": i
        })

    while marks != 0:
        i = random.randint(0, len(data['result'][data['exam']]) - 1)
        popdata = data['result'][data['exam']].pop(i)
        if popdata['user_choice_index'] != 0: popdata['user_choice_index'] -= 1
        else: popdata['user_choice_index'] += 1
        data['result'][data['exam']].insert(i, popdata)
        marks -= 1

    data['result'][data['exam']] = json.dumps(data['result'][data['exam']])
    print(datetime.strptime(data['edate'], '%Y-%m-%d').date(), date)
    while datetime.strptime(data['edate'], '%Y-%m-%d').date() > date:
        if date.weekday() != 6:
            data['attendance'][date.strftime('%Y-%m-%d')] = "Present"
            date += timedelta(days=1)
        else:
            date += timedelta(days=1)
    return data
Ejemplo n.º 2
0
def admin_exam(req=None):
  if req is not None:
      return db.read('exams',request.args['name'])['data'][0]
  else:
    if request.method == "POST":
        db.write("exams",request.form['name'],{"data":[]})
        return render_template('admin_exam.html',qut=qt.random(),exams=db.status())
    return render_template('admin_exam.html',qut=qt.random(),exams=db.status())
Ejemplo n.º 3
0
def public_doexam():
    data = db.filter('students', {'id': request.form['id']})['data']
    if len(data):
        return render_template(
            'exam.html',
            data=data[0],
            que=json.dumps(
                db.read('exams', request.form['paper'])['data'][0]['data']),
            unid=data[0]['unid'],
            exam=request.form['paper'])
    else:
        return render_template('examlogin.html',
                               exams=db.status()['exams'],
                               msg='Student ID Incorrect!')
Ejemplo n.º 4
0
def admin_result():
    if request.method == "POST":
        print(db.filter("students",request.form)['data'][0])
        return db.filter("students",request.form)['data'][0]
    else:return render_template('admin_results.html',qut=qt.random(),students = db.read("students"))
Ejemplo n.º 5
0
def admin_delstudent(unid):
    db.trash('students',where={"unid":unid})
    return render_template('admin_results.html',qut=qt.random(),students = db.read("students"))
Ejemplo n.º 6
0
def admin_index():
    return render_template('admin_index.html',qut=qt.random(),students=len(db.read('students')['data']))
Ejemplo n.º 7
0
def logoutfd(col):
 return str(db.read(col))
Ejemplo n.º 8
0
def admin_attendance():
    if request.method == 'POST':
        if request.form['status'] == 'end':
            db.update("students",{'end':request.form['date']},where={'unid':request.form['unid']})
            return "Student Session Ended!"
        else:
            db.update("students",{'attendance':{request.form['date']:request.form['status']}},where={'unid':request.form['unid']})
            return "Absent Marked!"
    elif request.method == 'GET':return render_template('admin_attendance.html',qut=qt.random(),students = db.read("students"))