Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 68 additions & 18 deletions app/config/dataSource.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,77 @@
exports.internal = {
supplies: 'supplies',
staff: 'staff',
food: 'food',
water: 'water',
energyFuel: 'energy or fuel',
medical: 'medical',
openSpace: 'open space',
shelter: 'shelter',
supplies: 'supplies',
staff: 'staff',
food: 'food',
water: 'water',
energyFuel: 'energy or fuel',
medical: 'medical',
openSpace: 'open space',
shelter: 'shelter',
};

exports.external = {
/* --- SF Open Data --- */
communityResiliencyIndicators: 'https://data.sfgov.org/resource/wsj2-27m9.json',
communityResiliencyIndicators: {
url: "https://data.sfgov.org/resource/wsj2-27m9.json",
modifyDataset: dataset => {
// do something here as needed
return dataset;
}
},
/* --- SF Open Data Markers --- */
privatelyOwnedPublicOpenSpaces: 'https://data.sfgov.org/resource/3ub7-d4yy.geojson?$where=the_geom IS NOT NULL',
parksAndOpenSpaces: 'https://data.sfgov.org/resource/94uf-amnx.geojson?$where=location_1 IS NOT NULL',
schools: 'https://data.sfgov.org/resource/mmsr-vumy.geojson?$where=location_1 IS NOT NULL',
privatelyOwnedPublicOpenSpaces: {
url: "https://data.sfgov.org/resource/3ub7-d4yy.geojson",
query:
"$query=SELECT name AS title, descriptio AS description, the_geom WHERE the_geom IS NOT NULL",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works and eliminates the need for author: 'DataSF'.

query: '$query=SELECT name AS title, "DataSF" as author, descriptio AS description, the_geom WHERE the_geom IS NOT NULL'

author: "DataSF"
},
parksAndOpenSpaces: {
url: "https://data.sfgov.org/resource/94uf-amnx.geojson",
query:
"$query=SELECT parkid AS _id, parktype AS description, parkname AS name, location_1 WHERE location_1 IS NOT NULL",
author: "DataSF"
},
schools: {
url: "https://data.sfgov.org/resource/mmsr-vumy.geojson",
query:
"$query=SELECT location_1, campus_name AS name, campus_address AS description, county_fips AS _id WHERE location_1 IS NOT NULL",
author: "DataSF"
},
// very large, nation-wide data set, need to limit what's returned
businesses: 'https://data.sfgov.org/resource/vbiu-2p9h.geojson?$where=location IS NOT NULL',
cityFacilities: 'https://data.sfgov.org/resource/i5wr-crji.geojson?$where=geom IS NOT NULL',
healthCareFacilities: 'https://data.sfgov.org/resource/sci7-7q9i.geojson?$where=location IS NOT NULL',
pitStops: 'https://data.sfgov.org/resource/snkr-6jdf.geojson?$where=geom IS NOT NULL',
businesses: {
url: "https://data.sfgov.org/resource/vbiu-2p9h.geojson",
query:
"$query=SELECT * WHERE location IS NOT NULL AND city = 'San Francisco'",
author: "DataSF"
},
cityFacilities: {
url: "https://data.sfgov.org/resource/i5wr-crji.geojson",
query:
"$query=SELECT facility_id AS _id, common_name AS name, address AS description, geom WHERE geom IS NOT NULL",
author: "DataSF"
},
healthCareFacilities: {
url: "https://data.sfgov.org/resource/sci7-7q9i.geojson",
query:
"$query=SELECT uid AS _id, facility_name AS name, facility_type, location AS description WHERE location IS NOT NULL",
author: "DataSF"
},
pitStops: {
url: "https://data.sfgov.org/resource/snkr-6jdf.geojson",
query:
"$query=SELECT id AS _id, location AS name, facilitytype AS description, geom WHERE geom IS NOT NULL",
author: "DataSF"
},
/* --- SF Open Data Regions --- */
seismicHazardZones: 'https://data.sfgov.org/resource/t2cc-dy6b.geojson?$where=the_geom IS NOT NULL',
neighborhoods: 'https://data.sfgov.org/resource/6ia5-2f8k.geojson?$where=the_geom IS NOT NULL',
seismicHazardZones: {
url: "https://data.sfgov.org/resource/t2cc-dy6b.geojson",
query: "$query=SELECT id AS _id, the_geom WHERE the_geom IS NOT NULL",
author: "DataSF"
},
neighborhoods: {
url: "https://data.sfgov.org/resource/6ia5-2f8k.geojson",
query:
"$query=SELECT the_geom, name, link AS description WHERE the_geom IS NOT NULL",
author: "DataSF"
}
};
7 changes: 5 additions & 2 deletions app/repositories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const geojson = require('geojson');
const Marker = require('../models/marker.js');
const mapDatasets = require('../config/mapDatasets');
const { internal, external } = require('../config/dataSource');
const addAuthor = require("../utilities/addAuthor");

async function getAll() {
const datasets = await mapDatasets; // simulated db call
Expand All @@ -25,10 +26,12 @@ async function getById(mapDataset) {

async function fetchById(mapDataset) {
try {
const response = await fetch(external[mapDataset]);
const response = await fetch(`${external[mapDataset].url}?${external[mapDataset].query}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires query to be defined on all the external datasets. We can run can JavaScript inside curly braces.

const response = await fetch(`${external[mapDataset].url}?${external[mapDataset].query || ''}`);

const dataset = await response.json();

return dataset;
const modifiedDataset = addAuthor(dataset, external[mapDataset].author);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If each dataset needs to be modified differently this might be a better choice.

return external[mapDataset].modifyDataset
      ? external[mapDataset].modifyDataset(dataset)
      : dataset;


return modifiedDataset;
} catch (error) {
throw new Error(error);
}
Expand Down
8 changes: 8 additions & 0 deletions app/utilities/addAuthor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function addAuthor(dataset, author) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the modified query string I don't think we'll need this function with the current external datasets.

dataset.features.map(feature => {
feature.properties.author = author;
});
return dataset;
}

module.exports = addAuthor;