Python Question

Description

Why a Class?

Don't use plagiarized sources. Get Your Custom Assignment on
Python Question
From as Little as $13/Page

Why would we make a class for our temperature data? As an object-oriented 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 my_dataset.name = “temps”. The internal variable will need to have a different name.

For the setter, if the name supplied is between 3 and 20 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 non-printable characters such as n

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 _data_set. For now we will set this to None. We also need to instantiate a variable to hold the name of the dataset – a user-friendly 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.

PROCESS_FILE()

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.

GET_SUMMARY_STATISTICS()

This method takes a single argument filter_list. For now, it will return None if the internal dataset is None, otherwise, return a default tuple (0,0,0).

GET_AVG_TEMPERATURE_DAY_TIME()

This method takes 3 arguments: filter_list, day, and time. For now, it will return None if the internal dataset is None, otherwise, return 0.

GET_NUM_TEMPS()

This method takes 3 arguments: filter_list, lower_bound, and upper_bound. For now, it will return None if the internal dataset is None, otherwise, return 0.

GET_LOADED_TEMPS()

fThis method takes no arguments. For now, it will return None if the internal dataset is None, otherwise, return 0.

Class Methods
GET_NUM_OBJECTS()

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 class is perfect – but a failed run means something is definitely wrong.