pir_pipeline.utils.dashboard_utils.QuestionLinker

class pir_pipeline.utils.dashboard_utils.QuestionLinker(data: list[dict], db: SQLAlchemyUtils, log: bool = True)

Bases: object

QuestionLinker class to handle linking and unlinking of questions

__init__(data: list[dict], db: SQLAlchemyUtils, log: bool = True)

QuestionLinker object to handle linking and unlinking of questions

Args:
data (dict): A series of instructions for linking/unlinking questions.

Should be of the form: [

{

“link_type”: link or unlink, “base_question_id”: qid_1, “base_uqid”: uqid_1, “match_question_id”: qid_2, “match_uqid”: uqid_2

{

…

}

]

db (SQLAlchemyUtils): SQLAlchemyUtils object for database interactions log (bool): Boolean to determin whether to write to changelog. Defaults to True.

Methods

__init__(data, db[, log])

QuestionLinker object to handle linking and unlinking of questions

confirm()

Mark a question as confirmed

get_ids()

Return the ids from the present record.

link()

Link two questions

log(changes)

unlink()

Unlink a question (or a single question-year) from its group.

update_links()

Update links

confirm()

Mark a question as confirmed

get_ids()

Return the ids from the present record.

When the record carries a base_year/match_year, the uqid lookup is narrowed to that (question_id, year) row. This matters under a question_id collision, where the same question_id can sit under different uqids across years and a lookup by question_id alone would return an arbitrary one.

Link two questions

Unlink a question (or a single question-year) from its group.

When the record carries a match_year the peel targets only that (question_id, year) row; otherwise every year of match_qid is peeled out (the prior whole-question behavior). A peeled set of one row becomes unlinked (uqid None); a multi-row set stays together under a fresh uqid. The group being unlinked from is dissolved if a single row is left behind, since a uqid should never group a lone question-year.

Update links

Makes calls to QuestionLinker.link and QuestionLinker.unlink as needed