

def format_student_records(input_q, input_pid, target):
    formatted_records = []
    for i in range(len(input_q)):
        student_record = []
        for t in range(len(input_q[i])):
            qid = input_pid[i][t]
            cid = input_q[i][t]
            correct = target[i][t]
            status = "correctly" if correct == 1 else "incorrectly"
            if qid !=0:
                student_record.append(
                    f"The student has answered question QID={qid} involving concept CID={cid} {status} at timestep {t}.[ITEM]"
                )
            else:
                student_record.append(
                    "[None]"
                )
        formatted_records.append(student_record)
    return formatted_records

def format_student_query(input_q, input_pid):
    formatted_records = []
    for i in range(len(input_q)):
        student_record = []
        for t in range(len(input_q[i])):
            qid = input_pid[i][t]
            cid = input_q[i][t]
            if qid !=0:
                student_record.append(
                    f"Judge the student can answer question QID={qid} involving concept CID={cid} correctly or not.[ITEM]"
                )
            else:
                student_record.append(
                    "[None]"
                )
        formatted_records.append(student_record)
    return formatted_records



def format_student_data(student_ids, question_ids, concept_ids, correctness):
    formatted_data = []
    for i, student_id in enumerate(student_ids):
        student_data = []
        for t, (qid, cid, correct) in enumerate(zip(question_ids[i], concept_ids[i], correctness[i])):
            status = "correctly" if correct == 1 else "incorrectly"
            student_data.append(
                f"The student has previously, in chronological order, answered question QID={qid} involving concept CID={cid} {status} at timestep {t}."
            )
        formatted_data.append(student_data)
    return formatted_data

def main():
    # 示例数据
    student_ids = [1274, 82295]
    question_ids = [
        [1366, 1366, 1424, 1424, 1413, 1413, 2985, 2976, 2993, 2975],
        [1366, 1366, 1424, 1424, 1413, 1413, 2985, 2976, 2993, 2975]
    ]
    concept_ids = [
        [7, 9, 7, 9, 7, 9, 15, 15, 15, 15],
        [7, 9, 7, 9, 7, 9, 15, 15, 15, 15]
    ]
    correctness = [
        [1, 1, 0, 0, 1, 1, 0, 1, 1, 1],
        [1, 1, 0, 0, 1, 1, 0, 1, 1, 1]
    ]

    # 格式化数据
    formatted_data = format_student_data(student_ids, question_ids, concept_ids, correctness)

    # 打印格式化数据
    for student_data in formatted_data:
        for data in student_data:
            print(data)

if __name__ == "__main__":
    # 示例数据
    input_q = [
        [7, 9, 7, 9, 7, 9, 15, 15, 15, 15, 7, 9, 7, 9, 7, 9, 15, 15, 15, 15, 7, 9, 7, 9],
        [7, 9, 7, 9, 7, 9, 15, 15, 15, 15, 7, 9, 7, 9, 7, 9, 15, 15, 15, 15, 7, 9, 7, 9]
    ]
    input_pid = [
        [1366, 1366, 1424, 1424, 1413, 1413, 2985, 2976, 2993, 2975, 1366, 1366, 1424, 1424, 1413, 1413, 2985, 2976, 2993, 2975, 1366, 1366, 1424, 1424],
        [1366, 1366, 1424, 1424, 1413, 1413, 2985, 2976, 2993, 2975, 1366, 1366, 1424, 1424, 1413, 1413, 2985, 2976, 2993, 2975, 1366, 1366, 1424, 1424]
    ]
    target = [
        [1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0],
        [1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0]
    ]

    # 格式化数据
    formatted_records = format_student_records(input_q, input_pid, target)

    # 打印格式化数据
    for student_record in formatted_records:
        for record in student_record:
            print(record)

    print(formatted_records)
    print(f"formatted_records 的维度: {len(formatted_records)} x {len(formatted_records[0]) if formatted_records else 0}")
