Skip to content

Commit

Permalink
Fix data sources and adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Fosse committed Nov 22, 2023
1 parent 93496c7 commit b5c38ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

Changes to adapters will be documented in this file.
## 11/22/2023
### Set active: false
- south-australia-epa (needs fix, url won't resolve)

## 11/01/2023
### DELETED
Expand Down
19 changes: 11 additions & 8 deletions src/adapters/buenos-aires.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function fetchData(source, callback) {
.map(function (i, el) {
return {
id: $(this).attr('value'),
name: $(this).text()
name: $(this).text(),
};
})
.get();
Expand All @@ -48,12 +48,12 @@ export function fetchData(source, callback) {
.map(function (i, el) {
return {
id: $(this).attr('value'),
name: $(this).text()
name: $(this).text(),
};
})
.get();

const today = DateTime.local().setZone(timezone).startOf('day');
const today = DateTime.now().setZone(timezone).startOf('day');
stations.forEach((station) => {
parameters.forEach((parameter) => {
const url = makeStationQuery(
Expand All @@ -75,10 +75,9 @@ export function fetchData(source, callback) {

results = flattenDeep(results);
results = convertUnits(results);

return callback(null, {
name: 'unused',
measurements: results
measurements: results,
});
});
})
Expand Down Expand Up @@ -151,7 +150,11 @@ const formatData = (body, station, parameter, today) => {

const getDate = (today, hours) => {
let date = DateTime.fromISO(today, { zone: timezone });
// If hours are from 13 to 23, the date should be set to the day before yesterday
if (hours >= 13 && hours <= 23) {
date = date.minus({ days: 2 });
} else if (hours >= 0 && hours <= 12) {
// If hours are from 00 to 12, the date should be set to yesterday
date = date.minus({ days: 1 });
}
date = date.set({ hour: hours });
Expand All @@ -166,17 +169,17 @@ const getCoordinates = (station) => {
case 'CENTENARIO':
return {
longitude: -58.43194,
latitude: -34.60638
latitude: -34.60638,
};
case 'CORDOBA':
return {
longitude: -58.39165,
latitude: -34.60441667
latitude: -34.60441667,
};
case 'LA BOCA':
return {
longitude: -58.36555,
latitude: -34.62527
latitude: -34.62527,
};
default:
break;
Expand Down
19 changes: 13 additions & 6 deletions src/adapters/stateair.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
/**
* This code is responsible for implementing all methods related to fetching
* and returning data for the SateAir data sources.
*/

'use strict';

import { convertUnits } from '../lib/utils.js';

import client from '../lib/requests.js';

import _ from 'lodash';
import { DateTime } from 'luxon';
import { load } from 'cheerio';
import { parallel } from 'async';

export const name = 'stateair';

export async function fetchData (source, cb) {
export async function fetchData(source, cb) {
// Generic fetch function
const getData = async (url, done) => {
try {
Expand Down Expand Up @@ -121,7 +126,7 @@ const formatData = function (data) {
case 'Kabul':
return 'Asia/Kabul';
case 'Dharan':
return 'Asia/Aden';
return 'Asia/Riyadh';
case 'Ashgabat':
return 'Asia/Ashgabat';
case 'Guatemala City':
Expand All @@ -147,14 +152,16 @@ const formatData = function (data) {
return 'Africa/Accra';
}
};

const date = DateTime.fromFormat(
dateString,
'yyyy-MM-dd HH:mm:ss',
getTZ(location)
{ zone: getTZ(location) }
);

return {
utc: date.toUTC().toISO({ suppressMilliseconds: true }),
local: date.toISO({ suppressMilliseconds: true })
local: date.toISO({ suppressMilliseconds: true }),
};
};

Expand Down Expand Up @@ -431,7 +438,7 @@ const formatData = function (data) {
const location = $('channel').children('title').text().trim();
const baseObj = {
location: 'US Diplomatic Post: ' + location,
parameter: parameter,
parameter,
unit: parameter === 'pm25' ? 'µg/m³' : 'ppb',
averagingPeriod: { value: 1, unit: 'hours' },
attribution: [
Expand Down
2 changes: 1 addition & 1 deletion src/sources/au.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"[email protected]"
],
"license": "Creative Commons Attribution 4.0 License. © Copyright 2023",
"active": true
"active": false
},
{
"url": "https://www.data.act.gov.au/api/id/94a5-zqnn.json",
Expand Down

0 comments on commit b5c38ba

Please sign in to comment.