-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cache_diagnostic.py
More file actions
129 lines (103 loc) · 4.74 KB
/
test_cache_diagnostic.py
File metadata and controls
129 lines (103 loc) · 4.74 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
122
123
124
125
126
127
128
129
#!/usr/bin/env python3
"""
Diagnostic test for cache functionality.
"""
import sys
import os
# Add the project root to the Python path
sys.path.append(r'C:\Users\Federico\Desktop\Desktop App TF4M')
from core.file_analyzer import FileAnalyzer
from core.project_manager import ProjectManager
from core.models import DataType, MatchStatus
def test_cache_diagnostic():
"""Comprehensive cache diagnostic."""
print("Cache Diagnostic Test")
print("=" * 40)
# Test with a real patient folder
patient_folder = r"F:\Dati Ferrara - Test Bulk Upload\ESEMPI\1"
if not os.path.exists(patient_folder):
print(f"❌ Test folder not found: {patient_folder}")
print("Available folders:")
base_folder = r"F:\Dati Ferrara - Test Bulk Upload\ESEMPI"
if os.path.exists(base_folder):
for item in os.listdir(base_folder):
item_path = os.path.join(base_folder, item)
if os.path.isdir(item_path):
print(f" - {item}")
return
print(f"Testing with folder: {patient_folder}")
# Initialize components
analyzer = FileAnalyzer()
project_manager = ProjectManager()
# Step 1: Check cache mode
print(f"\n1. Cache Configuration:")
print(f" Mode: {'centralized' if analyzer.match_cache.centralized_cache else 'distributed'}")
# Step 2: Clear existing cache
print(f"\n2. Clearing existing cache...")
analyzer.invalidate_cache(patient_folder)
cache_file = analyzer.match_cache.get_patient_cache_file(patient_folder)
print(f" Expected cache file: {cache_file}")
print(f" Cache file exists: {os.path.exists(cache_file)}")
# Step 3: Initial analysis
print(f"\n3. Initial analysis...")
patient_data = analyzer.analyze_patient_folder(patient_folder, use_cache=True)
print(f" Patient ID: {patient_data.patient_id}")
print(f" Total files: {len(patient_data.get_all_files())}")
print(f" Unmatched files: {len(patient_data.unmatched_files)}")
# Step 4: Check if cache was created
print(f"\n4. Cache creation check...")
print(f" Cache file exists: {os.path.exists(cache_file)}")
if os.path.exists(cache_file):
file_size = os.path.getsize(cache_file)
print(f" Cache file size: {file_size} bytes")
if file_size > 0:
print(" ✅ Cache file has content")
else:
print(" ❌ Cache file is empty")
# Step 5: Test manual assignment
if patient_data.unmatched_files:
print(f"\n5. Testing manual assignment...")
test_file = patient_data.unmatched_files[0]
original_path = test_file.path
print(f" Original file: {test_file.filename}")
print(f" Original status: {test_file.status.value}")
# Manually assign file
success = project_manager.update_patient_file_assignment(
patient_data.patient_id,
original_path,
DataType.INTRAORAL_PHOTO
)
if success:
print(" ✅ Manual assignment successful")
# Update cache
analyzer.update_cache(patient_data)
print(" ✅ Cache update called")
# Check cache file again
if os.path.exists(cache_file):
file_size = os.path.getsize(cache_file)
print(f" Cache file size after update: {file_size} bytes")
# Test if manual assignment is preserved by reloading
print(f"\n6. Testing cache persistence...")
patient_data_2 = analyzer.analyze_patient_folder(patient_folder, use_cache=True)
# Look for the manually assigned file
manual_found = False
for file_data in patient_data_2.get_all_files():
if file_data.path == original_path:
print(f" Found file: {file_data.filename}")
print(f" Status: {file_data.status.value}")
print(f" Data type: {file_data.data_type.value if file_data.data_type else 'None'}")
if file_data.status == MatchStatus.MANUAL:
print(" ✅ Manual status preserved!")
manual_found = True
else:
print(" ❌ Manual status NOT preserved")
break
if not manual_found:
print(" ❌ Manually assigned file not found")
else:
print(" ❌ Manual assignment failed")
else:
print(f"\n5. No unmatched files to test manual assignment")
print(f"\nDiagnostic test completed!")
if __name__ == "__main__":
test_cache_diagnostic()