prince1604 commited on
Commit
d7353b3
·
1 Parent(s): 19f9d48

Refined report structure: Ensure mutually exclusive separation of 'short_alt' vs 'poor_quality' (Generic/Filename) to correct double counting

Browse files
Files changed (1) hide show
  1. src/analyzer.py +33 -7
src/analyzer.py CHANGED
@@ -89,18 +89,44 @@ class ImageAnalyzer:
89
  poor_quality_images.append({'src': img['src'], 'alt': alt_text, 'reason': reason})
90
  total_poor_quality += 1
91
 
92
- # Separate short/sparse items for backward compatibility
93
- short_alt_images_legacy = [img for img in poor_quality_images if img['reason'].startswith("Too short") or img['reason'].startswith("Too few words")]
94
- total_short_alt_legacy += len(short_alt_images_legacy)
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  pages_report.append({
97
  "page_url": page_url,
98
  "missing_alt_count": len(missing_images),
99
- "poor_quality_count": len(poor_quality_images), # Total count of all poor quality
100
- "short_alt_count": len(short_alt_images_legacy), # Count only strictly short ones
101
  "images_without_alt": list(set(missing_images)),
102
- "images_with_poor_alt": poor_quality_images, # Contains ALL poor images
103
- "images_with_short_alt": short_alt_images_legacy # Contains ONLY short/sparse images
104
  })
105
 
106
  return {
 
89
  poor_quality_images.append({'src': img['src'], 'alt': alt_text, 'reason': reason})
90
  total_poor_quality += 1
91
 
92
+ # Split into mutually exclusive lists based on reason
93
+ # User requirement: "short_alt_count are not show sepratly bescue it show in poor_quality_count... remove and add in poor perfectly"
94
+ # We interpret this as requiring two distinct, non-overlapping sets.
95
 
96
+ non_overlapping_poor = []
97
+ non_overlapping_short = []
98
+
99
+ for img in poor_quality_images:
100
+ if img['reason'].startswith("Too short") or img['reason'].startswith("Too few words"):
101
+ non_overlapping_short.append(img)
102
+ else:
103
+ non_overlapping_poor.append(img)
104
+
105
+ # Update legacy counters (only adding strictly short ones to the legacy global count)
106
+ # But wait, should true "poor" ones be tracked globally too?
107
+ # The summary returned `total_poor_quality` which was everything.
108
+ # If we separate them, we should probably track them separately in summary too if possible,
109
+ # but for now we update the page level reporting as requested.
110
+
111
+ # Update global counters strictly based on the split
112
+ total_short_alt_legacy += len(non_overlapping_short)
113
+
114
+ # The 'total_poor_quality' global in summary currently counts EVERYTHING.
115
+ # If we want to maintain that consistency, we keep it as processed in loop.
116
+ # BUT user said "remove and add in poor perfectly" -> implies separation.
117
+ # Let's subtract the short ones from the global poor quality count for the SUMMARY as well?
118
+ # actually, `total_poor_quality` was just `+=1` in the loop for every hit.
119
+ # Let's adjust it to only count the non-overlapping poor ones.
120
+ total_poor_quality -= len(non_overlapping_short)
121
+
122
  pages_report.append({
123
  "page_url": page_url,
124
  "missing_alt_count": len(missing_images),
125
+ "poor_quality_count": len(non_overlapping_poor), # Mutually exclusive count
126
+ "short_alt_count": len(non_overlapping_short), # Mutually exclusive count
127
  "images_without_alt": list(set(missing_images)),
128
+ "images_with_poor_alt": non_overlapping_poor,
129
+ "images_with_short_alt": non_overlapping_short
130
  })
131
 
132
  return {