@@ -1046,7 +1046,6 @@ function readApiBaker(options = {}) {
10461046 fetch ( fileUrl )
10471047 . then ( response => {
10481048 if ( ! response . ok ) {
1049- // Try again with underscores if hyphens fail
10501049 const fallbackUrl = `precomputed/all_dts/${ location . replace ( / [ - \s ] / g, "_" ) } .json` ;
10511050 return fetch ( fallbackUrl ) . then ( fallbackResponse => {
10521051 if ( ! fallbackResponse . ok ) throw new Error ( 'Network response was not ok' ) ;
@@ -1284,24 +1283,31 @@ function readApiBaker(options = {}) {
12841283 let currentValue = 'N/A' ;
12851284 let nextValue = 'N/A' ;
12861285
1286+ // ...inside readApiBaker, after defining currentValue and nextValue for each plot...
1287+
12871288 if ( plot . param === "pm25" ) {
1288-
1289+ // For PM2.5, use 3-hour window logic for current and next values
1290+ currentValue = 'N/A' ;
1291+ nextValue = 'N/A' ;
12891292 for ( let i = 0 ; i < masterData . master_datetime . length ; i ++ ) {
12901293 const dtStr = masterData . master_datetime [ i ] ;
12911294 if ( ! dtStr ) continue ;
12921295 const forecastStart = new Date ( dtStr . replace ( ' ' , 'T' ) ) ;
12931296 const forecastEnd = new Date ( forecastStart . getTime ( ) + 3 * 60 * 60 * 1000 ) ;
1297+ // Current: is now within this 3-hour window?
12941298 if ( siteLocalNow >= forecastStart && siteLocalNow < forecastEnd ) {
12951299 currentValue = masterData [ plot . columns [ 0 ] . column ] [ i ] ;
12961300 }
1297-
1301+ // Next: is 1 hour from now within this 3-hour window?
12981302 const nextLocalDate = new Date ( siteLocalNow . getTime ( ) + 1 * 60 * 60 * 1000 ) ;
12991303 if ( nextLocalDate >= forecastStart && nextLocalDate < forecastEnd ) {
13001304 nextValue = masterData [ plot . columns [ 0 ] . column ] [ i ] ;
13011305 }
13021306 }
13031307 } else {
1304-
1308+ // For other species, match by hour
1309+ currentValue = 'N/A' ;
1310+ nextValue = 'N/A' ;
13051311 for ( let i = 0 ; i < masterData . master_datetime . length ; i ++ ) {
13061312 const dtStr = masterData . master_datetime [ i ] ;
13071313 if ( ! dtStr ) continue ;
@@ -1314,17 +1320,8 @@ function readApiBaker(options = {}) {
13141320 }
13151321 }
13161322 }
1317-
1318- for ( let i = 0 ; i < masterData . master_datetime . length ; i ++ ) {
1319- const dtStr = masterData . master_datetime [ i ] ;
1320- const hour = parseInt ( dtStr . slice ( 11 , 13 ) , 10 ) ;
1321- if ( hour === currentHour ) {
1322- currentValue = masterData [ plot . columns [ 0 ] . column ] [ i ] ;
1323- }
1324- if ( hour === nextHour ) {
1325- nextValue = masterData [ plot . columns [ 0 ] . column ] [ i ] ;
1326- }
1327- }
1323+
1324+ // Remove the extra for-loop that matches by hour for all species (it would overwrite the correct 3-hour logic for PM2.5)
13281325
13291326 if ( plot . displayAQI ) {
13301327 const currentAqi = currentValue ;
@@ -1712,21 +1709,21 @@ function generateMetricsHtml({
17121709 <div class="d-xvg">
17131710 <div class="xvg_aqi me-3">${ currentVal !== 'N/A' ? currentVal : '--' } </div>
17141711 <div class="xvg_aqi-change ${ change . class } ">${ change . arrow } ${ change . sign } ${ change . diff } (${ change . sign } ${ change . pct !== "N/A" ? change . pct + "%" : "--" } )</div>
1715- <div class="xvg_timestamp">Current AQI (US Scale): ${ formatTime ( currentIdx ) } </div>
1712+ <div class="xvg_timestamp">Current AQI (US Scale)}</div>
17161713 </div>
17171714
17181715 </div>
17191716
17201717 <div class="d-xvg">
17211718 <div class="xvg_aqi me-3">${ nextVal !== 'N/A' ? nextVal : '--' } </div>
17221719 <div class="xvg_aqi-change ${ nextChange . class } ">${ nextChange . arrow } ${ nextChange . sign } ${ nextChange . diff } (${ nextChange . sign } ${ nextChange . pct !== "N/A" ? nextChange . pct + "%" : "--" } )</div>
1723- <div class="xvg_timestamp">Next hour: ${ formatTime ( nextIdx ) } </div>
1720+ <div class="xvg_timestamp">Next hour</div>
17241721 </div>
17251722
17261723 <div class="d-xvg">
17271724 <div class="xvg_aqi me-3">${ prevVal !== 'N/A' ? prevVal : '--' } </div>
17281725 <div class="xvg_aqi-change ${ prevChange . class } ">${ prevChange . arrow } ${ prevChange . sign } ${ prevChange . diff } (${ prevChange . sign } ${ prevChange . pct !== "N/A" ? prevChange . pct + "%" : "--" } )</div>
1729- <div class="xvg_timestamp">Previous hour: ${ formatTime ( prevIdx ) } </div>
1726+ <div class="xvg_timestamp">Previous hour</div>
17301727 </div>
17311728 <div class="d-xvg">
17321729 <div class="xvg_aqi me-3">${ dailyAvg !== 'N/A' ? dailyAvg . toFixed ( 2 ) : '--' } </div>
0 commit comments