Placement notification formatter

Introduction#

PlacementNotificationFormatter turns offer documents into channel-ready text. Templates for final selections versus updates, HTML/Markdown choices, and the fields each template expects.

Project structure#

The placement notification system is organized within the application’s services layer, with clear boundaries between data extraction, formatting, and delivery components.

Core components#

The Placement Notification Formatter consists of several key components that work together to transform raw placement data into notification-ready content:

Data models and structures#

The formatter defines detailed data models for representing placement offers, students, roles, and notification documents. These models ensure type safety and provide clear contracts for data transformation.

Formatting algorithms#

Specialized algorithms handle the transformation of raw placement data into human-readable notifications, with particular attention to:

  • Company information presentation
  • Student listing organization
  • Package details formatting
  • Selection criteria summarization

Template generation#

The system implements template-based approaches for different placement scenarios, so final selections and updates share the same layout rules.

Architecture overview#

The placement notification system follows a layered architecture and dependency injection for testability.

Detailed component analysis#

PlacementNotificationFormatter class#

The formatter turns placement offer docs into notification text.

Data model definitions#

The formatter defines several Pydantic models that are the foundation for data transformation:

Package formatting algorithm#

Package formatting turns raw numbers into readable strings:

Role breakdown algorithm#

Role breakdown groups students by role and formats the counts:

Notification template generation#

The formatter implements template-based approaches for different placement scenarios:

Final Selection Templates.

  • Company placement summary with student count
  • Role breakdown with package information
  • Time sent information when available
  • Congratulations message

Update Templates.

  • Incremental placement update with new student count
  • Total placement counter
  • New position breakdown
  • Update-specific messaging

Integration with notification system#

The formatter integrates deeply with the broader notification ecosystem through several key mechanisms:

Database integration#

The formatter maintains loose coupling with database operations through dependency injection, allowing for flexible storage backends while preserving clean separation of concerns.

Channel delivery#

Notifications are delivered through a unified notification service that supports multiple channels including Telegram and web push notifications.

Event processing pipeline#

The formatter participates in a complete pipeline that includes email processing, data extraction, validation, and notification delivery.

Dependency analysis#

The placement notification system exhibits well-structured dependencies that promote maintainability and testability.

Coupling and cohesion analysis#

Formatter only formats. Persistence and delivery stay in DatabaseService and NotificationService.

Circular dependencies#

No circular dependencies were identified in the placement notification system, contributing to its maintainability and testability.

Performance considerations#

Performance notes for the formatter:

Memory efficiency#

  • Streaming processing of large datasets
  • Lazy evaluation of formatted content
  • Efficient string concatenation using join operations

Processing optimizations#

  • Early termination for non-relevant emails
  • Caching of frequently accessed data
  • Minimal object creation during formatting

Scalability features#

  • Asynchronous processing capabilities
  • Configurable batch sizes
  • Resource-aware operation limits

Troubleshooting guide#

Common issues and their solutions when working with the placement notification formatter:

Data transformation issues#

  • Problem: Incorrect package formatting

  • Solution: Verify numeric values are properly converted and handle edge cases

  • Check: Ensure package values are numeric and within expected ranges

  • Problem: Missing role information in student listings

  • Solution: Implement default role assignment when single role exists

  • Check: Validate role assignment logic for multi-role scenarios

Notification delivery problems#

  • Problem: Telegram message delivery failures

  • Solution: Check rate limiting and implement exponential backoff

  • Check: Verify bot token and chat ID configuration

  • Problem: Database storage conflicts

  • Solution: Implement conflict resolution and retry logic

  • Check: Verify unique identifier generation and collision handling

Integration challenges#

  • Problem: Email processing inconsistencies
  • Solution: Implement reliable error handling and retry mechanisms
  • Check: Validate email parsing and extraction logic

Conclusion#

Formatter turns offer docs into sendable text. Keep templates and merge logic separate and new offer shapes stay a template change.