import os import pandas as pd from argparse import ArgumentParser from src.grade import parse_grade_data, parse_final_grade_data from src.execution import parse_execution_data from src.assessment import parse_assessment_simple def parse_args(): """ Parse command line arguments. """ parser = ArgumentParser(description="Process CodeBench data.") parser.add_argument("--input", type=str, required=True, help="Input directory containing downloaded tar.") return parser.parse_args() def process_data(BASE_PATH): assessment_data = [] grade_data = [] execution_data = [] for root, dirs, files in os.walk(BASE_PATH): for d in dirs: full_path = os.path.join(root, d) if not len(dirs): # We are within a last level directory if root.split("/")[-1] == "assessments": for f in files: full_path = os.path.join(root, f) assessment_data.append(parse_assessment_simple(full_path)) elif root.split("/")[-1] == "grades": for f in files: if f.endswith(".data"): # Final grade full_path = os.path.join(root, f) grade_data.append(parse_final_grade_data(full_path)) else: full_path = os.path.join(root, f) grade_data.append(parse_grade_data(full_path)) elif root.split("/")[-1] == "executions": for f in files: full_path = os.path.join(root, f) execution_data.append(parse_execution_data(full_path)) break assessment_df = pd.concat(assessment_data) grade_df = pd.concat(grade_data) execution_df = pd.concat(execution_data) return assessment_df, grade_df, execution_df def main(): args = parse_args() # Load all provided dataframes subset = args.input.split("/")[-1] print(f"Processing data from {subset}...") assessment_df, grade_df, execution_df = process_data(args.input) # Save the dataframes to CSV files base_save_path = f"./data/{subset}/" os.makedirs(base_save_path, exist_ok=True) assessment_df.to_csv(os.path.join(base_save_path, f"assessment_{subset}.csv"), index=False) grade_df.to_csv(os.path.join(base_save_path, f"grade_{subset}.csv"), index=False) execution_df.to_csv(os.path.join(base_save_path, f"execution_{subset}.csv"), index=False) if __name__ == "__main__": main()