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

HW3 - Buckler #17

Open
wants to merge 5 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
18 changes: 15 additions & 3 deletions lab/lab1/part1-array-access.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
===================== */

var map = L.map('map', {
center: [39.9522, -75.1639],
zoom: 14
center: [40.023341, -75.321082],
zoom: 12
});

var Stamen_TonerLite = L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}.{ext}', {
Expand All @@ -75,9 +75,21 @@

===================== */

let restaurantData = [[40.002452, -75.274564, "Restaurant 1"], [40.023341, -75.321082, "Restaurant 2"], [40.083424, -75.405699, "Restaurant 3"]];

let addMarker = (obj) => {return L.marker([obj[0], obj[1]]).bindPopup(obj[2]).addTo(map)};

/*for(let i =0; i < restaurantData.length; i++) {
addMarker(restaurantData[i]).addTo(map);
}*/

restaurantData.forEach(addMarker);


/*restaurantData.forEach(addMarker().addTo(map));
L.marker([0, 0]).addTo(map);
L.marker([0, 0]).addTo(map);
L.marker([0, 0]).addTo(map);
L.marker([0, 0]).addTo(map); */

/* =====================

Expand Down
7 changes: 6 additions & 1 deletion lab/lab1/part2-fizzbuzz.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
Start code

===================== */

for (let i = 1; i <= 100; i++) {
if(i%3===0 & i%5 ===0) {console.log('FizzBuzz');}
else if (i%3 === 0) {console.log('Fizz');}
else if (i%5 === 0) {console.log('Buzz');}
else {console.log(i)};
}


/* =====================
Expand Down
46 changes: 38 additions & 8 deletions lab/lab1/part3-data-transformation.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<!DOCTYPE html>
<head>
<!--stylesheet imports-->
<link rel="stylesheet" href="leaflet.css" />
Expand All @@ -13,8 +13,8 @@

<!--javascript imports-->
<script src="leaflet.js"></script>
<script src="part4-data-clean.js"></script>
<script src="part4-data-dirty.js"></script>
<script src="part3-data-clean.js"></script>
<script src="part3-data-dirty.js"></script>

<script>

Expand Down Expand Up @@ -62,16 +62,43 @@
if their formatting is especially wrong. But it should accommodate most points.

===================== */

var data = bikeArrayClean;
var raw = bikeArrayDirty;

let data = [];

let cleaning = (obj) => {
console.log(obj);
temp = [];
if(obj[0].includes("-7")) {
n = 0
} else {n=1};
temp.push(obj[n], obj[n+1]);
if(typeof obj[n+2] === 'string') {
if(!obj[n+2].includes('stations')) {
Copy link
Member

Choose a reason for hiding this comment

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

The solution I pointed you earlier ---

basically does a loop in a loop to check every single entry. And checks to see if they are numbers doing something similar to what you've done. You have a pretty good solution here - if you really want additional feedback we can try to call @moradology (this is in reference to @bucklerd s comment on the pull request if there is a better way to do this bike data cleaning.

temp.push(obj[n+2]);
} else {temp.push("");};
if(obj[n+2].includes('stations')) {
temp.push(obj[n+2].substr(0,2));
} else if (typeof obj[n+3] === 'string') {
temp.push(obj[n+3].substr(0,2));
} else {temp.push("")};
data.push(temp);
}
};

bikeArrayDirty.forEach(cleaning);


//var data = bikeArrayClean;

/* =====================

Start code to filter data

===================== */


let dataFiltered = [];
let filter = (obj) => {if(obj[3] > 20) {dataFiltered.push(obj)}}
data.forEach(filter);

/* =====================

Expand All @@ -97,7 +124,10 @@
Start code to add markers to map

===================== */

let addMarker = (obj) => {
L.marker([obj[1], obj[0]]).addTo(map);
}
dataFiltered.forEach(addMarker);


/* =====================
Expand Down
18 changes: 16 additions & 2 deletions lab/lab1/part4-project-euler.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,22 @@
Start code

===================== */


let sum = 0;
for(let i = 1; i < 1000; i++) {
if(i%3===0 | i%5===0) {sum = sum + i;};
}
console.log('Sum = ' + sum)

let sum2 = 0;
let j = [1, 1];
for(let i=1; i < 4000000; i = j[0] + j[1]) {
if(i%2===0) {sum2 = sum2 + i};
j[0] = j[1];
j[1] = i;
//console.log("i " + i + ' j ' +j);

}
console.log('Sum2 = ' + sum2)

/* =====================

Expand Down
16 changes: 8 additions & 8 deletions lab/lab2/part1.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,62 +18,62 @@ console.log('Nathan\'s list', nathanGameList);
What is the first game in Ross's list?
===================== */

var query1;
var query1 = _.first(rossGameList);

console.log('What is the first game in Ross\'s list?', query1);

/* =====================
What are all of the games except for the first game in ross's list?
===================== */

var query2;
var query2 = _.rest(rossGameList);

console.log('What are all of the games except for the first game in Ross\'s list?', query2);

/* =====================
What is the last game in Nathan's list?
===================== */

var query3;
var query3 = _.last(nathanGameList);

console.log('What is the last game in Nathan\'s list?', query3);

/* =====================
What are all of the games in Nathan's list except for the last?
===================== */

var query4;
var query4 = _.initial(nathanGameList);

console.log('What are all of the games in Nathan\'s list except for the last?', query4);

/* =====================
What would Nathan's game list look like if he sold "catan"?
===================== */

var query5;
var query5 = _.without(nathanGameList, 'catan');

console.log('What would Nathan\'s game list look like if he sold "catan"?', query5);

/* =====================
If Nathan and Ross play a board game, what are their options? This should be a list of all games owned by ross or Nathan, with no duplicates.
===================== */

var query6;
var query6 = _.union(rossGameList, nathanGameList);

console.log('If Nathan and Ross play a board game, what are their options? This should be a list of all games owned by ross or Nathan, with no duplicates.', query6);

/* =====================
Which games are owned by both Ross and Nathan?
===================== */

var query7;
var query7 = _.intersection(rossGameList, nathanGameList);

console.log('Which games are owned by both Ross and Nathan', query7);

/* =====================
Which games are exclusive to collections? In other words, only owned by either Ross or Nathan.
===================== */

var query8;
var query8 = _.difference(rossGameList, nathanGameList);
Copy link
Member

Choose a reason for hiding this comment

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

difference is insufficient here to capture the games that Nathan has that Ross does not have.


console.log('Which games are exclusive to one collection? In other words, only owned by either Ross or Nathan (but not both!).', query8);
6 changes: 3 additions & 3 deletions lab/lab2/part3.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Let's revisit the bike share data from Week 2 Lab 1, Part 4. Remember, each arra

We're especially interested in number 4: number of bike share docks at the station.

Using underscore functions, generate a list of all bike share docks that are greater than 20. One way to do
Using underscore functions, generate a list of all bike share docks that are greater than 20. One way to do
this is by using _.filter, but you can try other solutions as well. Set your answer to variable "largeStationList".

## Task 2
Expand All @@ -25,6 +25,6 @@ by using _.countBy and set your answer to variable "largeStationCount".

var data = bikeArrayClean;

var largeStationList;
var largeStationList = _.filter(bikeArrayClean, function(obj){return obj[3] > 20; });

var largeStationCount;
var largeStationCount = _.countBy(bikeArrayClean, function(obj2) {return obj2[3] > 20 ? 1: 0;});
87 changes: 48 additions & 39 deletions lab/lab2/part4-underscore-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,79 +32,88 @@


// clean data
for (var i = 0; i < schools.length - 1; i++) {
// If we have '19104 - 1234', splitting and taking the first (0th) element
// as an integer should yield a zip in the format above
if (typeof schools[i].ZIPCODE === 'string') {
split = schools[i].ZIPCODE.split(' ');
let zipSplit = (obj) => {
if (typeof obj.ZIPCODE === 'string') {
split = obj.ZIPCODE.split(' ');
normalized_zip = parseInt(split[0]);
schools[i].ZIPCODE = normalized_zip;
obj.ZIPCODE = normalized_zip;
}



// If we have '19104 - 1234', splitting and taking the first (0th) element
// as an integer should yield a zip in the format above


// Check out the use of typeof here — this was not a contrived example.
// Someone actually messed up the data entry
if (typeof schools[i].GRADE_ORG === 'number') { // if number
schools[i].HAS_KINDERGARTEN = schools[i].GRADE_LEVEL < 1;
schools[i].HAS_ELEMENTARY = 1 < schools[i].GRADE_LEVEL < 6;
schools[i].HAS_MIDDLE_SCHOOL = 5 < schools[i].GRADE_LEVEL < 9;
schools[i].HAS_HIGH_SCHOOL = 8 < schools[i].GRADE_LEVEL < 13;
if (typeof obj.GRADE_ORG === 'number') { // if number
obj.HAS_KINDERGARTEN = obj.GRADE_LEVEL < 1;
obj.HAS_ELEMENTARY = 1 < obj.GRADE_LEVEL < 6;
obj.HAS_MIDDLE_SCHOOL = 5 < obj.GRADE_LEVEL < 9;
obj.HAS_HIGH_SCHOOL = 8 < obj.GRADE_LEVEL < 13;
} else { // otherwise (in case of string)
schools[i].HAS_KINDERGARTEN = schools[i].GRADE_LEVEL.toUpperCase().indexOf('K') >= 0;
schools[i].HAS_ELEMENTARY = schools[i].GRADE_LEVEL.toUpperCase().indexOf('ELEM') >= 0;
schools[i].HAS_MIDDLE_SCHOOL = schools[i].GRADE_LEVEL.toUpperCase().indexOf('MID') >= 0;
schools[i].HAS_HIGH_SCHOOL = schools[i].GRADE_LEVEL.toUpperCase().indexOf('HIGH') >= 0;
obj.HAS_KINDERGARTEN = obj.GRADE_LEVEL.toUpperCase().indexOf('K') >= 0;
obj.HAS_ELEMENTARY = obj.GRADE_LEVEL.toUpperCase().indexOf('ELEM') >= 0;
obj.HAS_MIDDLE_SCHOOL = obj.GRADE_LEVEL.toUpperCase().indexOf('MID') >= 0;
obj.HAS_HIGH_SCHOOL = obj.GRADE_LEVEL.toUpperCase().indexOf('HIGH') >= 0;
}
}
};

_.each(schools, zipSplit);

// filter data
var filtered_data = [];
var filtered_out = [];
for (var i = 0; i < schools.length - 1; i++) {
isOpen = schools[i].ACTIVE.toUpperCase() == 'OPEN';
isPublic = (schools[i].TYPE.toUpperCase() !== 'CHARTER' ||
schools[i].TYPE.toUpperCase() !== 'PRIVATE');
isSchool = (schools[i].HAS_KINDERGARTEN ||
schools[i].HAS_ELEMENTARY ||
schools[i].HAS_MIDDLE_SCHOOL ||
schools[i].HAS_HIGH_SCHOOL);
meetsMinimumEnrollment = schools[i].ENROLLMENT > minEnrollment;
meetsZipCondition = acceptedZipcodes.indexOf(schools[i].ZIPCODE) >= 0;
let filtering = (obj2) => {
isOpen = obj2.ACTIVE.toUpperCase() == 'OPEN';
isPublic = (obj2.TYPE.toUpperCase() !== 'CHARTER' ||
obj2.TYPE.toUpperCase() !== 'PRIVATE');
isSchool = (obj2.HAS_KINDERGARTEN ||
obj2.HAS_ELEMENTARY ||
obj2.HAS_MIDDLE_SCHOOL ||
obj2.HAS_HIGH_SCHOOL);
meetsMinimumEnrollment = obj2.ENROLLMENT > minEnrollment;
meetsZipCondition = acceptedZipcodes.indexOf(obj2.ZIPCODE) >= 0;
filter_condition = (isOpen &&
isSchool &&
meetsMinimumEnrollment &&
!meetsZipCondition);

if (filter_condition) {
filtered_data.push(schools[i]);
filtered_data.push(obj2);
} else {
filtered_out.push(schools[i]);
filtered_out.push(obj2);
}
}
_.each(schools, filtering);

console.log('Included:', filtered_data.length);
console.log('Excluded:', filtered_out.length);

// main loop
var color;
for (var i = 0; i < filtered_data.length - 1; i++) {
isOpen = filtered_data[i].ACTIVE.toUpperCase() == 'OPEN';
isPublic = (filtered_data[i].TYPE.toUpperCase() !== 'CHARTER' ||
filtered_data[i].TYPE.toUpperCase() !== 'PRIVATE');
meetsMinimumEnrollment = filtered_data[i].ENROLLMENT > minEnrollment;
let mapping = (obj3) => {
isOpen = obj3.ACTIVE.toUpperCase() == 'OPEN';
isPublic = (obj3.TYPE.toUpperCase() !== 'CHARTER' ||
obj3.TYPE.toUpperCase() !== 'PRIVATE');
meetsMinimumEnrollment = obj3.ENROLLMENT > minEnrollment;

// Constructing the styling options for our map
if (filtered_data[i].HAS_HIGH_SCHOOL){
if (obj3.HAS_HIGH_SCHOOL){
color = '#0000FF';
} else if (filtered_data[i].HAS_MIDDLE_SCHOOL) {
} else if (obj3.HAS_MIDDLE_SCHOOL) {
color = '#00FF00';
} else {
color = '##FF0000';
}
// The style options
var pathOpts = {'radius': filtered_data[i].ENROLLMENT / 30,
var pathOpts = {'radius': obj3.ENROLLMENT / 30,
'fillColor': color};
L.circleMarker([filtered_data[i].Y, filtered_data[i].X], pathOpts)
.bindPopup(filtered_data[i].FACILNAME_LABEL)
L.circleMarker([obj3.Y, obj3.X], pathOpts)
.bindPopup(obj3.FACILNAME_LABEL)
.addTo(map);
}
};
_.each(filtered_data, mapping);

})();