Download scripts/index_mapping_for_KT.py from whning0513/PTADisc: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/datasets/whning0513/PTADisc/resolve/main/scripts/index_mapping_for_KT.py
- Command line
-
hf download hf://datasets/whning0513/PTADisc/scripts/index_mapping_for_KT.py
-
curl -L -o index_mapping_for_KT.py https://huggingface.co/datasets/whning0513/PTADisc/resolve/main/scripts/index_mapping_for_KT.py
1.96 kB
| import pandas as pd | |
| import json | |
| import random | |
| import pandas as pd | |
| import tqdm | |
| import numpy as np | |
| import os | |
| DATA_DIR = "./data" | |
| DATA_ASS_DIR = "./" | |
| DATA_SAVE_DIR = "./data" | |
| df = pd.read_csv(DATA_DIR+"/raw.csv", dtype=object, encoding="utf-8") | |
| #del no_answer | |
| df=df.drop(index = df[(df.status == "NO_ANSWER")].index.tolist()) | |
| #process answer format | |
| answer=[] | |
| for row in df.itertuples(index=True, name='hxd'): | |
| if row.status=="ACCEPTED": | |
| answer.append(1) | |
| else: | |
| answer.append(0) | |
| df['status']=answer | |
| #del less than 5 | |
| _users = df.groupby(["user_id"], as_index=True) | |
| delete_users = [] | |
| for j in tqdm.tqdm(_users): | |
| if len(j[1]) < 5: | |
| delete_users.append(j[0]) | |
| print(f"del less than 5, del{len(delete_users)}totally") | |
| df = df[~df['user_id'].isin(delete_users)] | |
| #process pid | |
| psp = json.load(open(DATA_ASS_DIR + "/psp_problem.json", encoding="utf-8")) | |
| problemsetproblemid=df["problem_set_problem_id"] | |
| problem_id_list=[] | |
| for psp_id in problemsetproblemid: | |
| try: | |
| problem_id_list.append(psp[str(psp_id)]) | |
| except: | |
| problem_id_list.append(0) | |
| continue | |
| df["problem_id"]=problem_id_list | |
| df=df.drop(index = df[(df.problem_id == 0)].index.tolist()) | |
| #process difficulty,skill,refcount | |
| dif = json.load(open(DATA_ASS_DIR + "/problem_difficulty.json", encoding="utf-8")) | |
| skill = json.load(open(DATA_ASS_DIR + "/problem_knowledge.json", encoding="utf-8")) | |
| ref = json.load(open(DATA_ASS_DIR + "/problem_reference_count.json", encoding="utf-8")) | |
| pid=df["problem_id"] | |
| dif_list=[] | |
| skill_list=[] | |
| ref_list=[] | |
| for psp_id in tqdm.tqdm(pid): | |
| try: | |
| skill_list.append(skill[str(psp_id)]) | |
| dif_list.append(dif[str(psp_id)]) | |
| ref_list.append(ref[str(psp_id)]) | |
| except: | |
| continue | |
| df["reference_count"]=ref_list | |
| df["skill_id"]=skill_list | |
| df["difficulty"]=dif_list | |
| df.to_csv(DATA_SAVE_DIR + "/jisuan.csv",index=0) | |