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.

computer science

Description

Python Specification

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.

DataSet Class

_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:

  • add descriptor to _active_labels[category] if descriptor is not in the set or...
  • remove descriptor from _active_labels[category] if descriptor is in the set.

Module Level Functions

manage_filters(dataset: DataSet, category: DataSet.Categories)

Using the DataSet methods get_labels(), get_active_labels(), and toggle_active_label():

  • Print a menu-like list of all the labels for the given category
  • Indicate which ones are currently active (i.e. the string exists in dataset._active_labels[category]
  • Allow the user to change a label from active to inactive or from inactive to active
  • Loop until the user has finished making their choices

See the sample run for an idea of how to present this. 

Note the following requirements:

  • You must use enumerate to generate the menu items, and start with item 1
  • You must use the public getter and setter methods for Dataset.  Do not access the data directly.

Modifications to Existing Code

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.


Instruction Files

Related Questions in computer science category