Skip to content

Commit

Permalink
fixed datetime errors for tasmania (#1055)
Browse files Browse the repository at this point in the history
* fixed datetime errors for tasmania

* clean up

---------

Co-authored-by: Gabriel Fosse <kraken+majesticio@users.noreply.github.com>
  • Loading branch information
majesticio and Gabriel Fosse authored Aug 24, 2023
1 parent 43c2e1c commit b2f175d
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/adapters/tasmania.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function fetchData (source, cb) {
if (data === undefined) {
throw new Error('Failure to parse data.');
}

cb(null, data);
} catch (error) {
cb(error, { message: 'Unknown adapter error.' }, null);
Expand All @@ -38,13 +37,19 @@ const formatData = function (data, source) {
const date = DateTime.fromFormat(
string.trim(),
'HHmmss',
'Australia/Hobart'
{ zone: 'Australia/Hobart' }
);

if (!date.isValid) {
throw new Error('Invalid date format');
}

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

// manually retrieved list of station names
// new stations should be checked for naming on this map:
// http://epa.tas.gov.au/_layouts/15/Lightbox.aspx?url=http%3A%2F%2Fepa.tas.gov.au%2FAir%2FLive%2Flatest_air_data_on_map.jpg
Expand Down Expand Up @@ -101,15 +106,10 @@ const formatData = function (data, source) {

// loop through the csv rows
for (let k = 0; k < output.length; k++) {
// Station, hhmmss(AEST), PM2.5(ug/m^3), PM10(ug/m^3), lat(deg), long(degE), alt(m), Station name
const value = output[k];
const currentDate = value[1];

// Tasmania stations seem to use hhmmss = 999999 when the station
// is not available. check for and ignore these records
// also check the name matched in the locations list, otherwise this is a new station
const location = stations[value[0]];
if (currentDate === '999999' || location === 'undefined') {
if (currentDate === '999999' || location === undefined) {
continue;
}
const dates = parseDate(currentDate);
Expand All @@ -118,7 +118,6 @@ const formatData = function (data, source) {
const lat = value[4];
const lng = value[5];

// base obj for resuse
const baseObj = {
location: location,
city: source.city,
Expand All @@ -137,18 +136,17 @@ const formatData = function (data, source) {
date: dates,
};

// PM2.5 entry
const objPM25 = cloneDeep(baseObj);
objPM25.value = parseFloat(pm25);
objPM25.parameter = 'pm25';
measurements.push(objPM25);

// PM10 entry
const objPM10 = cloneDeep(baseObj);
objPM10.value = parseFloat(pm10);
objPM10.parameter = 'pm10';
measurements.push(objPM10);
}

measurements = convertUnits(flatten(measurements));
return {
name: 'unused',
Expand Down

0 comments on commit b2f175d

Please sign in to comment.