@@ -193,58 +193,66 @@ private String resolveAttendanceKey(String teamName, String shortName) {
193193 */
194194 private String resolveFuzzyAttendanceKey (String teamName , String shortName ) {
195195 if (teamsByNormalizedName .isEmpty ()) {
196+ log .debug ("No attendance data available for fuzzy matching" );
196197 return null ;
197198 }
198199
200+ log .debug ("Attempting fuzzy match for team: '{}' (short: '{}')" , teamName , shortName );
201+
199202 String fuzzyTeamName = teamName != null ? normalizeForFuzzyMatch (teamName ) : null ;
200203 String fuzzyShortName = (shortName != null && !shortName .equals (teamName ))
201204 ? normalizeForFuzzyMatch (shortName )
202205 : null ;
203206
207+ log .debug ("Fuzzy normalized: '{}' / '{}'" , fuzzyTeamName , fuzzyShortName );
208+
204209 int bestDistance = Integer .MAX_VALUE ;
205210 String bestMatchKey = null ;
211+ double bestSimilarity = 0.0 ;
206212
207213 for (String storedKey : teamsByNormalizedName .keySet ()) {
208214 String storedNormalized = normalizeForFuzzyMatch (storedKey );
215+ int distance = Integer .MAX_VALUE ;
209216
210217 // Try distance with full team name
211218 if (fuzzyTeamName != null && !fuzzyTeamName .isEmpty ()) {
212- int distance = levenshteinDistance (fuzzyTeamName , storedNormalized );
213- if (distance < bestDistance ) {
214- bestDistance = distance ;
215- bestMatchKey = storedKey ;
219+ int d = levenshteinDistance (fuzzyTeamName , storedNormalized );
220+ if (d < distance ) {
221+ distance = d ;
216222 }
217223 }
218224
219225 // Try distance with short team name as well
220226 if (fuzzyShortName != null && !fuzzyShortName .isEmpty ()) {
221- int distance = levenshteinDistance (fuzzyShortName , storedNormalized );
222- if (distance < bestDistance ) {
223- bestDistance = distance ;
224- bestMatchKey = storedKey ;
227+ int d = levenshteinDistance (fuzzyShortName , storedNormalized );
228+ if (d < distance ) {
229+ distance = d ;
225230 }
226231 }
232+
233+ if (distance < bestDistance ) {
234+ bestDistance = distance ;
235+ bestMatchKey = storedKey ;
236+ int maxLength = Math .max (
237+ fuzzyTeamName != null ? fuzzyTeamName .length () : 0 ,
238+ storedNormalized .length ()
239+ );
240+ bestSimilarity = maxLength > 0 ? 1.0 - (double ) distance / maxLength : 0.0 ;
241+ log .debug (" Candidate '{}' (normalized: '{}') - distance: {}, similarity: {:.2f}" ,
242+ storedKey , storedNormalized , distance , bestSimilarity );
243+ }
227244 }
228245
229246 // Only accept match if similarity is above threshold (80%)
230- // Calculate based on the longer of the two strings being compared
231- if (bestMatchKey != null ) {
232- String storedNormalized = normalizeForFuzzyMatch (bestMatchKey );
233- int maxLength = Math .max (
234- fuzzyTeamName != null ? fuzzyTeamName .length () : 0 ,
235- storedNormalized .length ()
236- );
237-
238- if (maxLength > 0 ) {
239- double similarity = 1.0 - (double ) bestDistance / maxLength ;
240- if (similarity >= 0.80 ) {
241- log .debug ("Fuzzy matched team '{}' to '{}' with similarity {}" ,
242- teamName , storedNormalized , String .format ("%.2f" , similarity * 100 ));
243- return bestMatchKey ;
244- }
245- }
247+ if (bestMatchKey != null && bestSimilarity >= 0.80 ) {
248+ log .debug ("Fuzzy matched team '{}' to '{}' with similarity {:.2f}%" ,
249+ teamName , bestMatchKey , bestSimilarity * 100 );
250+ return bestMatchKey ;
246251 }
247252
253+ if (bestMatchKey != null ) {
254+ log .debug ("Best fuzzy match '{}' has similarity {:.2f}% (below 80% threshold)" , bestMatchKey , bestSimilarity * 100 );
255+ }
248256 return null ;
249257 }
250258
0 commit comments