We'll be looking at simple weather data (just temperature) measured at the Naval Academy, and pulled from the site https://meteostat.net/. If you pull a week or less worth of data, you get hour-by-hour data, which is what I want. We have all the data for this January, a week at a time (files week1.tsv through week5.tsv) . Obviously, that last file has only four days worth of data in it. I also have a file month.tsv that includes all 31 days worth of data.
.tsv,
for tab separated values. This means that we have a text
file where each row of data is on a single line, and different
fields in a row of data are separated by tab characters,
i.e. '\t'. (Note: we usually assume that
fields are not allowed to contain tabs!.)
One nice thing about this format is that spreadsheets typically
can open or import this data.
Knowing the file format isn't everything, though. Part of "the format" in the larger sense is how things are laid out within that file format. In other words, "OK it's .tsv, but what fields do we have?" So here it is:
time temp 2022-01-01 00:00:00 11.1 2022-01-01 01:00:00 11.3 2022-01-01 02:00:00 11 ··· 2022-01-07 22:00:00 -4.1 2022-01-07 23:00:00 -4.8 |
(Note: the big gaps are tabs, not multiple spaces!)
What week1.tsv looks like
|
lab04lab04 directorydata.tgz into your lab04
directory like this:
curl -O https://www.usna.edu/Users/cs/SI204/lab/l04/data.tgz
tar xfz data.tgzNote: if you do an
ls you should see month.tsv week1.tsv week2.tsv week3.tsv
week4.tsv week5.tsv listed.
part1.cpp that reads a file name from
the user, then gives the average temperature across all the
entries in the data file.
echo $?
displays the value returned by the previous program run in the shell.
| run 1 | run 2 | run 3 |
$ ./part1 weak1.tsv Could not open file 'weak1.tsv' $ echo $? 1 |
$ ./part1 week1.tsv file: week1.tsv ave: 40.0904 |
$ ./part1 week5.tsv file: week5.tsv ave: 26.5225 |
Note: your program must work on all the input files I've given you, and any other that is in the proper format.
~/bin/submit -c=SI204 -p=lab04 part1.cpp
part2.cpp
that builds on your Part 1 solution by reporting the min and max
temperatures along with the day on which those temperatures
occurred.
| run 1 | run 2 | run 3 |
$ ./part2 weak1.tsv Could not open file 'weak1.tsv' $ echo $? 1 |
$ ./part2 week1.tsv file: week1.tsv ave: 40.0904 min: 23.36 on 2022-01-07 max: 64.58 on 2022-01-01 |
$ ./part2 week2.tsv file: week2.tsv ave: 33.1282 min: 20.3 on 2022-01-08 max: 47.66 on 2022-01-09 |
~/bin/submit -c=SI204 -p=lab04 part1.cpp part2.cpp
part3.cpp that builds on your Part 2
solution by writing a .tsv file (the name is given by the user)
that contains the same time&temp data as the input, with
three differences:
dayTABhourTABtemp
| run 1 | run 2 | run 2 (cont.) |
$ ./part3 weak1.tsv out1.tsv Could not open file 'weak1.tsv' $ echo $? 1 |
$ ./part3 week5.tsv out5.tsv file: week5.tsv ave: 26.5225 min: 15.8 on 2022-01-30 max: 33.8 on 2022-01-31 output in: out5.tsv |
File out5.tsv produced by run 2.
You can open this (and your output) in a spreadsheet
like libreoffice. You can also view it in the terminal
like this:
$ cat out5.tsv
day hour temp
2022-01-29 1 30.2
2022-01-29 2 30.2
···
2022-01-31 22 30.2
2022-01-31 23 30.2
2022-01-31 24 28.4
|
libreoffice out5.tsv& will automatically
import the tsv file into a spreadsheet. Try running on several of the
input files and opening them in a spreadsheet.
~/bin/submit -c=SI204 -p=lab04 part1.cpp part2.cpp part3.cpp
2022-01-29) followed by a field with the
temperature from the first hour, then a field with the temperature
from the second hour, all the way up to a field for the 24th hour.
| run 1 | contents of week5.tsv | contents of out5NEW.tsv |
$ ./part4 week5.tsv out5NEW.tsv file: week5.tsv ave: 26.5225 min: 15.8 on 2022-01-30 max: 33.8 on 2022-01-31 output in: out5NEW.tsv |
time temp 2022-01-01 00:00:00 11.1 2022-01-01 01:00:00 11.3 ··· 2022-01-07 22:00:00 -4.1 2022-01-07 23:00:00 -4.8 |
2022-01-29 30.2 30.2 ··· 24.8 23 23 2022-01-30 21.2 21.2 ··· 24.8 28.4 28.4 2022-01-31 28.4 28.4 ··· 30.2 30.2 28.4 |
~/bin/submit -c=SI204 -p=lab04 part1.cpp part2.cpp part3.cpp part4.cpp