attendance_tool_msp package

Attendance Tool Package

A comprehensive attendance automation system for processing CSV attendance data, validating student information, and generating formatted reports.

Modules: - processor: CSV data validation and processing - exporter: Word and PDF report generation - argument_parser: Command-line interface handling

Subpackages: - gui: Graphical user interface components

class attendance_tool_msp.Exporter(valid_rows, invalid_rows, title='Attendance Report')

Bases: object

Document export class for generating Word and PDF attendance reports.

Design Note:

Helper methods are instance methods because they work together as a cohesive workflow. Using individual helper functions as static methods wouldn’t make sense since they depend on each other and the instance data. These helper methods are meant to work together internally, not to be called from outside, and would likely cause unexpected results if used independently.

valid_rows

Valid attendance records

Type:

list

invalid_rows

Invalid records with error messages

Type:

list

title

Document title

Type:

str

export_pdf()

Generate a PDF document by converting a Word document. The temporary Word document is automatically deleted after conversion.

Returns:

The file path of the generated PDF document

Return type:

str

Raises:
  • PermissionError – If Word document creation fails due to file access issues

  • Exception – If Word document creation fails or PDF conversion fails

export_word()

Generate a Word document containing attendance data.

Returns:

The file path of the generated Word document

Return type:

str

Raises:

PermissionError – If document cannot be created or saved

property invalid_rows

Get the list of invalid attendance rows.

Returns:

List of dictionaries containing invalid attendance data with error messages

Return type:

list

property title

Get the document title.

Returns:

The document title used for headers and filenames

Return type:

str

property valid_rows

Get the list of valid attendance rows.

Returns:

List of dictionaries containing valid attendance data

Return type:

list

class attendance_tool_msp.Processor(file_path)

Bases: object

CSV validation and processing class for attendance data.

Design Note:

Validation methods are static methods by design choice. These pure functions don’t need instance state. Making them static improves reusability and testability. They can be called independently without creating processor instances and are expected to be used for testing and reuse, outputting expected results.

file_path

Path to the CSV file to process

Type:

str

property file_path

Get the CSV file path.

Returns:

The path to the CSV file

Return type:

str

process()

Validates CSV file and returns valid and invalid data.

Returns:

(valid_rows, invalid_rows) as lists of dictionaries

Return type:

tuple

Raises:
  • FileNotFoundError – If CSV file cannot be opened

  • ValueError – If CSV headers are invalid or missing

static validate_course_code(course_code)

Validates MIU course code format. At least 3 letters + at least 3 numbers + optional additional characters including parentheses. Normalizes format with proper capitalization. Regular expressions are used.

Examples

SWE11004, CSC101, MRK10105-BUS, ETH10104-CSC, BAS13104 Lecture, BAS13104 Tutorial, BAS1120301 (Tutorial)

Parameters:

course_code (str) – The course code to validate

Returns:

Validated and normalized course code with proper capitalization

Return type:

str

Raises:

ValueError – If course code format is invalid

static validate_course_time(course_time)

Validates course time format and returns normalized H:MM - H:MM format. Supports formats like H:MM - H:MM, H - H:MM, H to H:MM (minutes optional, - or to separator). AM/PM indicators are NOT supported. Regular expressions are used.

Examples

1:00 - 2:30, 11:30 - 1, 1 to 2:30, 9 - 10:15

Parameters:

course_time (str) – The course time to validate

Returns:

Normalized course time in H:MM - H:MM format

Return type:

str

Raises:

ValueError – If course time format is invalid

static validate_csv_headers(fieldnames)

Validates that all required CSV headers are present.

Parameters:

fieldnames (list) – List of column headers from CSV file

Returns:

This function does not return a value, it only validates

Return type:

None

Raises:

ValueError – If columns/headers are missing or empty

static validate_dr_ta_name(name)

Validates and normalizes instructor names (Doctor/TA). Similar functionality to validate_name but allows for titles like “Dr.”, “TA”, and “Prof.”. Auto-adds “Dr.” prefix if no title is detected anywhere in the name. Regular expressions are used.

Parameters:

name (str) – The instructor’s name to validate

Returns:

Normalized instructor name with appropriate title prefix

Return type:

str

Raises:

ValueError – If name is invalid

static validate_email(email)

Validates university email addresses. Regular expressions are not used.

Parameters:

email (str) – The email address to validate

Returns:

This function does not return a value, it only validates

Return type:

None

Raises:

ValueError – If email is invalid or not from required domain

static validate_hour(hour)

Helper method for course time validation - validates hour values for 12-hour time format.

Parameters:

hour (int) – Hour value to validate

Returns:

This function does not return a value, it only validates

Return type:

None

Raises:

ValueError – If hour is not between 1-12 (inclusive)

static validate_minutes(minutes)

Helper method for course time validation - validates minute values for time format.

Parameters:

minutes (int) – Minute value to validate

Returns:

This function does not return a value, it only validates

Return type:

None

Raises:

ValueError – If minutes is not between 0-59 (inclusive)

static validate_name(name)

Validates and normalizes a person’s full name. Automatically capitalizes each word for consistent formatting. Regular expressions are used.

Parameters:

name (str) – The full name to validate

Returns:

Validated and properly capitalized name

Return type:

str

Raises:

ValueError – If name is invalid

static validate_university_id(student_id)

Validates MIU student ID format (YYYY/XXXXX). Auto-formats 9-digit IDs without slashes to YYYY/XXXXX format. Regular expressions are not used.

Examples

2023/00824, 2020/34125, 202306246 (auto-formatted to 2023/06246)

Parameters:

student_id (str) – The student ID to validate

Returns:

Validated and normalized student ID in YYYY/XXXXX format

Return type:

str

Raises:

ValueError – If student ID format is invalid

attendance_tool_msp.initialize_parser()

Configure a customized command line argument parser for attendance processing.

Sets up argument parsing for CSV file processing with Word/PDF export options. Supports both GUI mode (no arguments) and command-line export mode.

Returns:

Configured parser with CSV file, export format, and title arguments

Return type:

argparse.ArgumentParser

attendance_tool_msp.launch_gui()

Launch the MSP Attendance Exporter GUI application.

attendance_tool_msp.validate_arguments(parser, args)

Validate parsed command line arguments and determine application mode.

Analyzes the provided arguments to determine whether to run in GUI mode or export mode, and validates that required arguments are present for each mode.

Parameters:
  • parser (argparse.ArgumentParser) – The argument parser object for error reporting

  • args (argparse.Namespace) – Parsed command line arguments

Returns:

Application mode - either “gui” or “export”

Return type:

str

Raises:

SystemExit – Via parser.error() if invalid argument combinations are provided