File size: 3,102 Bytes
fbeda03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
Logging helper functions for consistent, centralized log formatting.

This module provides helper functions to reduce verbose multi-line logging
statements in the main code, improving readability while maintaining
detailed log output.
"""

import logging
from typing import List, Optional, TYPE_CHECKING

if TYPE_CHECKING:
    from tracking import PlayEvent


def log_flag_plays(flag_plays: List["PlayEvent"], logger_instance: logging.Logger) -> None:
    """
    Log details of FLAG plays in a consistent format.

    Args:
        flag_plays: List of FLAG PlayEvent objects to log
        logger_instance: Logger to use for output
    """
    for fp in flag_plays:
        logger_instance.info(
            "  FLAG: %.1fs - %.1fs (duration=%.1fs)",
            fp.start_time,
            fp.end_time,
            fp.end_time - fp.start_time,
        )


def log_play_complete(play: "PlayEvent", method: str, logger_instance: logging.Logger) -> None:
    """
    Log when a play is completed (via backward calc or capped).

    Replaces 7-line logging blocks like:
        logger.info(
            "Play #%d complete (backward calc, %s): %.1fs - %.1fs (duration: %.1fs)",
            play.play_number, play.play_type, play.start_time, play.end_time,
            play.end_time - play.start_time,
        )

    Args:
        play: The completed PlayEvent
        method: Completion method ("backward_calc" or "capped")
        logger_instance: Logger to use for output
    """
    logger_instance.info(
        "Play #%d complete (%s, %s): %.1fs - %.1fs (duration: %.1fs)",
        play.play_number,
        method,
        play.play_type,
        play.start_time,
        play.end_time,
        play.end_time - play.start_time,
    )


def log_play_created(
    play: "PlayEvent",
    play_type: str,
    logger_instance: logging.Logger,
    extra_info: Optional[str] = None,
) -> None:
    """
    Log when a play is created (timeout, special, turnover, etc.).

    Replaces 6-7 line logging blocks like:
        logger.info(
            "Play #%d created (special): %.1fs - %.1fs (duration: %.1fs, end_method: %s)",
            play.play_number, play.start_time, play.end_time,
            play.end_time - play.start_time, end_method,
        )

    Args:
        play: The created PlayEvent
        play_type: Type description ("timeout, home", "special", "normal, turnover")
        logger_instance: Logger to use for output
        extra_info: Optional additional info to append (e.g., end_method)
    """
    duration = play.end_time - play.start_time
    if extra_info:
        logger_instance.info(
            "Play #%d created (%s): %.1fs - %.1fs (duration: %.1fs, %s)",
            play.play_number,
            play_type,
            play.start_time,
            play.end_time,
            duration,
            extra_info,
        )
    else:
        logger_instance.info(
            "Play #%d created (%s): %.1fs - %.1fs (duration: %.1fs)",
            play.play_number,
            play_type,
            play.start_time,
            play.end_time,
            duration,
        )