@@ -36,20 +36,35 @@ def consolidate_criteria_daily_for_year(year: str, transform_dir: Path) -> pd.Da
3636 Returns:
3737 Consolidated DataFrame with criteria daily fact data
3838 """
39- # Read the transformed data for this year
40- input_file = transform_dir / f"aqi_aqs_daily_{ year } .csv"
41- if not input_file .exists ():
42- print (f"⚠️ No AQI daily file found for year { year } : { input_file } " )
39+ # Find all transformed data files matching the pattern for this year
40+ pattern = f"*aqi*{ year } .csv"
41+ matching_files = list (transform_dir .glob (pattern ))
42+
43+ if not matching_files :
44+ print (f"⚠️ No AQI daily files found for year { year } matching pattern: { pattern } " )
4345 return pd .DataFrame ()
4446
45- try :
46- df = pd .read_csv (input_file )
47- except Exception as e :
48- print (f"❌ Error reading { input_file } : { e } " )
47+ print (f" 📂 Found { len (matching_files )} file(s) matching pattern for { year } " )
48+
49+ dfs = []
50+ for input_file in matching_files :
51+ try :
52+ file_df = pd .read_csv (input_file )
53+ print (f" ✓ Read { len (file_df )} records from { input_file .name } " )
54+ dfs .append (file_df )
55+ except Exception as e :
56+ print (f"❌ Error reading { input_file } : { e } " )
57+ continue
58+
59+ if not dfs :
60+ print (f"⚠️ No files were successfully read for year { year } " )
4961 return pd .DataFrame ()
50-
62+
63+ # Combine all dataframes
64+ df = pd .concat (dfs , ignore_index = True )
65+
5166 if df .empty :
52- print (f"⚠️ Empty AQI daily file for year { year } " )
67+ print (f"⚠️ All combined files are empty for year { year } " )
5368 return pd .DataFrame ()
5469
5570 # Define the required columns for fct_criteria_daily fact table
0 commit comments