year_consistency
¶
Year consistency checking logic extracted from YearRetriever.
This module handles year dominance calculation, parity detection, consensus checking, and anomalous track identification.
YearConsistencyChecker
¶
YearConsistencyChecker(
*,
console_logger,
top_years_count=TOP_YEARS_COUNT,
parity_threshold=PARITY_THRESHOLD,
dominance_min_share=DOMINANCE_MIN_SHARE,
suspicion_threshold_years=DEFAULT_SUSPICION_THRESHOLD_YEARS
)
Handles year consistency analysis for album tracks.
Responsibilities: - Calculate dominant year using majority rule - Detect year parity between top candidates - Find consensus release year across tracks - Identify tracks with anomalous years
Initialize the year consistency checker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console_logger
|
Logger
|
Logger for console output |
required |
top_years_count
|
int
|
Number of top years to consider for parity |
TOP_YEARS_COUNT
|
parity_threshold
|
int
|
Max difference for parity detection |
PARITY_THRESHOLD
|
dominance_min_share
|
float
|
Min share of tracks for dominance (0.0-1.0) |
DOMINANCE_MIN_SHARE
|
suspicion_threshold_years
|
int
|
If dominant year is this many years older than earliest track added date, trigger API verification |
DEFAULT_SUSPICION_THRESHOLD_YEARS
|
Source code in src/core/tracks/year_consistency.py
get_dominant_year
¶
Find dominant year among tracks using majority rule.
Calculates dominance based on ALL tracks in album, not just tracks for years. A year is dominant only if >50% of ALL album tracks have that year.
Note: Years "0" and empty strings are excluded from dominance calculation as they represent placeholder/default values in Music.app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
list[TrackDict]
|
List of ALL tracks in the album to analyze |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Dominant year string if found, None if no clear majority or parity |
Source code in src/core/tracks/year_consistency.py
get_most_common_year
staticmethod
¶
Get most common year among tracks for comparison purposes.
Unlike get_dominant_year(), this method returns the most common year without any trust checks (suspicious year detection, dominance threshold). Used specifically for year-match comparison with API results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
list[TrackDict]
|
List of tracks to analyze |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Most common year string, or None if no valid years found |
Source code in src/core/tracks/year_consistency.py
get_consensus_release_year
¶
Get release_year if all tracks agree (consensus).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
list[TrackDict]
|
List of tracks to check |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Consensus release_year string if found, None otherwise |
Source code in src/core/tracks/year_consistency.py
get_earliest_track_added_year
staticmethod
¶
Extract earliest year any track was added to library.
Useful for detecting current year contamination - if tracks were added this year and library year is current year, it's likely legitimate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
list[TrackDict]
|
List of tracks to analyze |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Earliest year a track was added, or None if no dates found |