Sale!

CPSC223 Lab 5

$30.00 $18.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (1 vote)

Program Instructions

1. All the functions should accept the weather dictionary data structure as follows:
weather dictionary:
key : datetime as string (formatted as YYYYMMDDhhmmss)
value : readings dictionary
readings dictionary
for key : ‘t’
value : temperature as integer
for key : ‘h’
value : humidity as integer
for key : ‘r’
value : rainfall as float

2. Create a weather module.
i. Create a function named read_data which receives a keyword
parameter filename.

a. The function should open the filename in read mode and return a
dictionary of the JSON decoded contents of the file.

b. If the file does not exist, the function should accept the
FileNotFoundError and return an empty dictionary.
ii. Create a function named write_data which receives a keyword
parameter data (the dictionary) and filename

a. The function should open the filename in write mode and write the
dictionary data into the file encoded as JSON.

iii. Create a function named max_temperature which receives a keyword
parameter data and date

a. The function should return the maximum temperature for all
dictionary data where the key contains the date as YYYYMMDD.
iv. Create a function named min_temperature which receives a keyword
parameter data and date

a. The function should return the minimum temperature for all
dictionary data where the key contains the date as YYYYMMDD.

v. Create a function named max_humidity which receives a keyword
parameter data and date
a. The function should return the maximum humidity for all dictionary
data where the key contains the date as YYYYMMDD.

vi. Create a function named min_humidity which receives a keyword
parameter data and date
a. The function should return the minimum humidity for all dictionary
data where the key contains the date as YYYYMMDD.

vii. Create a function named tot_rain which receives a keyword
parameter data and date
a. The function should return the sum of rainfall for all dictionary data
where the key contains the date as YYYYMMDD.

viii. Create a function named report_daily which receives a keyword
parameter data and date
a. The function should return a single string which when passed to
any print function will display on the screen formatted exactly as
indicated in the example output below. You will most likely be
appending strings together using a literal “\n” where a newline is
desired. To get the month name, you can import the
builtin calendar module and call the month_name function passing it
the month as an integer.

ix. Create a function named report_historical which receives a keyword
parameter data
a. The function should return a single string which when passed to
any print function will display on the screen formatted exactly as
indicated in the example output below.

You will most likely be
appending strings together using a literal “\n” where a newline is
desired. To get the month name, you can import the
builtin calendar module and call the month_name function passing it
the month as an integer.

3. Create a main driver program to meet the following requirements:
i. Create a file named main.py.
ii. Import the weather module.
iii. Set a default filename to store the JSON data.
iv. Declare a dictionary to hold the weather data.

v. Implement a menu within a loop with following choices:
a. Set data filename
a. Prompt the user for a filename.
b. Call the weather read_data function.
c. Using the return value set the weather data dictionary.

b. Add weather data
a. Prompt the user for the date using the format YYYYMMDD.
b. Prompt the user for the time using the format hhmmss.
c. Prompt the user for the temperature.
d. Prompt the user for the humidity.
e. Prompt the user for the rainfall.

f. Add the above readings to the weather dictionary.
g. Call the weather write_data function to add the dictionary to
the JSON encoded file.
c. Print daily report

a. Prompt the user for the date using the format YYYYMMDD.
b. Call the weather report_daily function.
c. Print out the return string.
d. Print historical report

a. Call the weather report_historical function.
b. Print out the return string.
e. Exit the program
4. Example input and output:

*** TUFFY TITAN WEATHER LOGGER MAIN MENU
1. Set data filename
2. Add weather data
3. Print daily report
4. Print historical report
9. Exit the program
Enter menu choice: 1
Enter data filename: w.dat

*** TUFFY TITAN WEATHER LOGGER MAIN MENU
1. Set data filename
2. Add weather data
3. Print daily report
4. Print historical report
9. Exit the program
Enter menu choice: 2
Enter date (YYYYMMDD): 20220107
Enter time (hhmmss): 133059
Enter temperature: 82
Enter humidity: 56
Enter rainfall: 0.2

*** TUFFY TITAN WEATHER LOGGER MAIN MENU
1. Set data filename
2. Add weather data
3. Print daily report
4. Print historical report
9. Exit the program
Enter menu choice: 3
Enter date (YYYYMMDD): 20210203

========================= DAILY REPORT ========================
Date Time Temperature Humidity Rainfall
==================== ======== =========== ======== ========
February 3, 2021 07:55:01 55 87 0.00
February 3, 2021 09:06:02 63 84 0.00
February 3, 2021 10:29:03 71 79 0.00
February 3, 2021 12:55:04 72 69 0.00
February 3, 2021 18:39:05 59 75 0.00

*** TUFFY TITAN WEATHER LOGGER MAIN MENU
1. Set data filename
2. Add weather data
3. Print daily report
4. Print historical report
9. Exit the program
Enter menu choice: 4

============================== HISTORICAL REPORT ===========================
Minimum Maximum Minumum Maximum Total
Date Temperature Temperature Humidity Humidity Rainfall
==================== =========== =========== ======== ======== ========
February 3, 2021 55 72 69 87 0.00
February 5, 2021 57 74 56 68 0.36
May 17, 2021 65 82 31 43 0.00
September 1, 2021 73 101 82 94 0.52
November 26, 2021 62 73 20 32 0.00
December 25, 2021 34 46 2 11 0.01
January 1, 2022 56 56 33 33 0.00
January 7, 2022 82 82 56 56 0.20

*** TUFFY TITAN WEATHER LOGGER MAIN MENU
1. Set data filename
2. Add weather data
3. Print daily report
4. Print historical report
9. Exit the program
Enter menu choice: 9