Question: I have a python question. I did first part and I am not sure the second part. This assigment is based on other assignments. I

I have a python question. I did first part and I am not sure the second part. This assigment is based on other assignments. I upload my code of first part and this code covers toher assignments so you can use this code for second part. I could not upload the data file needed for this assignment and my code here since question is too long and its not allowed me to do that. So please provide way for me to upload:

First part of question is:

First, in order to make our program internationally useful and also recognized by the broad scientific community, is to implement our choose_units() function and use our previously implemented convert_units() function.

First 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 set a default value. Because I'm just crazy wild, I called my variable current_unit. The variable should have a default value that indicates units in Celsius.

We'll use a global constant dictionary to hold on to the valid units. Because dictionaries are old news to us, I'm giving it to you.

UNITS = { 0: ("Celsius", "C"), 1: ("Fahrenheit", "F"), 2: ("Kelvin", "K") }

Next we need to create a function to choose units. It should have the following functionality:

REPORT what the current units are

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_units to the user's selection.

Important: You should use the dictionary above to generate the menu options and validate the user selection. PAY ATTENTION TO THIS!

When called, your function should generate something like this:

STEM Center Temperature Project Eric Reed Main Menu --------- 1 - Process a new data file 2 - Choose units 3 - Edit room filter 4 - Show summary statistics 5 - Show temperature by date and time 6 - Show histogram of temperatures 7 - Quit What is your choice? 2 Current units in Celsius Choose new units: 0 - Celsius 1 - Fahrenheit 2 - Kelvin Which unit? 1 Main Menu --------- 1 - Process a new data file 2 - Choose units 3 - Edit room filter 4 - Show summary statistics 5 - Show temperature by date and time 6 - Show histogram of temperatures 7 - Quit What is your choice? 2 Current units in Fahrenheit Choose new units: 0 - Celsius 1 - Fahrenheit 2 - Kelvin Which unit? 2 Main Menu --------- 1 - Process a new data file 2 - Choose units 3 - Edit room filter 4 - Show summary statistics 5 - Show temperature by date and time 6 - Show histogram of temperatures 7 - Quit What is your choice? 2 Current units in Kelvin Choose new units: 0 - Celsius 1 - Fahrenheit 2 - Kelvin Which unit? 43 Please choose a unit from the list Choose new units: 0 - Celsius 1 - Fahrenheit 2 - Kelvin Which unit? a *** Please enter a number only *** Choose new units: 0 - Celsius 1 - Fahrenheit 2 - Kelvin Which unit? 0 Main Menu --------- 1 - Process a new data file 2 - Choose units 3 - Edit room filter 4 - Show summary statistics 5 - Show temperature by date and time 6 - Show histogram of temperatures 7 - Quit What is your choice?

Now, let's make sure you implemented this correctly. Add a 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 wouldn't work with our convert_units() 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 Project Eric Reed Main Menu --------- 1 - Process a new data file 2 - Choose units 3 - Edit room filter 4 - Show summary statistics 5 - Show temperature by date and time 6 - Show histogram of temperatures 7 - Quit What is your choice? 2 Current units in Celsius Choose new units: 0 - Celsius 1 - Fahrenheit 2 - Kelvin 5 - Rankine Which unit? 4 Please choose a unit from the list Choose new units: 0 - Celsius 1 - Fahrenheit 2 - Kelvin 5 - Rankine Which unit? 5 Main Menu --------- 1 - Process a new data file 2 - Choose units 3 - Edit room filter 4 - Show summary statistics 5 - Show temperature by date and time 6 - Show histogram of temperatures 7 - Quit What is your choice? 2 Current units in Rankine Choose new units: 0 - Celsius 1 - Fahrenheit 2 - Kelvin 5 - Rankine Which unit?

Now make sure you take that Rankine line out.

Alright, got that. You can test out your convert_units() function if you like, and make sure it works

Second part is:

Now we need to implement the method get_avg_temperature_day_time(self, active_sensors, day, time). I listed out the parameters to remind you. We still want it to return None if there is no dataset loaded. Now we also want it to return None if there are no sensors active in active_sensors or if the active sensors have no readings (you can do both in one statement!). And 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 floating point number (also known as a float).

It's up to you how to implement this. I used a list comprehension to create a list of just the temperature field of each matching line, and then it was easy to calculate the average. I do encourage you to do a list comprehension. They are oh, so 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 are done, let's check and make sure this is working for you. Add a line after your call to print_menu() like this:

 print(current_set.get_avg_temperature_day_time(filter_list, 5, 7))

We don't need an if statement like we did for the last assignment. This time we're being good programmers and using an accessor. If we don't have a dataset loaded the accessor will return None, and the print function will dutifully print None as well!

After loading the dataset though, you should see the number 20.4554411...... pop out. That's the average of temperatures on day 5 (Friday) at hour 7 (7AM-8AM). Now go to edit room filter and remove "Out". When you go back to the main menu you should see 20.86392..... No sense continuing until you get these numbers! Now go back and remove ALL the rooms from the filter. The average temp should report None.

Leave the testing line in for your submission, please, then remove it before the next assignment.

We'll use the get_avg_temperature_day_time() function for the next assignment, but as long as we're on a roll with summary statistics let's implement menu option 4. This should be a piece of cake, it's very similar to what we just did.

First implement get_summary_statistics(self, active_sensors) to return a tuple of floats with the minimum, maximum and average temperature of the sensors that are active inactive_sensors. If there is no data, this method should return None. Remember, this function must not print anything out, that's the job of our helper function, print_summary_statistics()...

Well, just take a look at the sample run and you'll know what to do for print_summary_statistics(). Remember to change "None" to the appropriate object names in the menu routine . Be sure print_summary_statistics() behaves well in these situations:

Normal operation (all sensors active, and some sensors filtered)

No data loaded

All sensors off

Notice in the sample run that temperatures are rounded to two decimal places. Notice also that the units are listed! Those should come from the units dictionary, of course, not from some kind of if statement. Hint, in this case the units dictionary behaves "sort-of" like a multi-dimensional array, as described in the modules. That also means you need to use convert_units to get the right values. Finally, note that the name we gave the dataset is printed out with the summary statistics!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!