Skip to content
Snippets Groups Projects
Commit 5bd7c30b authored by Ashwin Maran's avatar Ashwin Maran
Browse files

add lab-p5 and p5

parent ff05ea8d
No related branches found
No related tags found
No related merge requests found
# Lab P5: Looping Patterns and Hurricane API
Let us start Lab-P5! This lab introduces you to some fundamental looping patterns that will help solve P5. It is
designed to help you become comfortable using the functions in `project.py`. You will also
learn basic methods to manipulate strings needed for P5.
## Corrections and clarifications
None yet.
**Find any issues?** Report to us:
- Iffat Nafisa <nafisa@wisc.edu>
- Hakan Dingenc <dingenc@wisc.edu>
----------------------------------
## Learning Objectives:
In this lab you will practice:
- inspecting the `project.py` file,
- iterating through data using a `for` loop,
- writing algorithms to search, filter, count, and find min / max,
- writing algorithms that store/use indices
- writing helper functions,
- writing algorithms that manipulate strings.
----------------------------------
## Introduction:
In this lab, you will look at hurricane data and learn techniques to extract specific data. Data
scientists use such data when studying the effects of climate change.
According to the [Center for Climate and Energy Solutions](https://www.c2es.org/content/hurricanes-and-climate-change/), "Climate change is worsening
hurricane impacts in the United States by increasing the intensity and decreasing the speed at
which they travel. Scientists are currently uncertain whether there will be a change in the number
of hurricanes, but they are certain that the intensity and severity of hurricanes will continue to
increase. These trends make hurricanes far more costly in terms of physical damage and deaths."
By tracking past hurricanes' speed, number of fatalaties, and property damage, scientists can prepare for
future ones.
------------------------------
## Note on Academic Misconduct
You may do these lab exercises only with your project partner; you are not allowed to start working on Lab-P5 with one person, then do the project with a different partner. Now may be a good time to review [our course policies](https://cs220.cs.wisc.edu/s23/syllabus.html).
------------------------------
## Project partner
We strongly recommend students find a project partner. Pair programming is a great way to learn from a fellow student. Project difficulty increases exponentially in this course. Finding a project partner early on during the semester is a good idea.
If you are still looking for a project partner, take a moment now to ask around the room if anyone would like to partner with you on this project. Then you can work with them on this lab as well as the project.
----------------------------------
## Segment 1: Setup
Create a `lab-p5` directory and download the following files into the `lab-p5` directory:
* `hurricanes.csv`
* `project.py`
* `practice.ipynb`
* `practice_test.py`
Once you have downloaded the files, open a terminal and navigate to your `lab-p5` directory.
Run `ls` to make sure the above files are available.
**Note:** If you accidentally downloaded the file as a `.txt` instead of `.csv` (or `.cvs` or `.csv.txt`)
(say `hurricanes.cvs`), you can execute `mv hurricanes.cvs hurricanes.csv` on a
Terminal/PowerShell window. Recall that the `mv` (move) command lets you rename a source file
(first argument, example: `hurricanes.cvs`) to the destination file (second argument, example:
`hurricanes.csv`).
----------------------------------
## Segment 2: Learning the API
You will be finishing the rest of your lab on `practice.ipynb`. Run the command `jupyter notebook` from your Terminal/PowerShell window.
Remember not to close this
Terminal/PowerShell window while Jupyter is running, and open a new Terminal/PowerShell
window if necessary.
**Note**: For P5, you will be working on `p5.ipynb`, which is very similar to `practice.ipynb`.
It is strongly recommended that you finish this notebook before moving on to P5,
so you can ask your TA/PM any questions about the notebook that may arise.
**Note**: Unlike `p5.ipynb`, you do **not** have to submit `practice.ipynb`. This notebook is solely
for your practice and preparation for P5.
------------------------------
You can now get started with [P5]((https://git.doit.wisc.edu/cdis/cs/courses/cs220/cs220-s23-projects/-/tree/main/p5)). **You may use any helper functions created here in project p5**. Remember to only work with P5 with your partner from this point on. Have fun!
This diff is collapsed.
This diff is collapsed.
# Images
Images from lab-p5 are stored here.
lab-p5/images/table.png

40.1 KiB

This diff is collapsed.
#!/usr/bin/python
import os, json, math
REL_TOL = 6e-04 # relative tolerance for floats
ABS_TOL = 15e-03 # absolute tolerance for floats
PASS = "PASS"
TEXT_FORMAT = "text" # question type when expected answer is a str, int, float, or bool
expected_json = {"1-1": (TEXT_FORMAT, '1804 New England hurricane'),
"1-2": (TEXT_FORMAT, '1806 Great Coastal hurricane'),
"1-3": (TEXT_FORMAT, 105),
"1-4": (TEXT_FORMAT, '1M'),
"2": (TEXT_FORMAT, 'Nicole'),
"3-1": (TEXT_FORMAT, '9'),
"3-2": (TEXT_FORMAT, '608'),
"3-3": (TEXT_FORMAT, '5309'),
"3-4": (TEXT_FORMAT, '867'),
"4-1": (TEXT_FORMAT, 'CS'),
"4-2": (TEXT_FORMAT, '220'),
"5-1": (TEXT_FORMAT, 'B'),
"5-2": (TEXT_FORMAT, 3.19),
"6": (TEXT_FORMAT, 9),
"7-1": (TEXT_FORMAT, 2023),
"7-2": (TEXT_FORMAT, 22),
"8": (TEXT_FORMAT, 13),
"9": (TEXT_FORMAT, 1979),
"10": (TEXT_FORMAT, 8),
"11": (TEXT_FORMAT, 325),
"12": (TEXT_FORMAT, 325),
"13": (TEXT_FORMAT, 1920),
"14": (TEXT_FORMAT, 99.4836956521739),
"15": (TEXT_FORMAT, 18),
"16": (TEXT_FORMAT, 40),
"17": (TEXT_FORMAT, 'Ian'),
"18": (TEXT_FORMAT, '1975 Tropical Depression Six'),
"19-1": (TEXT_FORMAT, 130),
"19-2": (TEXT_FORMAT, 294),
"20-1": (TEXT_FORMAT, 551),
"20-2": (TEXT_FORMAT, 3),
"20-3": (TEXT_FORMAT, 190),
"20-4": (TEXT_FORMAT, 104.375),
"20-5": (TEXT_FORMAT, True),
"20-6": (TEXT_FORMAT, 8000),
"20-7": (TEXT_FORMAT, 'Katrina')}
def check_cell(qnum, actual):
format, expected = expected_json[qnum[1:]]
try:
if format == TEXT_FORMAT:
return simple_compare(expected, actual)
else:
if expected != actual:
return "expected %s but found %s " % (repr(expected), repr(actual))
except:
if expected != actual:
return "expected %s" % (repr(expected))
return PASS
def simple_compare(expected, actual, complete_msg=True):
msg = PASS
if type(expected) == type:
if expected != actual:
if type(actual) == type:
msg = "expected %s but found %s" % (expected.__name__, actual.__name__)
else:
msg = "expected %s but found %s" % (expected.__name__, repr(actual))
elif type(expected) != type(actual) and not (type(expected) in [float, int] and type(actual) in [float, int]):
msg = "expected to find type %s but found type %s" % (type(expected).__name__, type(actual).__name__)
elif type(expected) == float:
if not math.isclose(actual, expected, rel_tol=REL_TOL, abs_tol=ABS_TOL):
msg = "expected %s" % (repr(expected))
if complete_msg:
msg = msg + " but found %s" % (repr(actual))
else:
if expected != actual:
msg = "expected %s" % (repr(expected))
if complete_msg:
msg = msg + " but found %s" % (repr(actual))
return msg
def check(qnum, actual):
msg = check_cell(qnum, actual)
if msg == PASS:
return True
print("<b style='color: red;'>ERROR:</b> " + msg)
__hurricane__ = []
def __init__():
import csv
"""This function will read in the csv_file and store it in a list of dictionaries"""
__hurricane__.clear()
with open('hurricanes.csv', mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
__hurricane__.append(row)
def count():
"""This function will return the number of records in the dataset"""
return len(__hurricane__)
def get_name(idx):
"""get_name(idx) returns the name of the hurricane in row idx"""
return __hurricane__[int(idx)]['name']
def get_formed(idx):
"""get_formed(idx) returns the date of formation of the hurricane in row idx"""
return __hurricane__[int(idx)]['formed']
def get_dissipated(idx):
"""get_dissipated(idx) returns the date of dissipation of the hurricane in row idx"""
return __hurricane__[int(idx)]['dissipated']
def get_mph(idx):
"""get_mph(idx) returns the mph of the hurricane in row idx"""
return int(__hurricane__[int(idx)]['mph'])
def get_damage(idx):
"""get_damage(idx) returns the damage in dollars of the hurricane in row idx"""
return __hurricane__[int(idx)]['damage']
def get_deaths(idx):
"""get_deaths(idx) returns the deaths of the hurricane in row idx"""
return int(__hurricane__[int(idx)]['deaths'])
__init__()
# Project 5 (P5): Investigating Hurricane Data
## Corrections and clarifications
* None yet.
**Find any issues?** Report to us:
- Iffat Nafisa <nafisa@wisc.edu>
- Hakan Dingenc <dingenc@wisc.edu>
## Note on Academic Misconduct:
You are **allowed** to work with a partner on your projects. While it is not required that you work with a partner, it is **recommended** that you find a project partner as soon as possible as the projects will get progressively harder. Be careful **not** to work with more than one partner. If you worked with a partner on Lab-P5, you are **not** allowed to finish your project with a different partner. You may either continue to work with the same partner, or work on P5 alone. Now may be a good time to review our [course policies](https://cs220.cs.wisc.edu/s23/syllabus.html).
## Instructions:
This project will focus on **loops** and **strings**. To start, download `p5.ipynb`, `project.py`, `p5_test.py` and `hurricanes.csv`.
**Note:** Please go through [lab-p5](https://git.doit.wisc.edu/cdis/cs/courses/cs220/cs220-s23-projects/-/tree/main/lab-p5) before you start the project. The lab contains some very important information that will be necessary for you to finish the project.
You will work on `p5.ipynb` and hand it in. You should follow the provided directions for each question. Questions have **specific** directions on what **to do** and what **not to do**.
After you've downloaded the file to your `p5` directory, open a terminal window and use `cd` to navigate to that directory. To make sure you're in the correct directory in the terminal, type `pwd`. To make sure you've downloaded the notebook file, type `ls` to ensure that `p5.ipynb`, `project.py`, `p5_test.py`, and `hurricanes.csv` are listed. Then run the command `jupyter notebook` to start Jupyter, and get started on the project!
**IMPORTANT**: You should **NOT** terminate/close the session where you run the above command. If you need to use any other Terminal/PowerShell commands, open a new window instead. Keep constantly saving your notebook file, by either clicking the "Save and Checkpoint" button (floppy disk) or using the appropriate keyboard shortcut.
------------------------------
## IMPORTANT Submission instructions:
- Review the [Grading Rubric](https://git.doit.wisc.edu/cdis/cs/courses/cs220/cs220-s23-projects/-/tree/main/p5/rubric.md), to ensure that you don't lose points during code review.
- Login to [Gradescope](https://www.gradescope.com/) and upload the zip file into the P5 assignment.
- If you completed the project with a **partner**, make sure to **add their name** by clicking "Add Group Member"
in Gradescope when uploading the P5 zip file.
<img src="images/add_group_member.png" width="400">
**Warning:** You will have to add your partner on Gradescope even if you have filled out this information in your `p5.ipynb` notebook.
- It is **your responsibility** to make sure that your project clears auto-grader tests on the Gradescope test system. Otter test results should be available in a few minutes after your submission. You should be able to see PASS / FAIL results for the 20 test cases, which is accessible via Gradescope Dashboard (as in the image below):
<img src="images/gradescope.png" width="400">
Note that you can only see your score as `-/100.0` since it has not yet been reviewed by a TA. However, you should confirm that your tests have all passed the autograder.
This diff is collapsed.
This diff is collapsed.
# Images
Images from p5 are stored here.
p5/images/add_group_member.png

157 KiB

p5/images/gradescope.png

150 KiB

p5/images/table.PNG

13.5 KiB

p5/p5.ipynb 0 → 100644
This diff is collapsed.
This diff is collapsed.
__hurricane__ = []
def __init__():
import csv
"""This function will read in the csv_file and store it in a list of dictionaries"""
__hurricane__.clear()
with open('hurricanes.csv', mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
__hurricane__.append(row)
def count():
"""This function will return the number of records in the dataset"""
return len(__hurricane__)
def get_name(idx):
"""get_name(idx) returns the name of the hurricane in row idx"""
return __hurricane__[int(idx)]['name']
def get_formed(idx):
"""get_formed(idx) returns the date of formation of the hurricane in row idx"""
return __hurricane__[int(idx)]['formed']
def get_dissipated(idx):
"""get_dissipated(idx) returns the date of dissipation of the hurricane in row idx"""
return __hurricane__[int(idx)]['dissipated']
def get_mph(idx):
"""get_mph(idx) returns the mph of the hurricane in row idx"""
return int(__hurricane__[int(idx)]['mph'])
def get_damage(idx):
"""get_damage(idx) returns the damage in dollars of the hurricane in row idx"""
return __hurricane__[int(idx)]['damage']
def get_deaths(idx):
"""get_deaths(idx) returns the deaths of the hurricane in row idx"""
return int(__hurricane__[int(idx)]['deaths'])
__init__()
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment