Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lowrank committed Sep 7, 2024
1 parent 0a66ce2 commit 155afa7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
10 changes: 8 additions & 2 deletions grader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import requests

from utility import execute_system_call, find_emails, extract_link, unzip
from utility import execute_system_call, find_emails, extract_link, unzip, remove_duplicates

NULL_EMAIL = 'null___@null__.___'

Expand Down Expand Up @@ -227,7 +227,7 @@ def grade(self, hw_str='hw00', output_file='grades.csv'):
"""
# create a file to store the grades
with open(output_file, 'w', encoding='utf-8') as grades_file:
grades_file.write('Name, ID, Email, Language, Score\n')
grades_file.write('Name,ID,Email,Language,Score\n')
# Unzip the submission file
if not os.path.exists(self.submission_dir):
print('Unzipping the submission file ...')
Expand Down Expand Up @@ -257,4 +257,10 @@ def grade(self, hw_str='hw00', output_file='grades.csv'):
cnt_passes, email, student_code = self.grade_exception_file(hw_str, student_dir)
data.append( (cnt_passes, email, student_code))
self.output(grades_file, i, student_info, data)

grades_file.close()
print(f'\nGrades saved in {output_file}\n')
print('Cleaning up ...')
remove_duplicates(output_file)
print('============== Grading completed! =============\n\n')

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
requests
bs4
numpy
numpy
pandas
15 changes: 15 additions & 0 deletions utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import zipfile
import subprocess
import pandas as pd
from bs4 import BeautifulSoup

def execute_system_call(command):
Expand Down Expand Up @@ -61,3 +62,17 @@ def unzip(file, file_dir, skip_dir=True):
continue
zip_info.filename = os.path.basename(zip_info.filename)
zip_ref.extract(zip_info, file_dir)

def remove_duplicates(csv_file):
"""
Remove duplicate IDs (remain the maximum score value) in the CSV file with panda
"""
# Read the CSV file
df = pd.read_csv(csv_file)

# Remove duplicate IDs (remain the maximum score value)
df = df.sort_values('Score', ascending=False).drop_duplicates('ID').sort_index()

# Write the updated data to the CSV file
df.to_csv(csv_file, index=False)

0 comments on commit 155afa7

Please sign in to comment.