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 currentset of type TempDataset
Update the function calls in our menu that pass the argument currentset. 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 Now we are ready to build on this code!
We will start with processfile 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 processfileTemperaturescsv and processfileBlah Remember, these are instance methods in our class, so you need to call them using the currentset 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 unittest code is retuned False,
Continuing in processfile recall that we have a variable dataset 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 processfile
In a loop, we readin 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 and then use math.floor to round the result down to an integer between and 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 dataset.
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 getloadedtemps
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 dataset?
Finally, newfile
def main:
sensorlist
"Foundations Lab",
CS Lab",
"Tiled Room",
"STEM Center",
"Workshop Room",
Out "Outside",
filterlist sensor for sensor in sensorlist # Initially all sensors are active
sensors
: roomname': 'Foundations Lab', 'roomnumber': 'sensornumber':
: roomname': CS Lab', 'roomnumber': 'sensornumber':
: roomname': 'Tiled Room', 'roomnumber': 'sensornumber':
: roomname': 'STEM Center', 'roomnumber': 'sensornumber':
: roomname': 'Workshop Room', 'roomnumber': 'sensornumber':
: roomname': 'Outside', 'roomnumber': 'Out', 'sensornumber':
sensorlist recursivesortsensorlist
while True:
changefiltersensors sensorlist, filterlist
if namemain:
main
nobjects # number of objects for this class
@property
def nameself:
return self.name
@name.setter
def nameself newname:
# raise value error if inappropriate length of names
if lennewname or lennewname:
raise ValueErrorLength of the name should be between and characters length'
self.name newname
def initself:
self.dataset None
self.name 'Unnamed'
# increment number of objects by
TempDataset.nobjects
def processfileself filename:
return False
def getsummarystatisticsself activesensors:
if self.dataset is None:
# return None is dataset is None
return None
else:
# return default tuple otherwise
return
def getavgtemperaturedaytimeself activesensors day, time:
if self.dataset is None:
# return None is dataset is None
return None
else:
# return otherwise
return
def getnumtempsself activesensors lowerbound, upperbound:
if self.dataset is None:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
