Skip to content

Commit

Permalink
Removed log at top of file
Browse files Browse the repository at this point in the history
  • Loading branch information
caparker committed Mar 28, 2024
1 parent 9b809d7 commit 9e9410b
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/adapters/ust-ist.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ const yesterday = DateTime.utc().minus({ days: 1 }).toISODate(); // format "YYYY
const stationsUrl = 'https://api.ust.is/aq/a/getStations';
const dataUrl = `https://api.ust.is/aq/a/getDate/date/${yesterday}`;

log.debug(yesterday);

/**
* Fetches air quality data for Iceland from a specific date and compiles it into a structured format.
*
*
* @param {Object} source - The source configuration object, including name and URL.
* @param {Function} cb - A callback function that is called with the final dataset or an error.
*/
Expand All @@ -36,20 +34,20 @@ export async function fetchData(source, cb) {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
pragma: "no-cache"
};
const allData = await client({ url: dataUrl, headers: headers});
const allData = await client({ url: dataUrl, headers: headers});
const allMeta = await client({ url: stationsUrl, headers: headers});
const stations = Object.keys(allData);

const measurements = stations.reduce((acc, stationId) => {
const stationData = allData[stationId];
const stationMeta = allMeta.find(s => s.local_id === stationData.local_id);

// Skip processing this station if metadata is missing
if (!stationMeta) {
console.warn(`Metadata missing for station ID: ${stationId}. Skipping...`);
return acc;
return acc;
}

const baseMeta = {
location: stationData.name,
city: stationMeta.municipality,
Expand All @@ -62,9 +60,9 @@ export async function fetchData(source, cb) {
url: source.sourceURL
}]
};

const latestMeasurements = parseParams(stationData.parameters);

return acc.concat(latestMeasurements.map(m => ({ ...baseMeta, ...m })));
}, []);
log.debug(measurements[0]);
Expand All @@ -73,7 +71,7 @@ export async function fetchData(source, cb) {
cb(e);
}
}


/**
* Parse object with parameters, each with a series of measurements.
Expand Down Expand Up @@ -102,18 +100,18 @@ export async function fetchData(source, cb) {
function parseParams(params) {
// Array with the valid parameters in the object
const validParams = Object.keys(params).filter(p => acceptableParameters.includes(p.toLowerCase().replace('.', '')));

return validParams.flatMap(p => {
const measurements = Object.keys(params[p])
.filter(key => !isNaN(parseInt(key))) // Filter out keys that are not indices
.map(index => {
const measurement = params[p][index];
const date = DateTime.fromFormat(measurement.endtime.trimEnd(), 'yyyy-LL-dd HH:mm:ss', { zone: 'Atlantic/Reykjavik' });

const resolution = params[p].resolution === '1h'
? { value: 1, unit: 'hours' }
: {};

return {
date: {
utc: date.toUTC().toISO({ suppressMilliseconds: true }),
Expand All @@ -125,8 +123,7 @@ function parseParams(params) {
averagingPeriod: resolution
};
});

return measurements;
});
}

0 comments on commit 9e9410b

Please sign in to comment.