Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Sales module
- Data table structure:
- * id (string): Unique and random generated identifier
- at least 2 special characters (except: ';'), 2 number, 2 lower and 2 upper case letters)
- * title (string): Title of the game sold
- * price (number): The actual sale price in USD
- * month (number): Month of the sale
- * day (number): Day of the sale
- * year (number): Year of the sale
- """
- # everything you'll need is imported:
- # User interface module
- import ui
- # data manager module
- import data_manager
- # common module
- import common
- def handle_menu():
- options = ["Show all", "Add new", "Remove from list", "Update"]
- menu_title = "Sales module"
- exit_message = "Back to main menu"
- ui.print_menu(menu_title, options, exit_message)
- def choose():
- FILE_PATH = 'sales/sales.csv'
- inputs = ui.get_inputs(["Please enter a number: "], "")
- option = inputs[0]
- table = data_manager.get_table_from_file(FILE_PATH)
- if option == "1":
- show_table(table)
- elif option == "4":
- show_table(table)
- id = ui.get_inputs(["Please enter id: "], "")
- if option == "0":
- return False
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- def update_handle_menu():
- options = ["Change title", "Change price", "Change day", "Update month", "Change year"]
- menu_title = "Sales module---> Update"
- exit_message = "Back to main menu"
- ui.print_menu(menu_title, options, exit_message)
- def choose_to_update():
- inputs = ui.get_inputs(["Please enter a number: "], "")
- option = inputs[0]
- if option == "1":
- title = ui.get_inputs(["Please enter new title: "], "")
- elif option == "1":
- rice = ui.get_inputs(["Please enter new price "], "")
- elif option == "1":
- day = ui.get_inputs(["Please enter new day: "], "")
- elif option == "1":
- month = ui.get_inputs(["Please enter new month: "], "")
- elif option == "1":
- year = ui.get_inputs(["Please enter new year: "], "")
- remove(table, id)
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- def start_module():
- """
- Starts this module and displays its menu.
- * User can access default special features from here.
- * User can go back to main menu from here.
- Returns:
- None
- """
- is_running = True
- while is_running:
- handle_menu()
- try:
- is_running = choose()
- except KeyError as err:
- ui.print_error_message(str(err))
- print('jestem w sales')
- # your code
- def show_table(table):
- """
- Display a table
- Args:
- table (list): list of lists to be displayed.
- Returns:
- None
- """
- title_list = ['id', 'title', 'price', 'month', 'day', 'year']
- ui.print_table(table, title_list)
- # your code
- def add(table):
- """
- Asks user for input and adds it into the table.
- Args:
- table (list): table to add new record to
- Returns:
- list: Table with a new record
- """
- # your code
- return table
- def remove(table, id):
- """
- Remove a record with a given id from the table.
- Args:
- table (list): table to remove a record from
- id_ (str): id of a record to be removed
- Returns:
- list: Table without specified record.
- """
- i = 0
- while (i < len(table)):
- if id[0] in table[i][0]:
- table.pop(i)
- i += 1
- ui.print_table_after_remove(table)
- # your code
- return table
- def update(table, id_):
- """
- Updates specified record in the table. Ask users for new data.
- Args:
- table (list): list in which record should be updated
- id_ (str): id of a record to update
- Returns:
- list: table with updated record
- """
- input = []
- record_to_update = []
- index_of_record_to_update = 0
- for index, record in enumerate(table):
- if record[0] == id_:
- record_to_update = record
- index_of_record_to_update = index
- # new_records.append(ui.get_inputs)
- # your code
- return table
- # special functions:
- # ------------------
- def get_lowest_price_item_id(table):
- """
- Question: What is the id of the item that was sold for the lowest price?
- if there are more than one item at the lowest price, return the last item by alphabetical order of the title
- Args:
- table (list): data table to work on
- Returns:
- string: id
- """
- # your code
- def get_items_sold_between(table, month_from, day_from, year_from, month_to, day_to, year_to):
- """
- Question: Which items are sold between two given dates? (from_date < sale_date < to_date)
- Args:
- table (list): data table to work on
- month_from (int)
- day_from (int)
- year_from (int)
- month_to (int)
- day_to (int)
- year_to (int)
- Returns:
- list: list of lists (the filtered table)
- """
- # your code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement