Пример #1
0
def add_assessment(cleaned_main, cleaned_optional, subject): #user
    updates = {}
    assessment = Assessment()
    
    assessment.subject = subject
    assessment.total_rating = cleaned_main['total_rating']
    assessment.year_taken = cleaned_main['year_taken']
                
    updates['total_rating'] =  assessment.total_rating

    if cleaned_optional['difficulty']:
        if cleaned_optional['difficulty'] > 0:
            assessment.difficulty = cleaned_optional['difficulty']
            updates['difficulty'] = assessment.difficulty
    if cleaned_optional['time_demanding']:
        if cleaned_optional['time_demanding'] > 0:
            assessment.time_demanding = cleaned_optional['time_demanding']
            updates['time_demanding'] = assessment.time_demanding
    if cleaned_optional['lecture_quality']:
        assessment.lecture_quality = cleaned_optional['lecture_quality']
        updates['lecture_quality'] = assessment.lecture_quality
    if cleaned_optional['theory_vs_practice']:
        if cleaned_optional['theory_vs_practice'] > 0:
            assessment.theory_vs_practice = cleaned_optional['theory_vs_practice']
            updates['theory_vs_practice'] =  assessment.theory_vs_practice
    if cleaned_optional['comment']:
        assessment.comment = cleaned_optional['comment']
    assessment.subject.update_ratings(updates)
    subject.save()
    assessment.save()
Пример #2
0
def assessmentview(request, subject_id=None):
    assessment_id = None
    if assessment_id == None:
        assessment = Assessment()
    else:
        assessment = get_object_or_404(Assessment, pk=assessment_id)

    if subject_id != None:
        subject = get_object_or_404(Subject, pk=subject_id)

    if request.method == 'POST':
        form = AssessmentForm(request.POST, instance=assessment)
        optional_form = AssessmentOptionalForm(request.POST)
        if form.is_valid() and optional_form.is_valid():
            #TODO knytte bruker
            cleaned_main = form.cleaned_data
            cleaned_optional = optional_form.cleaned_data
            add_assessment(cleaned_main, cleaned_optional, subject)
            return redirect(subject_details, subject_id)
        else:
            messages.error(request, 'Invalid inputs')
            form = AssessmentForm(request.POST, auto_id=True)

    else:
        form = AssessmentForm(instance=assessment)
        optional_form = AssessmentOptionalForm()
    return render(request, 'assessmentview.html', {'form' : form, 'optional_form' : optional_form})
def send_assessment(request):
    if request.method != 'POST':
        return Http404
    requester = long(request.POST['requester'])
    assessment = long(request.POST['assess'])
    ass = Assessment(requester=requester, assess=assessment)
    ass.save()
    return HttpResponse('ok')
Пример #4
0
    def __hit_to_assessment(hit):

        index_id = hit['_id']
        query_id = iri_to_uri(hit['_source']['query_id'])
        assessor = iri_to_uri(hit['_source']['assessor'])
        document = iri_to_uri(hit['_source']['document'])
        grade = iri_to_uri(hit['_source']['grade'])

        assessment = Assessment(index_id, query_id, assessor, document, grade)

        return assessment
Пример #5
0
 def post(self):
     """Create new assessment"""
     atitle = request.get_json()['atitle']
     adescription = request.get_json()['adescription']
     questions = request.get_json()['questions']
     scores = request.get_json()['scores']
     new_assessment = Assessment(atitle=atitle,
                                 adescription=adescription,
                                 questions=questions,
                                 scores=scores)
     try:
         new_assessment.save()
     except UniqueViolatedError:
         return jsonify(error="Duplicated assessment title"), 409
     return jsonify(message="ok")
Пример #6
0
def __store_to_es():
    doc_size = int(request.form['doc_size']) + 1
    assessment_list = []

    for i in range(1, doc_size):
        index_id = request.form['index_id_' + str(i)]
        query_id = request.form['query_id_' + str(i)]
        assessor = request.form['assessor_' + str(i)]
        document = request.form['document_' + str(i)]
        grade = int(request.form['grade_' + str(i)])

        assessment = Assessment(index_id, query_id, assessor, document, grade)

        assessment_list.append(assessment)

    service = Service()
    service.store_assessment(assessment_list)
Пример #7
0
 def save(self, commit=True):
     newassessment = Assessment(begindate=self.cleaned_data['begindate'],
                                enddate=self.cleaned_data['enddate'],
                                term=self.cleaned_data['term'],
                                excellent=self.cleaned_data['excellent'],
                                good=self.cleaned_data['good'],
                                ordinary=self.cleaned_data['ordinary'])
     if commit:
         newassessment.save()
     #产生行评价记录,后续考虑性能优化
     for i in Class.objects.all():
         for student in i.student_set.all():
             newassessmentRow = AssessmentRow(assessment=newassessment,
                                              student=student,
                                              excellent=0,
                                              good=0,
                                              ordinary=0)
             newassessmentRow.save()
     return newassessment
Пример #8
0
def getAllAssessments(assessed_vkid: str):
    """
  Получить все оценки оцененного пользователя

  return: [Assessment, ...] все оценки, если есть, иначе None
  """
    with sqlite3.connect(databaseName) as db:
        cursor.execute(
            "SELECT * FROM assessments \
        WHERE assessed_user = (?)", (assessed_vkid, ))
        rows = cursor.fetchall()
        if rows is not None:
            list_of_assessment = list()
            for row in rows:
                rowDict = dict(
                    zip([column[0] for column in cursor.description], row))
                list_of_assessment.append(Assessment(rowDict))
            return list_of_assessment
    return None
Пример #9
0
def getAssessment(vkid: str, assessed_vkid: str):
    """
  Получить существующую оценку

  return: Assesment, если такая оценка есть, иначе None
  """
    with sqlite3.connect(databaseName) as db:
        cursor.execute(
            "SELECT * FROM assessments \
        WHERE user = (?) AND assessed_user = (?)", (vkid, assessed_vkid))
        row = cursor.fetchone()
        if row is not None:
            """
      cursor.description возвращает имена столбцов из последнего запроса.
      он возвращает кортеж из 7 значений, где последние 6 = None.
      на нулевой позиции лежит название столбца, поэтому его и используем для
      формирования словаря.
      """
            rowDict = dict(
                zip([column[0] for column in cursor.description], row))
            assessment = Assessment(rowDict)
            return assessment
    return None
Пример #10
0
 def save(self,commit=True):
     newassessment = Assessment(begindate=self.cleaned_data['begindate'],\
         enddate=self.cleaned_data['enddate'],term=self.cleaned_data['term'],\
         excellent=self.cleaned_data['excellent'],good=self.cleaned_data['good'],\
         ordinary=self.cleaned_data['ordinary'])
     if commit:
         newassessment.save()
     #generate the records
     for i in Class.objects.all():
         for student in i.student_set.all():
             for exstudent in i.student_set.all():
                 newAssessmentRecord = AssessmentRecord(assessment=newassessment,\
                     ostudent=student,dstudent=exstudent,\
                     result='3')#'3'------>'无'
                 newAssessmentRecord.save()
     
     #generate rows
     for i in Class.objects.all():
         for student in i.student_set.all():
             newAssessmentRow = AssessmentRow(assessment=newassessment,student=student,\
                 excellent=0,good=0,ordinary=0)
             newAssessmentRow.save()
     return newassessment