Files
ulsu-stat/lib/pipeline.py
T
kozhilya 74edbde327 Refactor report templates and styles
- Updated CSS styles in report.css for improved readability and consistency.
- Removed deprecated report_class.html and report_group.html files.
- Introduced new Jinja2 templates: report_class.jinja and report_group.jinja for better maintainability.
- Enhanced JavaScript functionality in report_class.js to support dynamic chart rendering using Chart.js.
- Updated report_group.js to streamline print functionality.
2026-05-08 14:38:32 +04:00

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_jinja"
))
return pipeline