Question: INSTRUTIONS: In main ( ) , instantiate an object current _ set of type TempDataset ( ) . Update the function calls in our menu

INSTRUTIONS:
In main(), instantiate an object current_set of type TempDataset().
Update the function calls in our menu that pass the argument current_set. They currently pass the argument None, they should pass the dataset name.
Run this code to make sure you have no stray lines. Your menu should run just as in Assignment 7. Now we are ready to build on this code!
We will start with process_file(). This method has filename as one of its parameters. We need to try (hint) to open this file for reading. If we can't open it, we need to return False. Once you have that coded, you must test it by calling process_file("Temperatures2022-03-07.csv") and process_file("Blah"). Remember, these are instance methods in our class, so you need to call them using the current_set object we created. The first should quietly succeed if you have downloaded the data file and put it in the correct directory. The second should return False. If the unit-test code is retuned False,
Continuing in process_file(), recall that we have a variable _data_set in our class that was initialized to None. We want to reinitialize this as an empty list. Remember that this variable is an instance attribute in the class, be careful not to create another variable that is local to the method process_file()!
In a loop, we read-in each line from the file. We'll need to do type conversions to make day and sensor as ints and temp as a float. We also must convert Time of Day to a number that represents the hour of the day. Multiply the given time by 24, and then use math.floor to round the result down to an integer between 0 and 23(you will need to import the math library (import math) at the top of your module to use the floor function).
We want to discard anything other than a temp reading (how?). For temperature readings, we will make a tuple:
(day, time, sensor, temp)
and add the tuple to the list _data_set.
We will assume that the data in the file is correct. We should be handling errors in the reading of the data, but for our purposes, if we get past opening the file, we'll assume that everything else will go smoothly. Feel free to improve on this by returning False if any kind of load error happens throughout the process.
Continue until we are done with the list, and return True!
Next we implement get_loaded_temps()
This method is simple. If we have not successfully loaded a data file, it should return None. Otherwise, it should return the number of samples that were loaded (an int). How we can check to verify that data file has been loaded, by looking at _data_set?
Finally, new_file()
def main():
sensor_list =[
("4201", "Foundations Lab", 1),
("4204","CS Lab", 2),
("4205", "Tiled Room", 3),
("4213", "STEM Center", 4),
("4218", "Workshop Room", 5),
("Out", "Outside", 6)
]
filter_list =[sensor[2] for sensor in sensor_list] # Initially all sensors are active
sensors ={
1: {'room_name': 'Foundations Lab', 'room_number': '4201', 'sensor_number': 1},
2: {'room_name': 'CS Lab', 'room_number': '4204', 'sensor_number': 2},
3: {'room_name': 'Tiled Room', 'room_number': '4205', 'sensor_number': 3},
4: {'room_name': 'STEM Center', 'room_number': '4213', 'sensor_number': 4},
5: {'room_name': 'Workshop Room', 'room_number': '4218', 'sensor_number': 5},
6: {'room_name': 'Outside', 'room_number': 'Out', 'sensor_number': 6}
}
sensor_list = recursive_sort(sensor_list)
while True:
change_filter(sensors, sensor_list, filter_list)
if __name__=="__main__":
main()
n_objects =0 # number of objects for this class
@property
def name(self):
return self._name
@name.setter
def name(self, new_name):
# raise value error if inappropriate length of names
if len(new_name)<3 or len(new_name)>20:
raise ValueError('Length of the name should be between 3 and 20 characters length')
self._name = new_name
def __init__(self):
self._data_set = None
self._name = 'Unnamed'
# increment number of objects by 1
TempDataset.n_objects +=1
def process_file(self, filename):
return False
def get_summary_statistics(self, active_sensors):
if self._data_set is None:
# return None is data_set is None
return None
else:
# return default tuple (0,0,0) otherwise
return (0,0,0)
def get_avg_temperature_day_time(self, active_sensors, day, time):
if self._data_set is None:
# return None is data_set is None
return None
else:
# return 0 otherwise
return 0
def get_num_temps(self, active_sensors, lower_bound, upper_bound):
if self._data_set is None:

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!