Skip to content

Commit

Permalink
wildlife services updates (#243)
Browse files Browse the repository at this point in the history
* wildlife services updates

* Fix code formatting

---------

Co-authored-by: Format Bot <format-bot@netsblox.org>
  • Loading branch information
dragazo and Format Bot authored May 30, 2024
1 parent 96e82c3 commit 49aec58
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 24 additions & 16 deletions src/procedures/movebank/movebank.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,27 @@ Movebank.getStudies = async function () {
}),
);

const split = (x) =>
x.split(",").map((x) => x.trim()).filter((x) => x.length);

const res = [];
for (const raw of data) {
if (
raw.id && raw.main_location_lat && raw.main_location_long &&
raw.citation && ALLOWED_LICENSE_TYPES[raw.license_type]
) {
res.push({
id: parseInt(raw.id),
latitude: parseFloat(raw.main_location_lat),
longitude: parseFloat(raw.main_location_long),
species: raw.taxon_ids.split(",").map((x) => x.trim()),
sensors: raw.sensor_type_ids.split(",").map((x) => x.trim()),
citation: raw.citation,
});
}
!raw.id || !raw.main_location_lat || !raw.main_location_long ||
!raw.citation || !ALLOWED_LICENSE_TYPES[raw.license_type]
) continue;

const species = split(raw.taxon_ids);
if (species.length === 0) continue;

res.push({
id: parseInt(raw.id),
latitude: parseFloat(raw.main_location_lat),
longitude: parseFloat(raw.main_location_long),
species,
sensors: split(raw.sensor_type_ids),
citation: raw.citation,
});
}
return res;
};
Expand All @@ -162,10 +168,12 @@ Movebank.getStudies = async function () {
*/
Movebank.getStudiesNear = async function (latitude, longitude, distance) {
const p = { latitude, longitude };
return (await Movebank.getStudies()).filter((x) =>
geolib.getDistance(p, { latitude: x.latitude, longitude: x.longitude }) <=
distance
);
const d = (x) =>
geolib.getDistance(p, { latitude: x.latitude, longitude: x.longitude });
return (await Movebank.getStudies()).filter((x) => d(x) <= distance).sort((
a,
b,
) => d(a) - d(b));
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/procedures/wildcam/wildcam.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const { DATA, SPECIES, CAMERAS } = (function () {
}

const DATA = Object.values(res);
DATA.sort((a, b) => +a.date - +b.date);
DATA.sort((a, b) => a.date === b.date ? 0 : a.date > b.date ? 1 : -1); // dates are now in yyyy/mm/dd string form

let SPECIES = new Set();
for (const entry of DATA) {
Expand Down

0 comments on commit 49aec58

Please sign in to comment.