Python first of the series

I need support with this Python question so I can learn better.

Objective

Demonstrate an understanding of:

  • enumerate
  • a = b if c else d assignment pattern

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. I will give this once the tutor is chosen!

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 (99, 112, 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.

Sample Run

Your sample run should show that menu items 4 through 7 function correctly with and without a dataset loaded, and using various filters.

Your output can be different as long as it meets the criteria above. Be sure to check that your numerical values match those below. I have included a large sample run here. I recommend that you go through each of the same steps and make sure your code provides the same options and information.

 _x000D_
Please enter your name: Eric_x000D_
Hi Eric, welcome to Foothill's database project._x000D_
What is your home currency?EUR_x000D_
Enter a header for the menu: _x000D_
AIRbnb Dataset_x000D_
Options for converting from USD:_x000D_
USD       EUR       CAD       GBP       CHF       NZD       AUD       JPY       _x000D_
11.11     10.00     15.56     8.89      10.56     18.44     18.00     1199.11   _x000D_
22.22     20.00     31.11     17.78     21.11     36.89     36.00     2398.22   _x000D_
33.33     30.00     46.67     26.67     31.67     55.33     54.00     3597.33   _x000D_
44.44     40.00     62.22     35.56     42.22     73.78     72.00     4796.44   _x000D_
55.56     50.00     77.78     44.44     52.78     92.22     90.00     5995.56   _x000D_
66.67     60.00     93.33     53.33     63.33     110.67    108.00    7194.67   _x000D_
77.78     70.00     108.89    62.22     73.89     129.11    126.00    8393.78   _x000D_
88.89     80.00     124.44    71.11     84.44     147.56    144.00    9592.89   _x000D_
100.00    90.00     140.00    80.00     95.00     166.00    162.00    10792.00  _x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 4_x000D_
Please Load a Dataset First_x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 5_x000D_
Please Load a Dataset First_x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 6_x000D_
Please Load a Dataset First_x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 7_x000D_
Please Load a Dataset First_x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 8_x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 4_x000D_
The following data are from properties matching these criteria:_x000D_
- Private room_x000D_
- Entire home / apt_x000D_
                    Minimum             Average             Maximum _x000D_
Bronx               $ 40.00             $ 40.00             $ 40.00             _x000D_
Manhattan           $ 99.00             $ 143.57            $ 196.00            _x000D_
Queens              $ 350.00            $ 350.00            $ 350.00            _x000D_
Staten Island       $ 70.00             $ 70.00             $ 70.00             _x000D_
Brooklyn            $ 50.00             $ 118.00            $ 200.00            _x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 7_x000D_
The following labels are in the dataset:_x000D_
1: Private room         ACTIVE _x000D_
2: Entire home / apt    ACTIVE _x000D_
Please select an item to toggle or enter a blank line when you are finished.1_x000D_
The following labels are in the dataset:_x000D_
1: Private room         INACTIVE _x000D_
2: Entire home / apt    ACTIVE _x000D_
Please select an item to toggle or enter a blank line when you are finished._x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 4_x000D_
The following data are from properties matching these criteria:_x000D_
- Entire home / apt_x000D_
                    Minimum             Average             Maximum _x000D_
Bronx               N/A                 N/A                 N/A                 _x000D_
Manhattan           $ 100.00            $ 156.20            $ 196.00            _x000D_
Queens              $ 350.00            $ 350.00            $ 350.00            _x000D_
Staten Island       N/A                 N/A                 N/A                 _x000D_
Brooklyn            $ 150.00            $ 166.67            $ 200.00            _x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 7_x000D_
The following labels are in the dataset:_x000D_
1: Private room         INACTIVE _x000D_
2: Entire home / apt    ACTIVE _x000D_
Please select an item to toggle or enter a blank line when you are finished.2_x000D_
The following labels are in the dataset:_x000D_
1: Private room         INACTIVE _x000D_
2: Entire home / apt    INACTIVE _x000D_
Please select an item to toggle or enter a blank line when you are finished._x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 4_x000D_
The following data are from properties matching these criteria:_x000D_
                    Minimum             Average             Maximum _x000D_
Bronx               N/A                 N/A                 N/A                 _x000D_
Manhattan           N/A                 N/A                 N/A                 _x000D_
Queens              N/A                 N/A                 N/A                 _x000D_
Staten Island       N/A                 N/A                 N/A                 _x000D_
Brooklyn            N/A                 N/A                 N/A                 _x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 5_x000D_
The following data are from properties matching these criteria:_x000D_
- Manhattan_x000D_
- Queens_x000D_
- Staten Island_x000D_
- Brooklyn_x000D_
- Bronx_x000D_
                    Minimum             Average             Maximum _x000D_
Private room        $ 40.00             $ 86.44             $ 125.00            _x000D_
Entire home / apt   $ 100.00            $ 181.22            $ 350.00            _x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 6_x000D_
The following labels are in the dataset:_x000D_
1: Bronx                ACTIVE _x000D_
2: Manhattan            ACTIVE _x000D_
3: Queens               ACTIVE _x000D_
4: Staten Island        ACTIVE _x000D_
5: Brooklyn             ACTIVE _x000D_
Please select an item to toggle or enter a blank line when you are finished.1_x000D_
The following labels are in the dataset:_x000D_
1: Bronx                INACTIVE _x000D_
2: Manhattan            ACTIVE _x000D_
3: Queens               ACTIVE _x000D_
4: Staten Island        ACTIVE _x000D_
5: Brooklyn             ACTIVE _x000D_
Please select an item to toggle or enter a blank line when you are finished._x000D_
_x000D_
AIRbnb Dataset_x000D_
Main Menu_x000D_
1 - Print Average Rent by Location and Property Type_x000D_
2 - Print Minimum Rent by Location and Property Type_x000D_
3 - Print Maximum Rent by Location and Property Type_x000D_
4 - Print Min/Avg/Max by Location_x000D_
5 - Print Min/Avg/Max by Property Type_x000D_
6 - Adjust Location Filters_x000D_
7 - Adjust Property Type Filters_x000D_
8 - Load Data_x000D_
9 - Quit_x000D_
What is your choice? 9_x000D_
Goodbye!  Thank you for using the database_x000D_
_x000D_
Process finished with exit code 0

Order this or a similar paper and get 20% discount on your first order with us. Use coupon: GET20