- Implemented `stage_parse_schedule.py` to normalize and prepare university schedule data. - Created `stage_process_logs.py` for processing authentication logs and generating session records. - Added necessary classes and methods for log entry parsing, session extraction, and CSV output. - Updated `settings.yaml` with new schedule and processing configurations. - Introduced new templates and styles for report generation, including HTML and CSS files. - Added main entry point `run.py` to execute the attendance processing pipeline. - Included `.gitkeep` files in `output` and `result` directories to maintain structure.
150 lines
4.4 KiB
Python
150 lines
4.4 KiB
Python
"""Main pipeline for processing attendance data."""
|
|
|
|
from pathlib import Path
|
|
from typing import Dict, Any, List
|
|
from dataclasses import dataclass
|
|
import inspect
|
|
|
|
|
|
@dataclass
|
|
class Stage:
|
|
"""Represents a processing stage."""
|
|
|
|
name: str
|
|
description: str
|
|
module_name: str
|
|
run_function: str = "run_stage"
|
|
|
|
|
|
class Pipeline:
|
|
"""Manages the execution of sequential processing stages."""
|
|
|
|
def __init__(self, workspace_root: Path):
|
|
"""
|
|
Initialize the pipeline.
|
|
|
|
Args:
|
|
workspace_root: Root directory of the project
|
|
"""
|
|
self.workspace_root = Path(workspace_root)
|
|
self.stages: List[Stage] = []
|
|
self.context: Dict[str, Any] = {"workspace_root": workspace_root}
|
|
|
|
def add_stage(self, stage: Stage) -> None:
|
|
"""
|
|
Add a stage to the pipeline.
|
|
|
|
Args:
|
|
stage: Stage to add
|
|
"""
|
|
self.stages.append(stage)
|
|
|
|
def run(self) -> Dict[str, Any]:
|
|
"""
|
|
Execute all stages in sequence.
|
|
|
|
Returns:
|
|
Final context with results from all stages
|
|
"""
|
|
print("=" * 60)
|
|
print("ATTENDANCE PROCESSING PIPELINE")
|
|
print("=" * 60)
|
|
|
|
for i, stage in enumerate(self.stages, 1):
|
|
print(f"\n[Stage {i}] {stage.name}")
|
|
print(f"Description: {stage.description}")
|
|
print("-" * 60)
|
|
|
|
try:
|
|
# Dynamically import and run the stage
|
|
module = self._import_stage(stage.module_name)
|
|
run_func = getattr(module, stage.run_function)
|
|
|
|
# Run the stage with current context.
|
|
# Stages may accept either (workspace_root) or (workspace_root, context).
|
|
params = inspect.signature(run_func).parameters
|
|
if len(params) >= 2:
|
|
result = run_func(self.workspace_root, self.context)
|
|
else:
|
|
result = run_func(self.workspace_root)
|
|
|
|
# Store result in context
|
|
self.context[stage.module_name] = result
|
|
|
|
print(f"✓ Stage completed successfully\n")
|
|
|
|
except Exception as e:
|
|
print(f"✗ Stage failed with error: {str(e)}\n")
|
|
raise
|
|
|
|
print("=" * 60)
|
|
print("PIPELINE COMPLETED SUCCESSFULLY")
|
|
print("=" * 60)
|
|
|
|
return self.context
|
|
|
|
def _import_stage(self, module_name: str):
|
|
"""
|
|
Dynamically import a stage module.
|
|
|
|
Args:
|
|
module_name: Name of the module to import
|
|
|
|
Returns:
|
|
Imported module
|
|
"""
|
|
import importlib
|
|
|
|
full_module_name = f"lib.{module_name}"
|
|
return importlib.import_module(full_module_name)
|
|
|
|
|
|
def create_default_pipeline(workspace_root: Path) -> Pipeline:
|
|
"""
|
|
Create a pipeline with default stages.
|
|
|
|
Args:
|
|
workspace_root: Root directory of the project
|
|
|
|
Returns:
|
|
Configured pipeline ready to run
|
|
"""
|
|
pipeline = Pipeline(workspace_root)
|
|
|
|
# Stage 1: Load settings
|
|
pipeline.add_stage(Stage(
|
|
name="Load Settings",
|
|
description="Load configuration from settings.yaml and class data from classes.csv",
|
|
module_name="stage_load_settings"
|
|
))
|
|
|
|
# Stage 2: Process logs
|
|
pipeline.add_stage(Stage(
|
|
name="Process Authentication Logs",
|
|
description="Extract sessions from Windows authentication logs and group by class",
|
|
module_name="stage_process_logs"
|
|
))
|
|
|
|
# Stage 3: Parse university schedule export (placeholder for now)
|
|
pipeline.add_stage(Stage(
|
|
name="Parse University Schedule",
|
|
description="Prepare schedule data for future group attendance calculations",
|
|
module_name="stage_parse_schedule"
|
|
))
|
|
|
|
# Stage 4: Build report data
|
|
pipeline.add_stage(Stage(
|
|
name="Build Report Data",
|
|
description="Aggregate processed sessions into JSON report data",
|
|
module_name="stage_build_report_data"
|
|
))
|
|
|
|
# Stage 5: Generate HTML reports
|
|
pipeline.add_stage(Stage(
|
|
name="Generate HTML Reports",
|
|
description="Create standalone HTML reports for groups and classes",
|
|
module_name="stage_generate_reports_html"
|
|
))
|
|
|
|
return pipeline
|