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
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')
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")
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 review(request, workshop): player = request.user.get_profile() workshop = get_object_or_404(Workshop, pk=workshop) assessment = Assessment.get_for_player_and_workshop(player, workshop) if not assessment: return do_error(request, _('Cannot review an workshop you did not participate to.')) assessments = player.assessments_review.filter(workshop=workshop) if request.method == 'POST': answer = get_object_or_404(Answer, pk=request.GET.get('a')) review = Review.objects.get_or_create(reviewer=player, answer=answer)[0] review.feedback = request.POST['feedback_%d' % answer.id] review.answer_grade = request.POST['grade_%d' % answer.id] review.save() return render_to_response('workshop/review.html', {'assessment': assessment, 'workshop': workshop, 'assessments': assessments}, context_instance=RequestContext(request) )
def flush(): ndb.delete_multi(School.query().fetch(keys_only=True)) ndb.delete_multi(QuestionInstance.query().fetch(keys_only=True)) ndb.delete_multi(State_Questions.query().fetch(keys_only=True)) ndb.delete_multi(Topic_States.query().fetch(keys_only=True)) ndb.delete_multi(Question.query().fetch(keys_only=True)) ndb.delete_multi(State.query().fetch(keys_only=True)) ndb.delete_multi(Address.query().fetch(keys_only=True)) ndb.delete_multi(Teacher.query().fetch(keys_only=True)) ndb.delete_multi(Class.query().fetch(keys_only=True)) ndb.delete_multi(Assessment_Record.query().fetch(keys_only=True)) ndb.delete_multi(Student.query().fetch(keys_only=True)) ndb.delete_multi(UserInfo.query().fetch(keys_only=True)) ndb.delete _multi(Student_Assessments.query().fetch(keys_only=True)) ndb.delete_multi(Assessment.query().fetch(keys_only=True)) ndb.delete_multi(Subject.query().fetch(keys_only=True)) ndb.delete_multi(Topic_Questions.query().fetch(keys_only=True)) ndb.delete_multi(State_Questions.query().fetch(keys_only=True)) ndb.delete_multi(Topic_States.query().fetch(keys_only=True)) ndb.delete_multi(Subject_Topics.query().fetch(keys_only=True)) ndb.delete_multi(Student_Assessments.query().fetch(keys_only=True)) ndb.delete_multi(Topic.query().fetch(keys_only=True)) ndb.delete_multi(User.query().fetch(keys_only=True)) ndb.delete_multi(Assessment_Record.query().fetch(keys_only=True)) ndb.delete_multi(State_Types.query().fetch(keys_only=True))
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
def flush(): ndb.delete_multi(School.query().fetch(keys_only=True)) ndb.delete_multi(QuestionInstance.query().fetch(keys_only=True)) ndb.delete_multi(State_Questions.query().fetch(keys_only=True)) ndb.delete_multi(Topic_States.query().fetch(keys_only=True)) ndb.delete_multi(Question.query().fetch(keys_only=True)) ndb.delete_multi(State.query().fetch(keys_only=True)) ndb.delete_multi(Address.query().fetch(keys_only=True)) ndb.delete_multi(Teacher.query().fetch(keys_only=True)) ndb.delete_multi(Class.query().fetch(keys_only=True)) ndb.delete_multi(Assessment_Record.query().fetch(keys_only=True)) ndb.delete_multi(Student.query().fetch(keys_only=True)) ndb.delete_multi(UserInfo.query().fetch(keys_only=True)) ndb.delete_multi(Student_Assessments.query().fetch(keys_only=True)) ndb.delete_multi(Assessment.query().fetch(keys_only=True)) ndb.delete_multi(Subject.query().fetch(keys_only=True)) ndb.delete_multi(Topic_Questions.query().fetch(keys_only=True)) ndb.delete_multi(State_Questions.query().fetch(keys_only=True)) ndb.delete_multi(Topic_States.query().fetch(keys_only=True)) ndb.delete_multi(Subject_Topics.query().fetch(keys_only=True)) ndb.delete_multi(Student_Assessments.query().fetch(keys_only=True)) ndb.delete_multi(Topic.query().fetch(keys_only=True)) ndb.delete_multi(User.query().fetch(keys_only=True)) ndb.delete_multi(Assessment_Record.query().fetch(keys_only=True)) ndb.delete_multi(State_Types.query().fetch(keys_only=True))
def review(request, workshop): player = request.user.get_profile() workshop = get_object_or_404(Workshop, pk=workshop) assessment = Assessment.get_for_player_and_workshop(player, workshop) if not assessment: return do_error( request, _('Cannot review an workshop you did not participate to.')) assessments = player.assessments_review.filter(workshop=workshop) if request.method == 'POST': answer = get_object_or_404(Answer, pk=request.GET.get('a')) review = Review.objects.get_or_create(reviewer=player, answer=answer)[0] review.feedback = request.POST['feedback_%d' % answer.id] review.answer_grade = request.POST['grade_%d' % answer.id] review.save() return render_to_response('workshop/review.html', { 'assessment': assessment, 'workshop': workshop, 'assessments': assessments }, context_instance=RequestContext(request))
def get(self, id): assessment = Assessment.fetchone(id=id) return jsonify({ 'id': assessment.id, 'atitle': assessment.atitle, 'adescription': assessment.adescription, 'questions': assessment.questions, 'scores': assessment.scores })
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
def index(self): assessments = Assessment.fetchall() ret = [] for assessment in assessments: ret.append({ 'id': assessment.id, 'atitle': assessment.atitle, 'adescription': assessment.adescription, 'questions': assessment.questions, 'scores': assessment.scores }) return jsonify(sorted(ret, key=lambda i: i['id'], reverse=True))
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
def results(request, workshop): player = request.user.get_profile() workshop = get_object_or_404(Workshop, pk=workshop) assessment = Assessment.get_for_player_and_workshop(player, workshop) if not assessment: return do_error(request, _('Cannot view results for an workshop you did not participate to.')) return render_to_response('workshop/results.html', {'assessment': assessment, 'workshop': workshop}, context_instance=RequestContext(request) )
class AssessmentForm(ModelForm): rating_choices = zip(range(1, 11), range(1, 11)) total_rating = forms.ChoiceField(widget=forms.RadioSelect(), choices=rating_choices, help_text="") year_taken = forms.ChoiceField( widget=forms.Select(attrs={'class': 'chzn-select'}), choices=Assessment.get_year_choices()) class Meta: model = Assessment fields = [ 'total_rating', 'year_taken', ]
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)
def results(request, workshop): player = request.user.get_profile() workshop = get_object_or_404(Workshop, pk=workshop) assessment = Assessment.get_for_player_and_workshop(player, workshop) if not assessment: return do_error( request, _('Cannot view results for an workshop you did not participate to.' )) return render_to_response('workshop/results.html', { 'assessment': assessment, 'workshop': workshop }, context_instance=RequestContext(request))
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
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
def main() -> None: """Set up logging and call the reschedule function.""" args: Dict[str, str] = docopt(__doc__, version=__version__) # Set up logging log_level = args["--log-level"] try: logging.basicConfig(format="\n%(levelname)s: %(message)s", level=log_level.upper()) except ValueError: logging.critical( '"{}"is not a valid logging level. Possible values are debug, info, warning, and error.' .format(log_level)) sys.exit(1) try: with open(args["ASSESSMENT_FILE"]) as json_file: json_data = json.load(json_file) except EnvironmentError: logging.critical(f"JSON file not found: {args['ASSESSMENT_FILE']}") logging.critical("Please run command from the location with the file.") # Bandit complains about the input() function, but it is safe to # use in Python 3, which is required by this project. input("Press any key to close...") # nosec assessment = Assessment.parse(json_data) assessment = reschedule(assessment) with open(f"{assessment.id}-reschedule.json", "w") as fp: json.dump(assessment.as_dict(), fp, indent=4) logging.info(f"Assessment JSON ready: {assessment.id}-reschedule.json") # Stop logging and clean up logging.shutdown()
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()