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

Assignment 4 - LI #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
19 changes: 11 additions & 8 deletions lab/lab1/part1.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Is printMenu a function? Answer this question with underscore. Should evaluate
to true.
===================== */

var query1;
var query1 = _.isFunction(printMenu);

console.log('printMenu is a function:', query1);

Expand All @@ -72,7 +72,7 @@ Is bakedGoods an array? Answer this question with underscore. Should evaluate
to true.
===================== */

var query2;
var query2 = _.isArray(bakedGoods);

console.log('bakedGoods is an array:', query2);

Expand All @@ -81,39 +81,42 @@ Is the first element in bakedGoods an object? Answer this question with
underscore. Should evaluate to true.
===================== */

var query3;
var query3 = _.isObject(bakedGoods[0]);

console.log('The first element in bakedGoods is an object:', query3);

/* =====================
Use _.where to return all cakes. Or bread. Whichever is your favorite.
===================== */

var query4;
var query4 = _.where(bakedGoods, {"type":"Cake"}) ;

console.log('All bread. Or cakes:', query4);

/* =====================
Use _.filter to return all baked goods that cost more than $4.
===================== */

var query5;
var query5 = _.filter(bakedGoods, function(good){
return good['price']>4
});

console.log('More than $4:', query5);

/* =====================
Use _.sortBy to order the list by inventory (from lowest to highest).
===================== */

var query6;

var query6=_.sortBy(bakedGoods,function(good){
return good['inventory']
});
console.log('Sorted by inventory (lowest to highest):', query6);

/* =====================
Use _.groupBy to organize the baked goods by type.
===================== */

var query7;
var query7=_.groupBy(bakedGoods,'type');

console.log('Grouped by type:', query7);

Expand Down
18 changes: 16 additions & 2 deletions lab/lab2/js/part1-ajax-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ console.log("fizzbuzz success:",
It will just log undefined to the console.

===================== */
var phillySolarInstallationDataUrl = "https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-solar-installations.json";
var phillyCrimeDataUrl = "https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-crime-snippet.json";
//var phillySolarInstallationDataUrl = "https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-solar-installations.json";
//var phillyCrimeDataUrl = "https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-crime-snippet.json";
var phillyBikeCrashesDataUrl = "https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-bike-crashes-snippet.json";


Expand All @@ -103,6 +103,20 @@ var phillyBikeCrashesDataUrl = "https://raw.githubusercontent.com/CPLN692-MUSA61
Remember to call all code within the function body. Use console.log to make sure
that this step is completed before moving on!
===================== */
var dataDownload= $.ajax({
url: "https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-bike-crashes-snippet.json",
})
.done(function( msg ) {
console.log('in it');
//alert( "Data Saved: " + msg );
var parseData = JSON.parse(msg);
console.log(parseData);
var layerGroup = L.featureGroup().addTo(map);
plotMap = (dataDownload) => _.forEach(dataDownload, function(x){
L.marker([x.lat_final, x.long_final]).addTo(layerGroup);});
plotMap(parseData);
});
console.log('out of it');


/* =====================
Expand Down
37 changes: 31 additions & 6 deletions lab/lab2/js/part2-app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,29 @@
===================== */

// We set this to HTTP to prevent 'CORS' issues
var downloadData = $.ajax("http://");
/*
var downloadData = $.ajax("https://");
var parseData = function() {};
var makeMarkers = function() {};
var plotMarkers = function() {};


*/

var downloadData= $.ajax("https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-bike-crashes-snippet.json");
var parseData = function(webdata) {
return JSON.parse(webdata);
};
var makeMarkers = function(crashdata) {
var markers = [];
_.each(crashdata, function(obj){
markers.push(L.marker([obj.lat_final, obj.long_final]));
});
return markers;
};
var plotMarkers = function(markers) {
_.each(markers, function(marker){
marker.addTo(map);
});
};
/* =====================
Define the function removeData so that it clears the markers you've written
from the map. You'll know you've succeeded when the markers that were
Expand All @@ -52,9 +69,17 @@ var plotMarkers = function() {};
In real applications, this will typically happen in response to changes to the
user's input.
===================== */

var removeMarkers = function() {};

var removeMarkers = function(markers) {
_.each(markers, function(marker){
map.removeLayer(marker);
});
};
//removeMarkers(parseData);
/*
var removeMarkers = function(condition) {
map.removeLayer(marker);
};
removeMarkers(parseData);*/
/* =====================
Optional, stretch goal
Write the necessary code (however you can) to plot a filtered down version of
Expand Down
49 changes: 46 additions & 3 deletions lab/lab2/js/part3-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
Define a resetMap function to remove markers from the map and clear the array of markers
===================== */
var resetMap = function() {
_.each(markers, function(marker){
map.removeLayer(marker);
});
/* =====================
Fill out this function definition
===================== */
Expand All @@ -38,18 +41,58 @@ var resetMap = function() {
will be called as soon as the application starts. Be sure to parse your data once you've pulled
it down!
===================== */
var getAndParseData = function() {
var bikeCrashPhillyUrl = "https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-bike-crashes-snippet.json";

/* =====================
Fill out this function definition
===================== */
};

// its essential to define mydata out of the scope of ajax function below
var mydata;
var getAndParseData = function() {
bikedata=$.ajax(bikeCrashPhillyUrl)
.done(function(bikedata){
mydata=JSON.parse(bikedata);
console.log(mydata);
console.log('done?');
});
};
console.log(mydata);//????????not defined```
/*
var myfilter=[]; //filter year, police agc and dringking or not
_.each(mydata, function(crash){
if(crash.CRASH_YEAR>=numericField1&&
crash.CRASH_YEAR<=numericField2 &&
crash.POLICE_AGC== stringField &&
(crash.DRINKING_D==1)==booleanField) {
myfilter.push(crash);
} return myfilter;
}); //NOT ABLE TO ACCESS mydata...


/* =====================
Call our plotData function. It should plot all the markers that meet our criteria (whatever that
criteria happens to be — that's entirely up to you)
===================== */

//filter year, police agc and dringking or not

var myfilter =function (crash){
var myfilter=[];
_.each(mydata, function(crash){
if(crash.CRASH_YEAR>=numericField1&&
crash.CRASH_YEAR<=numericField2 &&
crash.POLICE_AGC== stringField &&
(crash.DRINKING_D==1)==booleanField) {
myfilter.push(crash);
}return myfilter})}; //The filter does not seem to work */


var plotData = function() {
markers=_.each(mydata, function(x){
L.marker([x.lat_final,x.long_final]).addTo(map).bindPopup(x.DRINKING_D);
});
};
/* =====================
Fill out this function definition
===================== */
};