-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_track_order.py
More file actions
121 lines (96 loc) · 4.13 KB
/
Copy pathcheck_track_order.py
File metadata and controls
121 lines (96 loc) · 4.13 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3
"""
Standalone script to check if track numbers in batch_content.txt are in ascending order.
This script can be run independently without importing the server module.
Usage:
python3 check_track_order.py
Or make it executable and run:
chmod +x check_track_order.py
./check_track_order.py
"""
import os
import re
def _get_batch_file_path():
"""Get the path to batch_content.txt file."""
current_dir = os.path.dirname(os.path.realpath(__file__))
batch_file_path = os.path.join(current_dir, 'output_files/batch_content.txt')
return os.path.abspath(batch_file_path)
def _extract_track_numbers(content):
"""Extract track numbers from file content."""
track_pattern = r'Track:\s*(\d+)'
matches = re.findall(track_pattern, content)
return [int(match) for match in matches] if matches else []
def _find_order_inconsistencies(track_numbers):
"""Find places where tracks are not in ascending order."""
inconsistencies = []
for i in range(1, len(track_numbers)):
current_track = track_numbers[i]
previous_track = track_numbers[i-1]
if current_track <= previous_track:
inconsistencies.append({
'position': i + 1,
'previous_track': previous_track,
'current_track': current_track,
'line_number': i + 2
})
return inconsistencies
def _print_inconsistencies(inconsistencies):
"""Print found inconsistencies."""
print(f"\n❌ INCONSISTENCIES FOUND: {len(inconsistencies)} places where tracks are not in ascending order:")
print("-" * 70)
for issue in inconsistencies:
print(f"Position {issue['position']}: Track {issue['current_track']} comes after Track {issue['previous_track']}")
print(f" Expected: Track {issue['previous_track']} < Track {issue['current_track']}")
print(f" Approximate line: {issue['line_number']}")
print()
def _find_duplicate_tracks(track_numbers):
"""Find duplicate track numbers."""
duplicate_tracks = []
seen = set()
for track in track_numbers:
if track in seen and track not in duplicate_tracks:
duplicate_tracks.append(track)
seen.add(track)
return duplicate_tracks
def _print_statistics(track_numbers):
"""Print additional statistics about tracks."""
expected_sequence = set(range(1, len(track_numbers) + 1))
track_set = set(track_numbers)
missing_tracks = expected_sequence - track_set
duplicate_tracks = _find_duplicate_tracks(track_numbers)
if missing_tracks:
print(f"⚠️ Missing tracks (if expecting 1 to {len(track_numbers)}): {sorted(missing_tracks)}")
if duplicate_tracks:
print(f"⚠️ Duplicate tracks found: {duplicate_tracks}")
def check_track_order():
"""
Function to check if track numbers in batch_content.txt are in ascending order.
Prints any inconsistencies found where tracks are not in ascending order.
"""
batch_file_path = _get_batch_file_path()
if not os.path.exists(batch_file_path):
print(f"Error: File not found - {batch_file_path}")
return
try:
with open(batch_file_path, 'r') as f:
content = f.read()
track_numbers = _extract_track_numbers(content)
if not track_numbers:
print("No track numbers found in the file.")
return
print(f"Found {len(track_numbers)} track entries.")
print(f"Track numbers: {track_numbers}")
inconsistencies = _find_order_inconsistencies(track_numbers)
if inconsistencies:
_print_inconsistencies(inconsistencies)
else:
print("\n✅ All tracks are in ascending order!")
_print_statistics(track_numbers)
except Exception as e:
print(f"Error reading file: {e}")
if __name__ == '__main__':
check_track_order()
# ------------------------------------------------------------ #
# To run this script, use the following command:
# python3 check_track_order.py
# ------------------------------------------------------------ #