mirror of
https://github.com/JonasunderscoreJones/epr_grader.git
synced 2025-10-26 01:39:18 +02:00
Readme update
This commit is contained in:
parent
e9c9c6ae49
commit
5497926df1
3 changed files with 135 additions and 97 deletions
107
eprgrader.py
107
eprgrader.py
|
|
@ -8,11 +8,13 @@ Later on, collecting all the stylecheck files and grading tables into
|
|||
neat little archives for upload.
|
||||
"""
|
||||
|
||||
__author__ = "Adrian Welcker, Lukas Horst"
|
||||
__author__ = "Adrian Welcker"
|
||||
__credits__ = "Adjustments from Lukas Horst"
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import copy
|
||||
import csv
|
||||
import io
|
||||
import itertools
|
||||
import os
|
||||
|
|
@ -20,18 +22,19 @@ import pathlib
|
|||
import platform
|
||||
import shutil
|
||||
import sys
|
||||
from itertools import count
|
||||
|
||||
import openpyxl
|
||||
import pandas as pd
|
||||
import unicodedata
|
||||
import zipfile
|
||||
import re
|
||||
|
||||
from openpyxl.styles import Font
|
||||
from datetime import datetime
|
||||
|
||||
from pylint.lint import Run as RunPylint
|
||||
import pycodestyle
|
||||
|
||||
from rating_table_adjuster import update_rating, update_style_deduction
|
||||
from violation_checker import ViolationChecker
|
||||
|
||||
PYLINT_ARGS = [
|
||||
|
|
@ -189,7 +192,10 @@ def lint_files(folders, author_pairs, deduction: bool):
|
|||
|
||||
|
||||
def remove_unnecessary_violations(style_check: str):
|
||||
"""Function to delete all lines with a violation to ignore"""
|
||||
"""
|
||||
Function to delete all lines with a violation to ignore
|
||||
author: Lukas Horst
|
||||
"""
|
||||
lines = style_check.splitlines()
|
||||
|
||||
filtered_lines = []
|
||||
|
|
@ -336,6 +342,99 @@ def finalise_grading(folder: pathlib.Path):
|
|||
outfile.write(file, pathlib.PurePath(person.name) / file.name)
|
||||
|
||||
|
||||
def get_points(file_path: str):
|
||||
"""
|
||||
Returns the total points of the given rating table
|
||||
author: Lukas Horst
|
||||
"""
|
||||
data = pd.read_excel(file_path, usecols='A, C')
|
||||
total_points = 0
|
||||
for i in range(len(data)):
|
||||
if data.iat[i, 0] == 'Summe':
|
||||
break
|
||||
value = data.iat[i, 1]
|
||||
if pd.notna(value) and type(value) != str:
|
||||
total_points += value
|
||||
return max(0, total_points)
|
||||
|
||||
|
||||
def update_style_deduction(file_path: str, violation_checker: ViolationChecker, student_name: str):
|
||||
"""
|
||||
Function to update the deduction for style violations in the given rating table
|
||||
author: Lukas Horst
|
||||
"""
|
||||
wb = openpyxl.load_workbook(file_path, data_only=True)
|
||||
ws = wb['Sheet1']
|
||||
# Updating the name
|
||||
ws[f'A1'].value = student_name
|
||||
rows = ws.iter_rows(min_row=1, max_row=75, min_col=1, max_col=1)
|
||||
for i, row in enumerate(rows):
|
||||
cell = row[0]
|
||||
if cell.value is not None:
|
||||
# Updating the deduction for the author variable
|
||||
if '__author__' in cell.value:
|
||||
ws[f'C{i+1}'].value = -violation_checker.count_deduction(3)
|
||||
ws[f'C{i + 1}'].font = Font(color='FF0000')
|
||||
# All deductions except the author variable and docstrings
|
||||
elif 'o.g. Fehler' in cell.value:
|
||||
deduction = 0
|
||||
for j in range(1, 10):
|
||||
if j == 3 or j == 5:
|
||||
continue
|
||||
deduction -= violation_checker.count_deduction(j)
|
||||
ws[f'C{i+1}'].value = deduction
|
||||
ws[f'C{i+1}'].font = Font(color='FF0000')
|
||||
# Deduction for docstrings
|
||||
elif 'Abzug bei' in cell.value:
|
||||
ws[f'C{i+1}'].value = -violation_checker.count_deduction(5)
|
||||
ws[f'C{i + 1}'].font = Font(color='FF0000')
|
||||
# Updating the function for the total points
|
||||
elif 'Summe' in cell.value:
|
||||
ws[f'C{i+1}'] = f'=MAX(0, SUM(C1:C{i}))'
|
||||
break
|
||||
wb.save(file_path)
|
||||
wb.close()
|
||||
|
||||
|
||||
def read_csv_file(file_path: str):
|
||||
"""
|
||||
Function to read a csv file and returns a list with each row in a dic
|
||||
author: Lukas Horst
|
||||
"""
|
||||
with open(file_path, mode='r', newline='', encoding='utf-8') as file:
|
||||
reader = csv.DictReader(file)
|
||||
rows = []
|
||||
for row in reader:
|
||||
rows.append(row)
|
||||
return rows
|
||||
|
||||
|
||||
def write_csv_file(file_path: str, data: list[dict[str, str]]):
|
||||
"""
|
||||
Function to (over)write a csv file with the given data
|
||||
author: Lukas Horst
|
||||
"""
|
||||
with open(file_path, mode='w', newline='', encoding='utf-8') as file:
|
||||
fieldnames = list(data[0].keys())
|
||||
writer = csv.DictWriter(file, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
writer.writerows(data)
|
||||
|
||||
|
||||
def update_rating(overall_rating_path: str, student_rating_path: str, student_name: str):
|
||||
"""
|
||||
Function to update the points of the given student
|
||||
author: Lukas Horst
|
||||
"""
|
||||
csv_data = read_csv_file(overall_rating_path)
|
||||
for row in csv_data:
|
||||
if row['Vollständiger Name'] == student_name:
|
||||
points = str(get_points(student_rating_path)).replace('.', ',')
|
||||
row['Bewertung'] = points
|
||||
write_csv_file(overall_rating_path, csv_data)
|
||||
return
|
||||
|
||||
|
||||
def main():
|
||||
"""The function main is where execution begins."""
|
||||
print('EPRgrader v3/221031 running on ', datetime.now(), ' [', platform.platform(terse=True), ' ',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue