Ejemplo n.º 1
0
def get_next_application():
    id = Judge.getJudgeIdByToken()
    needs_new_judgement = True
    app = None

    #Get current application being judged
    current = Judgement.getCurrentJudgementByJudgeId(id)
    if current:
        app_id = current.app_id
        app = Application.query.filter_by(id=app_id).first()
        needs_new_judgement = app.state != 'tbd'

    if needs_new_judgement:
        judge_judgements = Judgement.query.filter_by(judge_id=id).all()
        apps_judged = set([judge_judgement.app_id for judge_judgement in judge_judgements])
        apps_all = set([application[0] for application in Application.query.filter_by(state='tbd').values('id')])
        apps_missing = apps_all - apps_judged
        if not apps_missing:
            return {'status':'everyone_judged'}
        app_id = random.sample(apps_missing,1)[0]
        newJudgement = Judgement(app_id=app_id, judge_id=id)
        newJudgement.judge_index = len(judge_judgements)
        newJudgement.rating = ''
        db.session.add(newJudgement)
        db.session.commit()
        app = Application.query.filter_by(id=app_id).first()

    if app is not None:
        return app.to_dict()
    else:
        return {}
Ejemplo n.º 2
0
 def find(type, problem_id):
     if type == 'SingleChoice':
         problem = SingleChoice.find(problem_id)
     elif type == 'MultipleChoice':
         problem = MultipleChoice.find(problem_id)
     elif type == 'Judgement':
         problem = Judgement.find(problem_id)
     return problem
Ejemplo n.º 3
0
 def delete(type, id):
     if type == 'SingleChoice':
         obj = SingleChoice.find(id).delete()
     elif type == 'MultipleChoice':
         obj = MultipleChoice.find(id).delete()
     elif type == 'Judgement':
         obj = Judgement.find(id).delete()
     return obj
Ejemplo n.º 4
0
 def find_all(**kwargs):
     problems = {}
     single_choice = SingleChoice.find_all(**kwargs)
     multiple_choice = MultipleChoice.find_all(**kwargs)
     judgement = Judgement.find_all(**kwargs)
     problems["SingleChoice"] = getDistListFromObjectList(single_choice)
     problems["MultipleChoice"] = getDistListFromObjectList(multiple_choice)
     problems["Judgement"] = getDistListFromObjectList(judgement)
     return problems
Ejemplo n.º 5
0
 def all():
     problems = []
     single_choice = SingleChoice.all()
     multiple_choice = MultipleChoice.all()
     judgement = Judgement.all()
     problems.extend(getDistListFromObjectList(single_choice))
     problems.extend(getDistListFromObjectList(multiple_choice))
     problems.extend(getDistListFromObjectList(judgement))
     return problems
Ejemplo n.º 6
0
def rate_application(rating):
    id = Judge.getJudgeIdByToken()
    judgement = Judgement.getCurrentJudgementByJudgeId(id)

    if judgement is None:
        return {"status": "ko"}

    judgement.rating = rating
    db.session.commit()

    return {"status": "ok"}
Ejemplo n.º 7
0
 def upsert(form):
     type = form.get('type')
     options = {}
     options['A'] = form.get('A', '')
     options['B'] = form.get('B', '')
     options['C'] = form.get('C', '')
     options['D'] = form.get('D', '')
     query_form = {'id': int(form.get('id', -1))}
     if type == 'SingleChoice':
         update_form = dict(
             subject_id=int(form.get('subject_id')),
             chapter_id=int(form.get('chapter_id')),
             type=form.get('type'),
             topic=form.get('topic'),
             options=options,
             answer=form.get('answer'),
             analysis=form.get('analysis', ''),
         )
         problem = SingleChoice.upsert(query_form, update_form)
     elif type == 'MultipleChoice':
         update_form = dict(
             subject_id=int(form.get('subject_id')),
             chapter_id=int(form.get('chapter_id')),
             type=form.get('type'),
             topic=form.get('topic'),
             options=options,
             answer=form.get('answer'),
             analysis=form.get('analysis', ''),
         )
         problem = MultipleChoice.upsert(query_form, update_form)
     elif type == 'Judgement':
         if form.get('answer') == 'true':
             answer = True
         else:
             answer = False
         update_form = dict(
             subject_id=int(form.get('subject_id')),
             chapter_id=int(form.get('chapter_id')),
             type=form.get('type'),
             topic=form.get('topic'),
             answer=answer,
             analysis=form.get('analysis', ''),
         )
         problem = Judgement.upsert(query_form, update_form)
     return problem