Пример #1
0
    def generate_gs_outline(self, grader: GS_assignment_Grader,
                            exam_json: dict, id_question_ids: [str]):
        gs_number_to_exam_q = {}
        questions = []

        page = 2  # Page 1 is an info page

        qid = 1
        if exam_json.get("public"):
            prev_page = 1
            pg = GS_Outline_Question(
                grader,
                None,
                [self.get_gs_crop_info(page, exam_json.get("public"))],
                title="Public",
                weight=0,
            )
            sqid = 1
            for question in extract_public(exam_json):
                question_id = question.get("id")
                if question_id in id_question_ids:
                    print(f"Skipping {question_id} as it is an id question.")
                    page += 1  # Still need to increment this as it is still on the exam pdf.
                    continue
                pg.add_child(
                    self.question_to_gso_question(grader, page, question))
                gs_number_to_exam_q[f"{qid}.{sqid}"] = question
                sqid += 1
                page += 1
            if page != prev_page and len(pg.children) > 0:
                questions.append(pg)
                qid += 1

        for group in extract_groups(exam_json):
            prev_page = page
            weight = group.get("points", "0")
            if not weight:
                weight = 0
            g = GS_Outline_Question(
                grader,
                None,
                [self.get_gs_crop_info(page, group)],
                title=group.get("name", ""),
                weight=weight,
            )
            sqid = 1
            for question in extract_questions(group,
                                              extract_public_bool=False,
                                              top_level=False):
                g.add_child(
                    self.question_to_gso_question(grader, page, question))
                gs_number_to_exam_q[f"{qid}.{sqid}"] = question
                sqid += 1
                page += 1
            if page != prev_page:
                questions.append(g)
                qid += 1

        outline = GS_Outline(self.name_region, self.sid_region, questions)
        return (gs_number_to_exam_q, outline)
Пример #2
0
 def set_group_types(self, outline: GS_Outline, debug=True):
     questions = list(outline.questions_iterator())
     with std_out_err_redirect_tqdm() as orig_stdout:
         for qid, question in tqdm(
             questions, file=orig_stdout, unit="Question", **def_tqdm_args
         ):
             self.set_group_type(question)
Пример #3
0
    def set_group_types(self, outline: GS_Outline, debug=True):
        questions = list(outline.questions_iterator())
        with std_out_err_redirect_tqdm() as orig_stdout:
            # for qid, question in tqdm(
            #     questions, file=orig_stdout, unit="Question", **def_tqdm_args
            # ):
            #     self.set_group_type(question)
            def sgt(q):
                qid, question = q
                self.set_group_type(question)

            with ThreadPool(self.simultaneous_jobs) as p:
                list(
                    tqdm(
                        p.imap_unordered(sgt, questions),
                        total=len(questions),
                        file=orig_stdout,
                        unit="Question",
                        **def_tqdm_args,
                    ))
Пример #4
0
 def merge_gs_outline_ids(self, outline: GS_Outline):
     self.gs_outline = outline
     for qnum, q in outline.questions_iterator():
         q.data = self.gs_number_to_exam_q[qnum]