Skip to content
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

WIP: WPRDC data fetching function #83

Merged
merged 3 commits into from
Jan 27, 2017

Conversation

mbilker
Copy link
Collaborator

@mbilker mbilker commented Jan 27, 2017

This is a work in progress. Please comment, suggest changes, and criticisms.

This is for #17.

The idea is instead of duplicating the fetch() code for every request to WPRDC that a function makes all the calls and does the error handling (to be implemented).

Copy link
Contributor

@vonbearshark vonbearshark left a comment

Choose a reason for hiding this comment

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

This is fantastic. Exactly the kind of setup we need. I have some small changes, then we're good to merge

const WPRDC_QUERY_SUFFIX = '" ';

// Fetch data from West Pennsylvania Regional Data Center using the SQL API
function fetchWPRDCData(dataSourceName, options) {
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, we can set default JS params in ES6, like:

function fetchWPRDCData(dataSourceName, options={}) {

So we don't have to have the conditional after. We're being selective in what es6 features we use, so this is fine as is. Just FYI.

options = {};
}

console.group(`${dataSourceName} API`);
Copy link
Contributor

Choose a reason for hiding this comment

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

prune out all logging


records.forEach((record, i) => {
// TODO: Check browser compatability for `instanceof Function`
if (dataSource.processRecord instanceof Function) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can do without the instanceof check, and just check for the existence of the processRecord field. I can't think of a scenario when it wouldn't be a function

record.pin.addTo(map)
markers.push(record);
} else {
console.log('Found a null location!', record);
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll fix this with #61

const latLongNoNulls = latLong.some((field) => !!field);
if (latLongNoNulls) {
let title = null;
if (dataSource.title instanceof Function) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's assume that all datasets have a title and that it is a function.In fact, could you add this for the police and 311? It can be the field that you're using now for the display.

icon: dataSource.icon
});

if (dataSource.popup instanceof Function) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, with #79 we can assume that all datasets will have a function to generate the popup that can , so we don't have to have this check, I think.

html: '<i class="fa fa-commenting"></i>',
iconSize: [32, 32],
iconAnchor: [16, 32]
Promise.all([
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, this looks so clean

@mbilker
Copy link
Collaborator Author

mbilker commented Jan 27, 2017

I corrected everything but part of the dataSource.processRecord. It just checks for existence. The Library data source did not have custom processing before so I didn't add the function to the data source object.

Copy link
Contributor

@vonbearshark vonbearshark left a comment

Choose a reason for hiding this comment

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

Looks awesome! This is going to be a great help

@vonbearshark vonbearshark merged commit 42ce8e9 into pittcsc:master Jan 27, 2017
@mbilker mbilker deleted the data-call-function branch January 27, 2017 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants