diff --git a/02_activities/assignments/assigment_3.py b/02_activities/assignments/assigment_3.py new file mode 100644 index 000000000..5f471834c --- /dev/null +++ b/02_activities/assignments/assigment_3.py @@ -0,0 +1,35 @@ +### Load libraries +import pandas as pd +import matplotlib.pyplot as plt + +### Read-in parking ticket data +parking = pd.read_csv("Parking_Tags_Data_2025.csv", + skiprows=1, + dtype={'TIME_OF_INFRACTION': str}, + encoding='latin1') + +### Calculate total fines by infraction code +fines_by_infraction = ( + parking + .groupby('INFRACTION_CODE', as_index=False)['SET_FINE_AMOUNT'] + .sum() + .rename(columns = {'SET_FINE_AMOUNT': 'TOTAL_FINE_AMOUNT'})) + +### Plot total fines against infraction code +# Find top N infraction codes by total fine +topN = 20 +top_fines = ( + fines_by_infraction + .sort_values('TOTAL_FINE_AMOUNT', ascending=False) + .head(topN)) + +# Convert columns to arrays +total_fines = top_fines['TOTAL_FINE_AMOUNT'].to_numpy() +infraction_codes = top_fines['INFRACTION_CODE'].astype('Int64').astype(str).to_numpy() + +# Create figure +fig, ax = plt.subplots(figsize = (9, 3)) +ax.bar(infraction_codes, total_fines) +ax.set_title('Total Fines by Infraction Code (Top 20), 2025') +ax.set_xlabel('Infraction Code') +ax.set_ylabel('Total Fines') diff --git a/02_activities/assignments/assignment_3-R.md b/02_activities/assignments/assignment_3-R.md new file mode 100644 index 000000000..8ce9898a8 --- /dev/null +++ b/02_activities/assignments/assignment_3-R.md @@ -0,0 +1,67 @@ +# Data Visualization + +## Assignment 3: Final Project + +### Requirements: +- We will finish this class by giving you the chance to use what you have learned in a practical context, by creating data visualizations from raw data. +- Choose a dataset of interest from the [City of Toronto’s Open Data Portal](https://www.toronto.ca/city-government/data-research-maps/open-data/) or [Ontario’s Open Data Catalogue](https://data.ontario.ca/). +- Using Python and one other data visualization software (Excel or free alternative, Tableau Public, any other tool you prefer), create two distinct visualizations from your dataset of choice. +- For each visualization, describe and justify: + > What software did you use to create your data visualization? + R + > Who is your intended audience? + Municipal policymakers who wish to analyze the revenue trend from parking tickets, perhaps to forecast the timing of revenues. + > What information or message are you trying to convey with your visualization? + Parking ticket revenue is highly volatile. + > What aspects of design did you consider when making your visualization? How did you apply them? With what elements of your plots? + The total fine amounts at the daily level fluctuate so much that they clutter the figure. To address this, I decided to plot a 7-day moving average of this variable instead, so that the line is smoother and more readable. + > How did you ensure that your data visualizations are reproducible? If the tool you used to make your data visualization is not reproducible, how will this impact your data visualization? + The R code can be executed as it is to reproduce the visualization. + > How did you ensure that your data visualization is accessible? + The visualization uses simple language and easily distinguishable colours. + > Who are the individuals and communities who might be impacted by your visualization? + Municipal finance planners, since they are the ones who need to manage how parking ticket revenues play into the city budget. + > How did you choose which features of your chosen dataset to include or exclude from your visualization? + Elements which would overcomplicate the visualization, such as detailed infraction descriptions and location information, were excluded. + > What ‘underwater labour’ contributed to your final data visualization product? + I could not have completed the visualization without the City of Toronto employees who collected the parking ticket data, cleaned it, and created the data files. +- This assignment is intentionally open-ended - you are free to create static or dynamic data visualizations, maps, or whatever form of data visualization you think best communicates your information to your audience of choice! +- Total word count should not exceed **(as a maximum) 1000 words** + +### Why am I doing this assignment?: +- This ongoing assignment ensures active participation in the course, and assesses the learning outcomes: +* Create and customize data visualizations from start to finish in Python +* Apply general design principles to create accessible and equitable data visualizations +* Use data visualization to tell a story +- This would be a great project to include in your GitHub Portfolio – put in the effort to make it something worthy of showing prospective employers! + +### Rubric: + +| Component | Scoring | Requirement | +|-------------------|----------|-----------------------------------------------------------------------------| +| Data Visualizations | Complete/Incomplete | - Data visualizations are distinct from each other
- Data visualizations are clearly identified
- Different sources/rationales (text with two images of data, if visualizations are labeled)
- High-quality visuals (high resolution and clear data)
- Data visualizations follow best practices of accessibility | +| Written Explanations | Complete/Incomplete | - All questions from assignment description are answered for each visualization
- Explanations are supported by course content or scholarly sources, where needed | +| Code | Complete/Incomplete | - All code is included as an appendix with your final submissions
- Code is clearly commented and reproducible | + +## Submission Information + +🚨 **Please review our [Assignment Submission Guide](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md)** 🚨 for detailed instructions on how to format, branch, and submit your work. Following these guidelines is crucial for your submissions to be evaluated correctly. + +### Submission Parameters: +* Submission Due Date: `23:59 - 2026-06-16` +* The branch name for your repo should be: `assignment-3` +* What to submit for this assignment: + * A folder/directory containing: + * Two distinct data visualizations (for example, PNGs, PDFs, or screenshots) + * Two Markdown files answering all questions for each visualization (including a link to your dataset in both files) + * One Python file contains the complete code and visualization, and another file (with or without code) contains the visualization. +* What the pull request link should look like for this assignment: `https://github.com//visualization/pull/` + * Open a private window in your browser. Copy and paste the link to your pull request into the address bar. Make sure you can see your pull request properly. This helps the technical facilitator and learning support staff review your submission easily. + +Checklist: +- [ ] Create a branch called `assignment-3`. +- [ ] Ensure that the repository is public. +- [ ] Review [the PR description guidelines](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md#guidelines-for-pull-request-descriptions) and adhere to them. +- [ ] Verify that the link is accessible in a private browser window. + +If you encounter any difficulties or have questions, please don't hesitate to reach out to our team via our Slack. Our Technical Facilitators and Learning Support staff are here to help you navigate any challenges. diff --git a/02_activities/assignments/assignment_3-py.md b/02_activities/assignments/assignment_3-py.md new file mode 100644 index 000000000..2a11fcbc4 --- /dev/null +++ b/02_activities/assignments/assignment_3-py.md @@ -0,0 +1,67 @@ +# Data Visualization + +## Assignment 3: Final Project + +### Requirements: +- We will finish this class by giving you the chance to use what you have learned in a practical context, by creating data visualizations from raw data. +- Choose a dataset of interest from the [City of Toronto’s Open Data Portal](https://www.toronto.ca/city-government/data-research-maps/open-data/) or [Ontario’s Open Data Catalogue](https://data.ontario.ca/). +- Using Python and one other data visualization software (Excel or free alternative, Tableau Public, any other tool you prefer), create two distinct visualizations from your dataset of choice. +- For each visualization, describe and justify: + > What software did you use to create your data visualization? + Python + > Who is your intended audience? + Municipal policymakers who wish to analyze the salience of different types of parking infractions on the public. + > What information or message are you trying to convey with your visualization? + Most parking infractions are concentrated among a few violation types. + > What aspects of design did you consider when making your visualization? How did you apply them? With what elements of your plots? + There are 449 infraction types, so I restricted the figure to display the top 20 infractions with the most fines to avoid cluttering the plot. I also sorted the infraction codes by descending order of total fines. + > How did you ensure that your data visualizations are reproducible? If the tool you used to make your data visualization is not reproducible, how will this impact your data visualization? + The Python code can be executed as it is to reproduce the visualization. + > How did you ensure that your data visualization is accessible? + The visualization uses simple language and easily distinguishable colours. + > Who are the individuals and communities who might be impacted by your visualization? + Drivers, since they are the ones who may face parking tickets. + > How did you choose which features of your chosen dataset to include or exclude from your visualization? + Elements which would overcomplicate the visualization, such as detailed infraction descriptions and location information, were excluded. + > What ‘underwater labour’ contributed to your final data visualization product? + I could not have completed the visualization without the City of Toronto employees who collected the parking ticket data, cleaned it, and created the data files. +- This assignment is intentionally open-ended - you are free to create static or dynamic data visualizations, maps, or whatever form of data visualization you think best communicates your information to your audience of choice! +- Total word count should not exceed **(as a maximum) 1000 words** + +### Why am I doing this assignment?: +- This ongoing assignment ensures active participation in the course, and assesses the learning outcomes: +* Create and customize data visualizations from start to finish in Python +* Apply general design principles to create accessible and equitable data visualizations +* Use data visualization to tell a story +- This would be a great project to include in your GitHub Portfolio – put in the effort to make it something worthy of showing prospective employers! + +### Rubric: + +| Component | Scoring | Requirement | +|-------------------|----------|-----------------------------------------------------------------------------| +| Data Visualizations | Complete/Incomplete | - Data visualizations are distinct from each other
- Data visualizations are clearly identified
- Different sources/rationales (text with two images of data, if visualizations are labeled)
- High-quality visuals (high resolution and clear data)
- Data visualizations follow best practices of accessibility | +| Written Explanations | Complete/Incomplete | - All questions from assignment description are answered for each visualization
- Explanations are supported by course content or scholarly sources, where needed | +| Code | Complete/Incomplete | - All code is included as an appendix with your final submissions
- Code is clearly commented and reproducible | + +## Submission Information + +🚨 **Please review our [Assignment Submission Guide](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md)** 🚨 for detailed instructions on how to format, branch, and submit your work. Following these guidelines is crucial for your submissions to be evaluated correctly. + +### Submission Parameters: +* Submission Due Date: `23:59 - 2026-06-16` +* The branch name for your repo should be: `assignment-3` +* What to submit for this assignment: + * A folder/directory containing: + * Two distinct data visualizations (for example, PNGs, PDFs, or screenshots) + * Two Markdown files answering all questions for each visualization (including a link to your dataset in both files) + * One Python file contains the complete code and visualization, and another file (with or without code) contains the visualization. +* What the pull request link should look like for this assignment: `https://github.com//visualization/pull/` + * Open a private window in your browser. Copy and paste the link to your pull request into the address bar. Make sure you can see your pull request properly. This helps the technical facilitator and learning support staff review your submission easily. + +Checklist: +- [ ] Create a branch called `assignment-3`. +- [ ] Ensure that the repository is public. +- [ ] Review [the PR description guidelines](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md#guidelines-for-pull-request-descriptions) and adhere to them. +- [ ] Verify that the link is accessible in a private browser window. + +If you encounter any difficulties or have questions, please don't hesitate to reach out to our team via our Slack. Our Technical Facilitators and Learning Support staff are here to help you navigate any challenges. diff --git a/02_activities/assignments/assignment_3.R b/02_activities/assignments/assignment_3.R new file mode 100644 index 000000000..6ddabbe92 --- /dev/null +++ b/02_activities/assignments/assignment_3.R @@ -0,0 +1,30 @@ +### Load packages +library(data.table) +library(lubridate) +library(zoo) +library(ggplot2) + +### Read-in parking data +parking <- fread("Parking_Tags_Data_2025.csv", skip = 1, sep = ",") + +### Calculate total fines per day +fines_per_day <- parking[, + .(total_fine = sum(SET_FINE_AMOUNT)), + by = DATE_OF_INFRACTION] + +# Take 7-day moving average +ma_length <- 7 +fines_per_day$total_fine_ma <- rollmean(fines_per_day$total_fine, k = ma_length, fill = NA) + +### Convert date column to Date type +fines_per_day$date <- ymd(fines_per_day$DATE_OF_INFRACTION) + +### Plot total fines per day +ggplot(fines_per_day, aes(x = date, y = total_fine_ma)) + + geom_line(color = "blue") + + labs( + title = "Total Fines per Day (2025), 7-Day Moving Average", + x = "Calendar Day", + y = "Total Fine" + ) + + theme_light() diff --git a/02_activities/assignments/assignment_3_viz_R.jpeg b/02_activities/assignments/assignment_3_viz_R.jpeg new file mode 100644 index 000000000..3de1048e0 Binary files /dev/null and b/02_activities/assignments/assignment_3_viz_R.jpeg differ diff --git a/02_activities/assignments/assignment_3_viz_py.png b/02_activities/assignments/assignment_3_viz_py.png new file mode 100644 index 000000000..1107764ce Binary files /dev/null and b/02_activities/assignments/assignment_3_viz_py.png differ