pykubegrader.grade_reports namespace#

Submodules#

pykubegrader.grade_reports.assignments module#

class pykubegrader.grade_reports.assignments.Assignment(name: str, weekly: bool, weight: float, score: float, grade_adjustment_func=None, **kwargs)[source]#

Bases: assignment_type

Class for storing and updating assignment scores.

week#

The week number of the assignment.

Type:

int, optional

exempted#

Indicates if the assignment is exempted.

Type:

bool

graded#

Indicates if the assignment has been graded.

Type:

bool

late_adjustment#

Indicates if late submissions are allowed.

Type:

bool

students_exempted#

List of student IDs exempted from the assignment.

Type:

list

due_date#

The due date of the assignment.

Type:

datetime, optional

max_score#

The maximum score possible for the assignment.

Type:

float, optional

grade_adjustment_func#

Function to adjust the grade for late or exempted submissions.

Type:

callable, optional

add_exempted_students(students)[source]#

Add students to the exempted list.

update_score(submission=None)[source]#

Update the score of the assignment based on the submission.

grade_adjustment(submission)[source]#

Apply the adjustment function if provided.

add_exempted_students(students)[source]#

Add students to the exempted list. :param students: List of student IDs to exempt from the assignment. :type students: list

check_cheater(score, **kwargs)[source]#
grade_adjustment(submission, **kwargs)[source]#

Applies adjustments to the submission score based on grading policies.

This method applies any provided grade adjustment function to the raw score. If no custom function is given, it determines the final score by considering lateness penalties based on the submission timestamp and due date.

Parameters:

submission (dict) – A dictionary containing: - “raw_score” (float): The initial unadjusted score. - “timestamp” (str): The submission timestamp in a parsable format.

Returns:

The adjusted score, incorporating lateness penalties if applicable.

Returns 0 for late submissions if no late adjustment policy is defined.

Return type:

float

update_score(submission=None, **kwargs)[source]#

Updates the assignment score based on the given submission.

This method adjusts the score using the grade_adjustment function if a submission is provided. If the submission results in a higher score than the current score, the assignment score is updated. If no submission is provided and the student is not exempted, the score is set to zero. If the student is exempted, the score is set to NaN.

Parameters:

submission (dict, optional) – The submission data, expected to contain relevant details for grading. Defaults to None.

Returns:

The updated assignment score. If exempted, returns NaN. If no submission

is provided, returns 0.

Return type:

float

class pykubegrader.grade_reports.assignments.assignment_type(name: str, weekly: bool, weight: float | tuple[float, float])[source]#

Bases: object

Base class for assignment types.

weight#

The weight of the assignment in the overall grade.

Type:

float

__init__(name

str, weekly: bool, weight: float): Initializes an instance of the assignment_type class.

pykubegrader.grade_reports.class_grade_report module#

class pykubegrader.grade_reports.class_grade_report.ClassGradeReport(user, password, **kwargs)[source]#

Bases: object

Generates and manages a class-wide grade report.

This class retrieves a list of students, initializes a structured grade report, and populates it with individual student grade data. The final report includes both assignment-specific grades and a weighted average grade.

student_list#

A sorted list of all students in the class.

Type:

list

all_student_grades_df#

A DataFrame storing grades for each student, including assignment scores and a weighted average.

Type:

pd.DataFrame

setup_class_grades()[source]#

Initializes an empty DataFrame with assignment names and weighted average columns.

update_student_grade(student)[source]#

Fetches and updates an individual student’s weighted average grades in the DataFrame.

fill_class_grades()[source]#

Iterates through all students to populate the class-wide grade report.

fill_class_grades()[source]#

Populates the class-wide grade report with data from all students.

Iterates through the student_list and updates the DataFrame by fetching and storing each student’s weighted average grades.

get_class_stats()[source]#

Calculates and stores descriptive statistics for the class-wide grade report. Requires filling class grades first

make_report(**kwargs)[source]#

Makes the class grade report.

Parameters:

**kwargs – Additional keyword arguments.

setup_class_grades()[source]#

Creates an empty DataFrame to store grades for all students.

The DataFrame contains assignment columns and a “Weighted Average Grade” column, with students as index labels.

update_student_grade(student)[source]#

Fetches and updates the grade report for an individual student.

Parameters:

student (str) – The username or identifier of the student.

Updates:

The student’s row in all_student_grades_df with their weighted average grades.

write_excel_spreadsheet(out_name='output.xlsx')[source]#

Exports the class-wide grade report to an Excel spreadsheet.

Parameters:

out_name (str, optional) – Name of output file. Defaults to ‘output.xlsx’.

pykubegrader.grade_reports.class_grade_report.main()[source]#

pykubegrader.grade_reports.grade_report module#

class pykubegrader.grade_reports.grade_report.GradeReport(start_date='2025-01-06', verbose=True, params=None, display_=True)[source]#

Bases: object

Class to generate a grade report for a course and perform grade calculations for each student.

build_assignments()[source]#

Generates a list of Assignment objects for each week, applying custom adjustments where needed.

calculate_grades()[source]#

Calculates the grades for each student based on the graded assignments. If there are filtered assignments, the score is updated based on the submission. Otherwise,

check_optional_drop_assignments()[source]#

Checks if the optional drop assignments are valid.

color_cells(styler, week_list, assignment_list)[source]#
compute_final_average()[source]#

Computes the final average by combining the running average from weekly assignments and the midterm/final exam scores.

determine_due_date(filtered_assignments)[source]#
drop_lowest_n_for_types(n, assignments_=None)[source]#

Exempts the lowest n assignments for each specified assignment type. If the lowest dropped score is from week 1, an additional lowest score is dropped.

Parameters:
  • assignments – List of assignment types (names) to process.

  • n – Number of lowest scores to exempt per type.

duplicate_scores()[source]#

Duplicate scores from one assignment to another

filter_submissions(week_number, assignment_type)[source]#
get_assignment(week_number, assignment_type)[source]#
get_graded_assignment(week_number, assignment_type)[source]#
get_max_score(filtered_assignments)[source]#
get_non_weekly_assignments()[source]#

Get all weekly assignments from the assignment list configuration

get_num_weeks()[source]#

Get the number of weeks in the course

get_weekly_assignments()[source]#

Get all weekly assignments from the assignment list configuration

graded_assignment_constructor(assignment_type: assignment_type, **kwargs)[source]#

Constructs a graded assignment object and appends it to the graded_assignments list.

Parameters:

assignment_type (str) – Type of assignment. Options: readings, lecture, practicequiz, quiz, homework, lab, labattendance, practicemidterm, midterm, practicefinal, final.

static highlight_nans(nan_df, display_df, color='red')[source]#

Highlights NaN values from nan_df on display_df.

Parameters: nan_df (pd.DataFrame): DataFrame containing NaNs to be highlighted. display_df (pd.DataFrame): DataFrame to be recolored. color (str): Background color for NaNs. Default is ‘red’.

Returns: pd.io.formats.style.Styler: Styled DataFrame with NaNs highlighted.

setup_grades_df()[source]#
update_assignments_not_due_yet()[source]#

Updates the score of assignments that are not due yet to NaN.

update_global_exempted_assignments()[source]#

Updates the graded assignments with the globally exempted assignments. If assignment doesn’t exist, pass.

update_weekly_table()[source]#

pykubegrader.grade_reports.grading_config module#