Learning objectives
This lab has two separate parts. In the first, we'll continue with the dashboard example from lecture, auditing whether it behaves correctly. In the second, we'll get a head start on the data structure design for the assignment that goes out on Friday.
This lab will:
- give you practice dissecting a web application
- have you review a delivered program
- have you do the data design for a dashboard project for Bikeshare data
Setup
- Find a partner. Labs are pair work.
- Make a copy of the written answer worksheet, share it with your partner(s), and submit the link to it in the worksheet submission form (you can do this before filling anything in).
Part 1Reviewing the dashboard
The dashboard from lecture has changed slightly. It now has two charts and two actual quiz questions under the charts (rather than just a submit button). The second chart shows the percent of responses correct for each concept in a quiz course.
We'll start by having you download the dashboard code and get it running on your computer.
Dashboard Setup
- Make a new folder for this lab (call it
dashboard-lab), download dashboard.zip, and unzip it into that folder. Open the folder in VS Code (File → Open Folder) and open a terminal there (Terminal → New Terminal). The terminal must be in this folder: if you runls(Windows:dir) you should seeapp.py. - The dashboard needs libraries your computer doesn't have (Flask for the web page, matplotlib for charts, pytest for tests), so create a private Python environment in the lab folder.
On a Mac:
python3 -m venv .venv .venv/bin/pip install flask matplotlib pytestOn Windows:
py -m venv .venv .venv\Scripts\pip install flask matplotlib pytestThis takes a minute or two and creates a folder named
.venv; you never edit it. - Run the dashboard with
.venv/bin/python -m flask --app app run --port 5003(Windows:.venv\Scripts\python -m flask --app app run --port 5003) and openhttp://127.0.0.1:5003in your browser. (Press Ctrl-C in the terminal to stop it, and run it again to restart with fresh data.) Run tests with.venv/bin/python -m pytest(Windows:.venv\Scripts\python -m pytest).
Overview of Files
Inside the folder, you'll find the following files:
questions.csv: contains the configuration of the questions, which can be either multiple choice or fill in the blankresponses.csv: contains student responses. (this file does not get updated as we run the dashboard -- figuring out how to do that is a challenge for next week)app.pyis the file that runs the dashboard (what we looked at in lecture)charts.py,scores.pyandtimeslots.pyprocess data to create the charts for the webpage
You need to assess whether and how the dashboard is working. First things first, look at the new chart and develop a hypothesis for what it does. Then, submit quiz responses to make sure that the charts change the way you expect. These are a form of test case (you think through the expected impact before running the test, rather than writing an assert statement).
Summarize your findings in your worksheet.
For each issue that you found, look through the various .py files and try to identify which parts of the code are responsible. Note them in your worksheet.
More generally, look at the .py files (except for app.py) and critique what you see, using the questions in the worksheet as a guide. Write your answers in the worksheet.
Checkpoint
Show a TA your experiments, findings, and analysis.
If you still have time in this segment of lab, work with Claude to try to fix the program. Tell it what problems you noticed and what results you expected to see instead. Each time Claude claims to have fixed the program, restart the page and check whether the issue has been fixed.
Make observations in your worksheet as you go.
Part 2Preparing a Bikeshare Dashboard
For your next homework assignment, you will be creating a dashboard to help the operations manager at a Bikeshare company. Each evening, the operations manager has to decide where bikes need to be moved overnight so that there are enough bikes in place for the rides expected on the next day. The company has enough trucks to make 15-20 moves per evening. The dashboard needs to help the manager decide which moves to make.
In this half of lab, you'll get a head start on designing the data structures you need and getting familiar with the dataset that you'll be working with. The assignment uses real data from Bluebikes, Boston's bike share program.
Prioritizing Moves
There are many metrics one could use in deciding how to move bikes around overnight. For now, the manager wants to look at the net flow of a station. This is the number of bikes that arrived throughout the day minus the number that left. A positive net flow means bikes pile up, so the company should remove some of them; a negative one means the company should deliver additional bikes there.
In planning this dashboard, you'll need to figure out how to compute the net flow of each station, and how to sort stations based on their net flow.
Get Familiar with the Bluebikes Data
Make a folder called bikeshare inside your lab folder, download starter.zip and unzip it there.
Open lab-trips.csv and lab-stations.csv, which you just unzipped. They are a tiny made-up sample of trips among four real Bluebikes stations, small enough to check by hand. (On the homework, you will get real data covering a day, a week, and a month.)
Spend a few minutes looking at the sample data. What do you notice about it? How do the two files relate? Make notes in your worksheet about what you expect to have to do in order to prepare this data for use in creating the dashboard.
Now, identify the data structures (lists, dataclasses, dictionaries) that you will want to have in order to compute a set of nightly moves based on the net flow. Keep in mind that you do not have to keep the data in the tables as provided in the csv files -- you get to decide which datastructures you want; part of your work on the assignment will involve extracting or converting the data you get from Bluebikes into the form that you'll need to generate content for the dashboard.
Checkpoint
Show a TA your data structure choice.
Compare notes with another student or pair who has reached this point in the assignment. Use this feedback to make your final decision about the data structures you will need.
If you get this far and still have time, you could work with Claude to develop the code to convert the csv data to your chosen data structure. You'll get the rest of the requirements for this assignment in the handout that releases on Friday.
Comments or concerns?
If you have comments or concerns, submit them on the anonymous feedback form. Sign in with your Brown Google account to open it; your email address is not recorded.