Classify static and smart crates
This commit is contained in:
+25
-2
@@ -1,6 +1,7 @@
|
||||
from collections import Counter
|
||||
|
||||
from serato_doctor.matching import MatchingEngine
|
||||
from serato_doctor.models.crate import CrateKind
|
||||
from serato_doctor.models.health import HealthReport
|
||||
from serato_doctor.models.library import Library
|
||||
|
||||
@@ -8,7 +9,14 @@ from serato_doctor.models.library import Library
|
||||
def analyze_health(library: Library) -> HealthReport:
|
||||
"""Calculate defensible health metrics without changing the library."""
|
||||
|
||||
results = library.reconcile_by_filename()
|
||||
dynamic_sources = {
|
||||
crate.path for crate in library.crates if crate.kind is CrateKind.SMART
|
||||
}
|
||||
results = tuple(
|
||||
result
|
||||
for result in library.reconcile_by_filename()
|
||||
if result.reference.source not in dynamic_sources
|
||||
)
|
||||
missing = [result for result in results if not result.exists_by_filename]
|
||||
healthy_count = len(results) - len(missing)
|
||||
score = (
|
||||
@@ -29,7 +37,8 @@ def analyze_health(library: Library) -> HealthReport:
|
||||
|
||||
return HealthReport(
|
||||
score=score,
|
||||
total_references=len(results),
|
||||
total_references=len(library.references),
|
||||
scored_references=len(results),
|
||||
healthy_references=healthy_count,
|
||||
missing_references=len(missing),
|
||||
unique_missing_filenames=len(
|
||||
@@ -40,4 +49,18 @@ def analyze_health(library: Library) -> HealthReport:
|
||||
duplicate_files=sum(count - 1 for count in duplicate_counts),
|
||||
unused_tracks=unused_count,
|
||||
suggested_matches=suggested_count,
|
||||
static_crates=sum(
|
||||
crate.kind is CrateKind.STATIC for crate in library.crates
|
||||
),
|
||||
smart_crates=sum(
|
||||
crate.kind is CrateKind.SMART for crate in library.crates
|
||||
),
|
||||
unknown_crates=sum(
|
||||
crate.kind is CrateKind.UNKNOWN for crate in library.crates
|
||||
),
|
||||
dynamic_references_excluded=sum(
|
||||
len(crate.references)
|
||||
for crate in library.crates
|
||||
if crate.kind is CrateKind.SMART
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user