def get_csv_statistics_export(statistics_info, current_user: User) -> Export: current_date = get_current_date() filename = ('statystykiCSV' + get_formatted_date(current_date) + '.csv').replace(" ", "_") with open(os.path.join(current_user.get_directory(), filename), 'w', newline='') as csv_file: csv_writer = csv.writer(csv_file, delimiter='|', quoting=csv.QUOTE_MINIMAL) statistics: List[Statistics] = Statistics.get_statistics_by_ids( statistics_info) for statistic in statistics: csv_writer.writerow([statistic.university_id] + [statistic.course_name] + [statistic.user_points] + [statistic.course_points] + [str(statistic.get_percent_value()) + '%']) for student_exercise in statistic.student_exercises: csv_writer.writerow( [student_exercise.exercise.lesson.name] + [student_exercise.exercise.name] + [student_exercise.points] + [student_exercise.max_points] + [str(student_exercise.get_percent_value()) + '%']) csv_writer.writerow('') export = Export(user_id=current_user.id, file_name=filename, generation_date=current_date, type=Export.types['CSV'], format=Export.formats['STATISTICS']) db.session.add(export) db.session.commit() return export
def get_csv_solution_export(solutions: List[Solution], current_user: User) -> Export: current_date = get_current_date() filename = ('rozwiazaniaCSV' + get_formatted_date(current_date) + '.csv').replace(" ", "_") with open(os.path.join(current_user.get_directory(), filename), 'w', newline='') as csv_file: csv_writer = csv.writer(csv_file, delimiter='|', quoting=csv.QUOTE_MINIMAL) for solution in solutions: csv_writer.writerow([solution.author.university_id] + [solution.get_course().name] + [solution.get_lesson().name] + [solution.exercise.name] + [solution.get_str_send_date()] + [solution.points] + [solution.status]) export = Export(user_id=current_user.id, file_name=filename, generation_date=current_date, type=Export.types['CSV'], format=Export.formats['SOLUTION']) db.session.add(export) db.session.commit() return export
def can_send_solution(exercise: Exercise, sorted_solutions: List[Solution]) -> bool: solutions_amount = len(sorted_solutions) if exercise.is_finished() or solutions_amount >= exercise.max_attempts: return False if solutions_amount == 0: return True else: last_solution = sorted_solutions[0] second_difference = (get_current_date() - get_offset_aware(last_solution.send_date)).seconds return second_difference > last_solution.exercise.interval
def create_test(self, input_file, output_file, timeout, points): input_name, output_name = secure_filename(input_file.filename), secure_filename(output_file.filename) test = Test(points=points, input_name=input_name, output_name=output_name, exercise_id=self.id, timeout=timeout, create_date=get_current_date()) self.tests.append(test) db.session.commit() test_directory = test.get_directory() create_directory(test_directory) input_file.save(os.path.join(test_directory, input_name)) output_file.save(os.path.join(test_directory, output_name))
def get_pdf_statistics_export(statistics_info, current_user: Teacher) -> Export: current_date = get_current_date() filename = ('statystykiPDF' + get_formatted_date(current_date) + '.pdf').replace(" ", "_") global_filename = os.path.join(current_user.get_directory(), filename) create_statistic_pdf(statistics_info, global_filename) export = Export(user_id=current_user.id, file_name=filename, generation_date=current_date, type=Export.types['PDF'], format=Export.formats['STATISTICS']) db.session.add(export) db.session.commit() return export
def get_pdf_solution_export(solutions: List[Solution], current_user: User) -> Export: current_date = get_current_date() filename = ('rozwiazaniaPDF' + get_formatted_date(current_date) + '.pdf').replace(" ", "_") global_filename = os.path.join(current_user.get_directory(), filename) create_solutions_pdf(solutions, global_filename) export = Export(user_id=current_user.id, file_name=filename, generation_date=current_date, type=Export.types['PDF'], format=Export.formats['SOLUTION']) db.session.add(export) db.session.commit() return export
def add_solution(exercise: Exercise, member: Member, file: FileStorage, ip_address: str, attempt_nr: int, os_info: str): filename = secure_filename(file.filename) solution = Solution(filename=filename, ip_address=ip_address, send_date=get_current_date(), os_info=os_info, attempt=attempt_nr) exercise.solutions.append(solution) member.solutions.append(solution) solution_directory = solution.get_directory() create_directory(solution_directory) file.save(join(solution_directory, solution.filename)) unpack_file(solution.filename, solution_directory) db.session.commit() solution.enqueue_execution()
def is_finished(self): return get_current_date() > get_offset_aware(self.end_date)