Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. """ Sales module
  2.  
  3. Data table structure:
  4. * id (string): Unique and random generated identifier
  5. at least 2 special characters (except: ';'), 2 number, 2 lower and 2 upper case letters)
  6. * title (string): Title of the game sold
  7. * price (number): The actual sale price in USD
  8. * month (number): Month of the sale
  9. * day (number): Day of the sale
  10. * year (number): Year of the sale
  11. """
  12.  
  13. # everything you'll need is imported:
  14. # User interface module
  15. import ui
  16. # data manager module
  17. import data_manager
  18. # common module
  19. import common
  20.  
  21. def handle_menu():
  22. options = ["Show all", "Add new", "Remove from list", "Update"]
  23. menu_title = "Sales module"
  24. exit_message = "Back to main menu"
  25. ui.print_menu(menu_title, options, exit_message)
  26.  
  27. def choose():
  28. FILE_PATH = 'sales/sales.csv'
  29. inputs = ui.get_inputs(["Please enter a number: "], "")
  30. option = inputs[0]
  31. table = data_manager.get_table_from_file(FILE_PATH)
  32. if option == "1":
  33. show_table(table)
  34. elif option == "4":
  35. show_table(table)
  36. id = ui.get_inputs(["Please enter id: "], "")
  37. if option == "0":
  38. return False
  39. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  40. def update_handle_menu():
  41. options = ["Change title", "Change price", "Change day", "Update month", "Change year"]
  42. menu_title = "Sales module---> Update"
  43. exit_message = "Back to main menu"
  44. ui.print_menu(menu_title, options, exit_message)
  45.  
  46. def choose_to_update():
  47. inputs = ui.get_inputs(["Please enter a number: "], "")
  48. option = inputs[0]
  49. if option == "1":
  50. title = ui.get_inputs(["Please enter new title: "], "")
  51. elif option == "1":
  52. rice = ui.get_inputs(["Please enter new price "], "")
  53. elif option == "1":
  54. day = ui.get_inputs(["Please enter new day: "], "")
  55. elif option == "1":
  56. month = ui.get_inputs(["Please enter new month: "], "")
  57. elif option == "1":
  58. year = ui.get_inputs(["Please enter new year: "], "")
  59. remove(table, id)
  60. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  61. def start_module():
  62. """
  63. Starts this module and displays its menu.
  64. * User can access default special features from here.
  65. * User can go back to main menu from here.
  66.  
  67. Returns:
  68. None
  69. """
  70. is_running = True
  71. while is_running:
  72. handle_menu()
  73. try:
  74. is_running = choose()
  75. except KeyError as err:
  76. ui.print_error_message(str(err))
  77. print('jestem w sales')
  78.  
  79.  
  80. # your code
  81.  
  82.  
  83. def show_table(table):
  84. """
  85. Display a table
  86.  
  87. Args:
  88. table (list): list of lists to be displayed.
  89.  
  90. Returns:
  91. None
  92. """
  93. title_list = ['id', 'title', 'price', 'month', 'day', 'year']
  94. ui.print_table(table, title_list)
  95. # your code
  96.  
  97.  
  98. def add(table):
  99. """
  100. Asks user for input and adds it into the table.
  101.  
  102. Args:
  103. table (list): table to add new record to
  104.  
  105. Returns:
  106. list: Table with a new record
  107. """
  108.  
  109. # your code
  110.  
  111. return table
  112.  
  113.  
  114. def remove(table, id):
  115. """
  116. Remove a record with a given id from the table.
  117.  
  118. Args:
  119. table (list): table to remove a record from
  120. id_ (str): id of a record to be removed
  121.  
  122. Returns:
  123. list: Table without specified record.
  124. """
  125.  
  126. i = 0
  127.  
  128. while (i < len(table)):
  129. if id[0] in table[i][0]:
  130. table.pop(i)
  131. i += 1
  132.  
  133. ui.print_table_after_remove(table)
  134.  
  135. # your code
  136.  
  137. return table
  138.  
  139.  
  140. def update(table, id_):
  141. """
  142. Updates specified record in the table. Ask users for new data.
  143.  
  144. Args:
  145. table (list): list in which record should be updated
  146. id_ (str): id of a record to update
  147.  
  148. Returns:
  149. list: table with updated record
  150. """
  151. input = []
  152. record_to_update = []
  153. index_of_record_to_update = 0
  154. for index, record in enumerate(table):
  155. if record[0] == id_:
  156. record_to_update = record
  157. index_of_record_to_update = index
  158.  
  159. # new_records.append(ui.get_inputs)
  160.  
  161.  
  162. # your code
  163.  
  164. return table
  165.  
  166.  
  167. # special functions:
  168. # ------------------
  169.  
  170. def get_lowest_price_item_id(table):
  171. """
  172. Question: What is the id of the item that was sold for the lowest price?
  173. if there are more than one item at the lowest price, return the last item by alphabetical order of the title
  174.  
  175. Args:
  176. table (list): data table to work on
  177.  
  178. Returns:
  179. string: id
  180. """
  181.  
  182. # your code
  183.  
  184.  
  185. def get_items_sold_between(table, month_from, day_from, year_from, month_to, day_to, year_to):
  186. """
  187. Question: Which items are sold between two given dates? (from_date < sale_date < to_date)
  188.  
  189. Args:
  190. table (list): data table to work on
  191. month_from (int)
  192. day_from (int)
  193. year_from (int)
  194. month_to (int)
  195. day_to (int)
  196. year_to (int)
  197.  
  198. Returns:
  199. list: list of lists (the filtered table)
  200. """
  201.  
  202. # your code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement