Skip to content

Sprint Challenge Done #806

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

Open
wants to merge 1 commit 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
56 changes: 56 additions & 0 deletions Sprint-Challenge--Intro-Python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Sprint Challenge: Intro to Python

In this week's Sprint you explored the Python programming language as well as object-oriented design principles. This Sprint Challenge aims to assess your comfort in both of these areas through exercises similar to the ones you worked on at the beginning of this week in Intro to Python.

## Instructions
**Read these instructions carefully. Understand exactly what is expected _before_ starting this Sprint Challenge.**

This is an individual assessment. All work must be your own. Your challenge score is a measure of your ability to work independently using the material covered through this sprint. You need to demonstrate proficiency in the concepts and objectives introduced and practiced in the preceding days.

You are not allowed to collaborate during the Sprint Challenge. However, you are encouraged to follow the twenty-minute rule and seek support from your PM and Instructor in your cohort help channel on Slack. Your submitted work reflects your proficiency in the concepts and topics that were covered this week.

You have three hours to complete this Sprint Challenge. Plan your time accordingly.

## Commits

Commit your code regularly and meaningfully. This helps both you (in case you ever need to return to old code for any number of reasons) and it also helps your project manager to more thoroughly assess your work.

## Description

Complete the programs in the `src/` directory in any order.

* `oop/`
* `oop1.py`: class hierarchies
* `oop2.py`: subclassing and method overriding
* `comp/`
* `comp.py`: list comprehensions
* `cityreader/`
* `cityreader.py`: modules and CSV file reading

## Testing

Each file has its own associated test file. To test your code, run `python [name_of_test_file.py]` or `python3 [name_of_test_file.py]` if your Python 3 command is mapped to `python3`. Note: `cityreader` needs to be run from the same directory as the files or it will not be able to find the associated CSV file.

The `cityreader` stretch goal has its own test file, `test_stretch.py`, if you want to take a stab at implementing the stretch problem.

**_It's never a bad idea to take a look at the test files in order to see what each test is expecting._**

## Minimum Viable Product

In order to meet MVP requirements for this Sprint Challenge, complete all of the exercises posed in each directory by getting the tests for each exercise to pass.

In your solution, it is essential that you follow best practices and produce clean and professional results. Schedule time to review, refine, and assess your work and perform basic professional polishing including spell-checking and grammar-checking on your work. It is better to submit a challenge that meets the MVP requirements than one that attempts too much and does not.

## Stretch Problems

The `cityreader` directory poses an stretch problem that builds upon the functionality you are to implement as part of the non-stretch requirements in the `cityreader` directory.

There's a separate test file `test_stretch.py` for the stretch problem that you can run in order to test your implementation of the stretch problem.

## Rubric
| OBJECTIVE | TASK | 1 - DOES NOT MEET Expectations | 2 - MEETS Expectations | 3 - EXCEEDS Expectations | SCORE |
| ---------- | ----- | ------- | ------- | ------- | -- |
| _Student can demonstrate applied knowledge of Python basics by producing list comprehensions in `comp.py`_ | List Comprehensions: (1 point per problem, 8 max) | 0-5 points | 6-7 points | 8 points | |
| _Student can demonstrate applied knowledge of Object-Oriented Programming by completing `oop1.py` and `oop2.py`_ | OOP: (2 points per file, 4 max) | 0 points | 2 points | 4 points | |
| _Student can demonstrate applied research and language learning by completing `cityreader.py`_ | CSV: 6 points for `cityreader()`, 1 point for `cityreader_stretch()` | 0 points | 6 points | 7 points | |
| **FINAL SCORE** | | **0-13** | **14-18** | **19** | |
Binary file not shown.
61 changes: 61 additions & 0 deletions Sprint-Challenge--Intro-Python/src/cityreader/cities.csv

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions Sprint-Challenge--Intro-Python/src/cityreader/cityreader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#Done
# Create a class to hold a city location. Call the class "City". It should have
# fields for name, lat and lon (representing latitude and longitude).


# We have a collection of US cities with population over 750,000 stored in the
# file "cities.csv". (CSV stands for "comma-separated values".)
#
# In the body of the `cityreader` function, use Python's built-in "csv" module
# to read this file so that each record is imported into a City instance. Then
# return the list with all the City instances from the function.
# Google "python 3 csv" for references and use your Google-fu for other examples.
#
# Store the instances in the "cities" list, below.
#
# Note that the first line of the CSV is header that describes the fields--this
# should not be loaded into a City object.
import pandas as pd
class City():
def __init__(self, name, lat, lon):
self.name = name
self.lat = lat
self.lon = lon

def __str__(self):
return f'{self.name}, {self.lat}, {self.lon}'

cities = []

import csv

def cityreader(cities=[]):
# TODO Implement the functionality to read from the 'cities.csv' file
# Ensure that the lat and lon valuse are all floats
# For each city record, create a new City instance and add it to the
# `cities` list
with open('cities.csv') as city:
read_file = csv.reader(city, delimiter = ',')
next(read_file)
cities = [City(x[0], float(x[3]), float(x[4])) for x in read_file]
return cities

cityreader(cities)

# Print the list of cities (name, lat, lon), 1 record per line.
for c in cities:
print(c)

# STRETCH GOAL!
#
# Allow the user to input two points, each specified by latitude and longitude.
# These points form the corners of a lat/lon square. Pass these latitude and
# longitude values as parameters to the `cityreader_stretch` function, along
# with the `cities` list that holds all the City instances from the `cityreader`
# function. This function should output all the cities that fall within the
# coordinate square.
#
# Be aware that the user could specify either a lower-left/upper-right pair of
# coordinates, or an upper-left/lower-right pair of coordinates. Hint: normalize
# the input data so that it's always one or the other, then search for cities.
# In the example below, inputting 32, -120 first and then 45, -100 should not
# change the results of what the `cityreader_stretch` function returns.
#
# Example I/O:
#
# Enter lat1,lon1: 45,-100
# Enter lat2,lon2: 32,-120
# Albuquerque: (35.1055,-106.6476)
# Riverside: (33.9382,-117.3949)
# San Diego: (32.8312,-117.1225)
# Los Angeles: (34.114,-118.4068)
# Las Vegas: (36.2288,-115.2603)
# Denver: (39.7621,-104.8759)
# Phoenix: (33.5722,-112.0891)
# Tucson: (32.1558,-110.8777)
# Salt Lake City: (40.7774,-111.9301)

# TODO Get latitude and longitude values from the user

def cityreader_stretch(lat1, lon1, lat2, lon2, cities=[]):
# within will hold the cities that fall within the specified region
within = []

# Go through each city and check to see if it falls within
# the specified coordinates.

return within
86 changes: 86 additions & 0 deletions Sprint-Challenge--Intro-Python/src/cityreader/test_cityreader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import unittest
from cityreader import City, cityreader

def check_city(inp, exp):
if inp.name != exp.name:
return False
if inp.lat != exp.lat:
return False
if inp.lon != exp.lon:
return False
return True

class CityreaderTests(unittest.TestCase):
def setUp(self):
self.cities = cityreader()
self.expected = [
City("Seattle", 47.6217,-122.3238),
City("Richmond", 37.5294,-77.4755),
City("Virginia Beach", 36.7335,-76.0435),
City("Washington", 38.9047,-77.0163),
City("Milwaukee", 43.064,-87.9669),
City("Orlando", 28.4801,-81.3448),
City("Miami", 25.784,-80.2102),
City("Tampa", 27.9937,-82.4454),
City("Jacksonville", 30.3322,-81.6749),
City("Albuquerque", 35.1055,-106.6476),
City("Fort Worth", 32.7813,-97.3466),
City("McAllen", 26.2203,-98.2457),
City("El Paso", 31.8478,-106.431),
City("Dallas", 32.7938,-96.7659),
City("Austin", 30.3038,-97.7545),
City("Houston", 29.7871,-95.3936),
City("San Antonio", 29.4722,-98.5247),
City("New Orleans", 30.0687,-89.9288),
City("Charlotte", 35.208,-80.8308),
City("Raleigh", 35.8323,-78.6441),
City("Omaha", 41.2634,-96.0453),
City("Memphis", 35.1047,-89.9773),
City("Nashville", 36.1714,-86.7844),
City("Buffalo", 42.9016,-78.8487),
City("Queens", 40.7498,-73.7976),
City("New York", 40.6943,-73.9249),
City("Bronx", 40.8501,-73.8662),
City("Brooklyn", 40.6501,-73.9496),
City("Manhattan", 40.7834,-73.9662),
City("Philadelphia", 40.0076,-75.134),
City("Pittsburgh", 40.4396,-79.9763),
City("Sacramento", 38.5666,-121.4683),
City("Riverside", 33.9382,-117.3949),
City("San Francisco", 37.7561,-122.4429),
City("San Diego", 32.8312,-117.1225),
City("San Jose", 37.302,-121.8488),
City("Los Angeles", 34.114,-118.4068),
City("Las Vegas", 36.2288,-115.2603),
City("Denver", 39.7621,-104.8759),
City("Chicago", 41.8373,-87.6861),
City("Atlanta", 33.7627,-84.4231),
City("Indianapolis", 39.7771,-86.1458),
City("Oklahoma City", 35.4677,-97.5138),
City("Phoenix", 33.5722,-112.0891),
City("Tucson", 32.1558,-110.8777),
City("Bridgeport", 41.1909,-73.1958),
City("Hartford", 41.7661,-72.6834),
City("Baltimore", 39.3051,-76.6144),
City("Boston", 42.3189,-71.0838),
City("Cleveland", 41.4766,-81.6805),
City("Columbus", 39.9859,-82.9852),
City("Cincinnati", 39.1412,-84.506),
City("Salt Lake City", 40.7774,-111.9301),
City("Saint Louis", 38.6358,-90.2451),
City("Kansas City", 39.1239,-94.5541),
City("Minneapolis", 44.9635,-93.2679),
City("Detroit", 42.3834,-83.1024),
City("Providence", 41.8229,-71.4186),
City("Louisville", 38.1662,-85.6488),
City("Portland", 45.5372,-122.65)
]

def test_cityreader_correctness(self):
self.assertEqual(len(self.cities), 60)
for i in range(len(self.cities)):
self.assertTrue(check_city(self.cities[i], self.expected[i]))


if __name__ == '__main__':
unittest.main()
90 changes: 90 additions & 0 deletions Sprint-Challenge--Intro-Python/src/cityreader/test_stretch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import unittest
from cityreader import City, cityreader, cityreader_stretch

def check_city(inp, exp):
if inp.name != exp.name:
return False
if inp.lat != exp.lat:
return False
if inp.lon != exp.lon:
return False
return True

class CityreaderTests(unittest.TestCase):
def setUp(self):
self.cities = cityreader()

def test_cityreader_stretch_correctness(self):
expected = [
City("Albuquerque", 35.1055,-106.6476),
City("Riverside", 33.9382,-117.3949),
City("San Diego", 32.8312,-117.1225),
City("Los Angeles", 34.114,-118.4068),
City("Las Vegas", 36.2288,-115.2603),
City("Denver", 39.7621,-104.8759),
City("Phoenix", 33.5722,-112.0891),
City("Tucson", 32.1558,-110.8777),
City("Salt Lake City", 40.7774,-111.9301)
]

inp = cityreader_stretch(45, -100, 32, -120, self.cities)

self.assertEqual(len(inp), len(expected))

for i in range(len(inp)):
self.assertTrue(check_city(inp[i], expected[i]))

inp = cityreader_stretch(32, -120, 45, -100, self.cities)

self.assertEqual(len(inp), len(expected))

for i in range(len(inp)):
self.assertTrue(check_city(inp[i], expected[i]))

expected = [
City("Richmond", 37.5294,-77.4755),
City("Virginia Beach", 36.7335,-76.0435),
City("Washington", 38.9047,-77.0163),
City("Orlando", 28.4801,-81.3448),
City("Miami", 25.784,-80.2102),
City("Tampa", 27.9937,-82.4454),
City("Jacksonville", 30.3322,-81.6749),
City("Albuquerque", 35.1055,-106.6476),
City("Fort Worth", 32.7813,-97.3466),
City("McAllen", 26.2203,-98.2457),
City("El Paso", 31.8478,-106.431),
City("Dallas", 32.7938,-96.7659),
City("Austin", 30.3038,-97.7545),
City("Houston", 29.7871,-95.3936),
City("San Antonio", 29.4722,-98.5247),
City("New Orleans", 30.0687,-89.9288),
City("Charlotte", 35.208,-80.8308),
City("Raleigh", 35.8323,-78.6441),
City("Memphis", 35.1047,-89.9773),
City("Nashville", 36.1714,-86.7844),
City("Riverside", 33.9382,-117.3949),
City("San Diego", 32.8312,-117.1225),
City("Los Angeles", 34.114,-118.4068),
City("Las Vegas", 36.2288,-115.2603),
City("Denver", 39.7621,-104.8759),
City("Atlanta", 33.7627,-84.4231),
City("Indianapolis", 39.7771,-86.1458),
City("Oklahoma City", 35.4677,-97.5138),
City("Phoenix", 33.5722,-112.0891),
City("Tucson", 32.1558,-110.8777),
City("Baltimore", 39.3051,-76.6144),
City("Columbus", 39.9859,-82.9852),
City("Cincinnati", 39.1412,-84.506),
City("Saint Louis", 38.6358,-90.2451),
City("Kansas City", 39.1239,-94.5541),
City("Louisville", 38.1662,-85.6488)
]

inp = cityreader_stretch(40, -50, 12, -120, self.cities)

for i in range(len(inp)):
self.assertTrue(check_city(inp[i], expected[i]))


if __name__ == '__main__':
unittest.main()
Binary file not shown.
Loading