Question: Why would we make a class for our temperature data? As an object - oriented programmer, your answer eventually should be , why not? Just
Why would we make a class for our temperature data? As an objectoriented programmer, your answer eventually should be why not? Just about any time we have data that we want to be able to store, access, and manipulate, the data should be encapsulated into a class. This means that the client program in our case, main never sees or modifies the raw data. Instead, we create an abstraction The data itself is hidden and we expose methods to access or change the data.
Eventually, we will want to be able to do the following:
Create an object of type TempDataset
Load temperature data into that object
Name our dataset and ask for its name
Ask for the number of temperature samples in the dataset
Ask for the number of temperature samples within a certain range
Ask for the average temperature for a particular day of the week and hour of the day
Get the minimum, average, and maximum temperature as a tuple
Find out how many objects of TempDataset have been created
For many of these, we may also want to apply a filter to limit the response to certain sensors
Because this is an abstraction much of the implementation details are up to you. You can choose the internal variable names, for example. We do need to agree upon the names of the public methods and the exact responses we expect. Some of these methods we will implement now, others we will implement in upcoming assignments. Every method needs to give some response now, though, so we can test that everything is in order.
The Spec for TempDataset:
Class variables:
Create one class variable to hold the number of TempDataset objects that have been created, This variable should initially be set to zero.
Remember the following are methods in a class. So even if I say they take no arguments, they still should have a first parameter self or cls
Properties
Create a getter and setter for your variable that holds the name of the dataset. Use @property and @name.setter as described in the lectures. The getter will simply return the name. Note: the client should be able to access this using the variable name, as in mydataset.name "temps". The internal variable will need to have a different name.
For the setter, if the name supplied is between and characters inclusive, set the instance name variable to this new name. If the name supplied is too short or too long, raise a ValueError exception.
We are not doing any other checking, but we might consider rejecting the proposed name if it is not a string, or if it contains nonprintable characters such as
Instance Methods
init
The init method for our class will not take an argument.
We need to instantiate an instance variable to hold the data, let's call it dataset. For now we will set this to None. We also need to instantiate a variable to hold the name of the dataset a userfriendly header that we will display on our reports. For now we should set this to "Unnamed".
Finally, init should increment the class variable holding the total number of objects.
init never has a return value.
processfile
This method takes a single argument filename, the name of the file to be processed. We will implement this later, but for now let's just have it return False all the time.
getsummarystatistics
This method takes a single argument filterlist. For now, it will return None if the internal dataset is None, otherwise, return a default tuple
getavgtemperaturedaytime
This method takes arguments: filterlist, day, and time. For now, it will return None if the internal dataset is None, otherwise, return
getnumtemps
This method takes arguments: filterlist, lowerbound, and upperbound. For now, it will return None if the internal dataset is None, otherwise, return
getloadedtemps
fThis method takes no arguments. For now, it will return None if the internal dataset is None, otherwise, return
Class Methods
getnumobjects
This is a class method you may want to review what this means before you implement it This getter simply returns the value in the class variable you created the total number of objects that have been created of the type TempDataset. Implement this now. Note that we cannot use @property for a class method.
Unit Test Provided
For now, code up your class in a module separate from the rest of your work. We'll incorporate it into the project in the next assignment.
After you write the code for the class, append this unit test into the same module and run the module. Success running the unit test does not mean your code is perfect, the unit test is just meant to provide an indication that the public face of your class works as requested.
You should submit, in one file, your class with appropriate docstrings the appended unit test, and a sample run of the unit test. Again, a successful run of the unit test does not mean your
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
