Lab: Data Jam
Dear students:
Today we're going to do things a little bit different. We're going to have a data jam. In a game jam, folks team up for a weekend and try to crank out a game that fits some theme. In our data jam, you're going to team up with your tablemates and write Rust code to explore a data set. Our theme is Where and When, and our data set is a CSV file with these columns:
- country (text)
- capital (text)
- latitude (real)
- longitude (real)
- capital population (integer)
- area (real)
- country population in 1960 (integer)
- country population in 2021 (integer)
The file has records for 234 countries or territories. The information is pieced together from World Bank and some websites that may or may not be credible.
Define a
Country
struct with the described fields. Have it automatically implement the Debug
trait so you can print it with {:?}
.
Read in the file and populate a vector of countries. Do not use a loop. Slurp up the file with
std::fs::read_to_string
. You will find the following str
methods useful: lines
, split
, and parse
. You will also find the following iterator methods useful: skip
, map
, and collect
.
Identify three meaningful questions to ask of the data, and document these in comments. The questions must be able to be answered by sorting, minimizing, maximizing, combining, or relating the data.
Iterate through the collection to find answers to your questions. Use higher-order functions and iterator methods where appropriate.
Paste the answers to your questions in the comments so that your instructor can learn from your investigation too.
Submit
To receive credit for this lab, you must submit your .rs
file on Canvas by Monday noon. Late labs or forgot-to-submits are not accepted because Monday at noon is when your instructor has time to grade.