There are a lot of details to deal with here. Take each bit one at a time, and ask lots of questions. Start with your code from Assignment Eight.
_table_statistics(self, row_category: Categories, label: str)
Given a category from the Categories Enum, and a string matching one of the items in that category, calculate the minimum, maximum and average rent for the properties in that category, but those values should be filtered.
How do we filter the values? Let's demonstrate by example.
Suppose _active_labels[Categories.PROPERTY_TYPE] = {"Private Room"}. In other words, "Entire home / apt" has been filtered out.
If we call _table_statistics(Categories.LOCATION, "Manhattan"), we are asking for the min, avg and max rent for Manhattan. But only for properties that match "Private Room". There are only two matching properties in our default data. We should get back a tuple (98, 111.5, 125).
It might be a good idea to test using this example.
Because this method is intended private, you do not need to provide any protection from bad arguments.
display_field_table(self, rows: Categories)
Raise EmptyDatasetError if no data is loaded.
Notice that one of the two categories was passed. Display a table of the minimum, maximum and average rent for each item in that category. The data presented should be filtered. Print out the labels that are currently active, and use _table_statistics() to gather the data.
get_labels(self, category: Categories)
Returns a list of the items in _labels[category].
get_active_labels(self, category: Categories)
Returns a list of the items in _active_labels[category].
toggle_active_label(self, category: Categories, descriptor: str)
This public method will add or remove labels from _active_labels, allowing the user to filter out certain property types or locations.
If the passed descriptor is not a label in _labels[category], raise KeyError. Otherwise:
manage_filters(dataset: DataSet, category: DataSet.Categories)
Using the DataSet methods get_labels(), get_active_labels(), and toggle_active_label():
See the sample run for an idea of how to present this.
Note the following requirements:
menu() function
We have now implemented items 4 through 7 from our menu. Adjust the menu() function to call manage_filters() or display_field_table() with the appropriate arguments. Catch any EmptyDatasetError that is raised and provide an appropriate message to the user.
Get Free Quote!
445 Experts Online