mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 17:54:54 +00:00
Add Weather module with controller, service, and DTO for fetching weather details
This commit is contained in:
@ -465,7 +465,16 @@ export class ControllerRoute {
|
||||
'This endpoint retrieves the terms and conditions for the application.';
|
||||
};
|
||||
};
|
||||
static WEATHER = class {
|
||||
public static readonly ROUTE = 'weather';
|
||||
|
||||
static ACTIONS = class {
|
||||
public static readonly FETCH_WEATHER_DETAILS_SUMMARY =
|
||||
'Fetch Weather Details';
|
||||
public static readonly FETCH_WEATHER_DETAILS_DESCRIPTION =
|
||||
'This endpoint retrieves the current weather details for a specified location like temperature, humidity, etc.';
|
||||
};
|
||||
};
|
||||
static PRIVACY_POLICY = class {
|
||||
public static readonly ROUTE = 'policy';
|
||||
|
||||
|
||||
18
libs/common/src/util/calculate.aqi.ts
Normal file
18
libs/common/src/util/calculate.aqi.ts
Normal file
@ -0,0 +1,18 @@
|
||||
export function calculateAQI(pm2_5: number): number {
|
||||
const breakpoints = [
|
||||
{ pmLow: 0.0, pmHigh: 12.0, aqiLow: 0, aqiHigh: 50 },
|
||||
{ pmLow: 12.1, pmHigh: 35.4, aqiLow: 51, aqiHigh: 100 },
|
||||
{ pmLow: 35.5, pmHigh: 55.4, aqiLow: 101, aqiHigh: 150 },
|
||||
{ pmLow: 55.5, pmHigh: 150.4, aqiLow: 151, aqiHigh: 200 },
|
||||
{ pmLow: 150.5, pmHigh: 250.4, aqiLow: 201, aqiHigh: 300 },
|
||||
{ pmLow: 250.5, pmHigh: 500.4, aqiLow: 301, aqiHigh: 500 },
|
||||
];
|
||||
|
||||
const bp = breakpoints.find((b) => pm2_5 >= b.pmLow && pm2_5 <= b.pmHigh);
|
||||
if (!bp) return pm2_5 > 500.4 ? 500 : 0; // Handle out-of-range values
|
||||
|
||||
return Math.round(
|
||||
((bp.aqiHigh - bp.aqiLow) / (bp.pmHigh - bp.pmLow)) * (pm2_5 - bp.pmLow) +
|
||||
bp.aqiLow,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user