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)
def set_group_type(self, o_question: GS_Outline_Question): question_type = o_question.data.get("type") q = o_question.get_gs_question() q_type = GroupTypes.complex if question_type in ["select_all", "multiple_choice"]: q_type = GroupTypes.mc # if question_type in ["long_answer", "long_code_answer"]: # q_type = GroupTypes.non_grouped return q.set_group_type(q_type)
def question_to_gso_question(self, grader: GS_assignment_Grader, page, question: dict) -> GS_Outline_Question: weight = question.get("points") if not weight: weight = 0 return GS_Outline_Question( grader, None, [self.get_gs_crop_info(page, question=question)], title=question.get("name", ""), weight=weight, )