whaleprep/scripts/examgoal_model/chapter.py
dev ff1c23eaec Vendor examgoal unpickle models, portable pickle path
import_examgoal.py required /tmp/pyqeval helper modules that were never
committed, so it failed on any fresh machine. The two upstream model
files now live in scripts/examgoal_model/ (relative import fixed) and
the default pickle path is scripts/examgoal_db.pkl.
2026-10-12 20:34:50 +05:30

41 lines
No EOL
1.2 KiB
Python

"""
This file has the Chapter class
"""
import json
from question import Question
class Chapter:
"""Abstraction for chapter"""
def __repr__(self)->str:
template = f"""
Parent Subject:{self.parent_subject}
Name:{self.name}
Question Dict: {self.question_dict_status}
Total Questions:{self.total_questions}
"""
return template
def __init__(self,chapter_path)->None:
"""Initialization of Chapter
:param:
chapter_path: Path to chpaters json file , recommended to use absolute path
"""
chapter_file = open(chapter_path,"r")
chapter_json = json.load(chapter_file)
chapter_file.close()
parent_subject = chapter_json["results"][0]["title"]
question_dict = dict()
counter = 0
for question_json in chapter_json["results"][0]["questions"]:
question = Question(question_json)
question_dict[counter] = question
counter += 1
self.parent_subject = parent_subject
self.name = chapter_json["results"][0]["questions"][0]["chapter"]
self.question_dict = question_dict
self.question_dict_status = "healthy"
self.total_questions = len(question_dict)