-
Notifications
You must be signed in to change notification settings - Fork 6
External sources data cleaning #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
66ee3f5
e3c0eaf
02b488a
bbd22b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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", | ||
| 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" | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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}`); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requires const response = await fetch(`${external[mapDataset].url}?${external[mapDataset].query || ''}`); |
||
| const dataset = await response.json(); | ||
|
|
||
| return dataset; | ||
| const modifiedDataset = addAuthor(dataset, external[mapDataset].author); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| function addAuthor(dataset, author) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the modified |
||
| dataset.features.map(feature => { | ||
| feature.properties.author = author; | ||
| }); | ||
| return dataset; | ||
| } | ||
|
|
||
| module.exports = addAuthor; | ||
There was a problem hiding this comment.
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'.