IMPLEMENTING OUR CHOOSE UNIT FUNCTION / PRINTING SOME STATISTICS

    May 5, 2024

 
IMPLEMENTING OUR CHOOSE UNIT FUNCTION / PRINTING SOME STATISTICS
This is truly exciting. We’ve now got data loaded into our current_set object, and we are ready to display that data!
First, in order to make our program internationally useful and also recognized by the broad scientific community, we must implement our choose_unit() function, use our previously implemented convert_unit() function.
We need to create a global integer variable (not a constant, be sure to use the right naming convention) to hold the current unit selection and provide a default value. Name this variable current_unit. The variable, current_unit should have a default value that indicates units in Celsius.
We will use a global constant dictionary to contain valid unit. Because dictionaries are old news to us, I’m giving it to you. (What makes it is global constant?
UNITS = {
0: (“Celsius”, “C”),
1: (“Fahrenheit”, “F”),
2: (“Kelvin”, “K”),
}

Next, we need to create a function to choose unit. It should provide the following functionality:
REPORT what the current unit is
GIVE A MENU of the available units
ASK the user to choose a new unit. Do not leave until the user chooses correctly. Be sure to filter for non-integer values.
CHANGE current_unit to the user’s selection.
Important: You should use the dictionary above to generate the menu options and validate the user selection.
When called, your function should generate something like this:
STEM Center Temperature ProjectMike MurphyMain Menu———1 – Process a new data file2 – Choose unit3 – Edit room filter4 – Show summary statistics5 – Show temperature by date and time6 – Show histogram of temperatures7 – QuitWhat is your choice? 2Current unit in CelsiusChoose new unit:0 – Celsius1 – Fahrenheit2 – KelvinWhich unit?1Main Menu———1 – Process a new data file2 – Choose unit3 – Edit room filter4 – Show summary statistics5 – Show temperature by date and time6 – Show histogram of temperatures7 – QuitWhat is your choice? 2Current unit is FahrenheitChoose new unit:0 – Celsius1 – Fahrenheit2 – KelvinWhich unit?2Main Menu———1 – Process a new data file2 – Choose unit3 – Edit room filter4 – Show summary statistics5 – Show temperature by date and time6 – Show histogram of temperatures7 – QuitWhat is your choice? 2Current unit is KelvinChoose new unit:0 – Celsius1 – Fahrenheit2 – KelvinWhich unit?43Please choose a unit from the listChoose new unit:0 – Celsius1 – Fahrenheit2 – KelvinWhich unit?a*** Please enter a number only ***Choose new unit:0 – Celsius1 – Fahrenheit2 – KelvinWhich unit?0Main Menu———1 – Process a new data file2 – Choose unit3 – Edit room filter4 – Show summary statistics5 – Show temperature by date and time6 – Show histogram of temperatures7 – QuitWhat is your choice?
Now, let’s make sure you implemented this correctly. Add an item to the dictionary so it looks like this WITHOUT MAKING ANY OTHER CHANGES TO YOUR CODE:
UNITS = { 0: (“Celsius”, “C”), 1: (“Fahrenheit”, “F”), 2: (“Kelvin”, “K”), 5: (“Rankine”, “R”)}
Of course, this won’t work with our convert_unit() function, but it’s okay, it’ll only be there for a second. Now make sure you can reproduce this, including the error entry of 4:
STEM Center Temperature ProjectMike MurphyMain Menu———1 – Process a new data file2 – Choose unit3 – Edit room filter4 – Show summary statistics5 – Show temperature by date and time6 – Show histogram of temperatures7 – QuitWhat is your choice? 2Current unit is CelsiusChoose new unit:0 – Celsius1 – Fahrenheit2 – Kelvin5 – RankineWhich unit?4Please choose a unit from the listChoose new unit:0 – Celsius1 – Fahrenheit2 – Kelvin5 – RankineWhich unit?5Main Menu———1 – Process a new data file2 – Choose unit3 – Edit room filter4 – Show summary statistics5 – Show temperature by date and time6 – Show histogram of temperatures7 – QuitWhat is your choice? 2Current unit is RankineChoose new units:0 – Celsius1 – Fahrenheit2 – Kelvin5 – RankineWhich unit?
Now make sure you remove the Rankine line.
Alright, got that. You should test your convert_unit() function, and make sure it works
We now need to implement the method get_avg_temperature_day_time(self, filter_list, day, time). I listed the parameters to remind you. We still want it to return None if there is no dataset loaded. We also want it to return None if there are no sensors active in filter_list or if the active sensors have no readings (you can do both in one statement!). If there are readings available, we want it to find all the samples based on our filter_list at a particular day of week and time of day, and return the average as a float (also known as a floating-point number).
It’s your job to determine how to implement this. I used a list comprehension to create a list of just the temperature field of each matching line, then it was easy to calculate the average. I encourage you to use a list comprehension. They are elegant, especially when we are filtering a few values like this, and they are one of the best-known features of Python. Remember, this function must not print anything out.
Once you have implemented this function, let’s make sure that it is working. Add a line after your call to print_menu() like this:
print(current_set.get_avg_temperature_day_time(filter_list, 5, 7))

Trust your assignments to an essay writing service with the fastest delivery time and fully original content.

Verified