File size: 1,959 Bytes
621eb67 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 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)
|