Gorcupt

2-3

Mar 28th, 2022
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. import pickle
  2. from threading import Thread
  3. import multiprocessing.dummy as multiprocessing
  4.  
  5.  
  6. def mostSell_Laptop():
  7. myList = loadSellPickle()
  8. laptopList = []
  9. for elem in myList:
  10. laptopList.append(elem[1])
  11. print('\nСамый продаваемый ноутбук')
  12. print(max(set(laptopList), key=laptopList.count))
  13.  
  14.  
  15. def mostEffective_Employee():
  16. myList = loadSellPickle()
  17. employeeList = []
  18. for elem in myList:
  19. employeeList.append(elem[0])
  20. print('\nСамый эффективный сотрудник')
  21. print(max(set(employeeList), key=employeeList.count))
  22.  
  23.  
  24. def top5expensiveVideoCard():
  25. myList = loadSellPickle()
  26. myList.sort(key=lambda x: (int(x[3])))
  27. myList.reverse()
  28. mostExpensive = myList[:5]
  29. print('\nСамые дорогие видеокарты: ')
  30. for i in mostExpensive:
  31. print(i[2] + ' ' + i[3])
  32.  
  33.  
  34. def loadSellPickle():
  35. pList = pickle.load(open('pickle.pkl', 'rb'))
  36. return pList
  37.  
  38.  
  39. def addNewRow():
  40. mylist = loadSellPickle()
  41. nameEmployee = input('\nСотрудник, совершивший продажу: ')
  42. nameLaptop = input('Название ноутбука: ')
  43. nameVideoCard = input('Название видеокарты: ')
  44. price = input('Цена видеокарты: ')
  45. myTuple = (nameEmployee, nameLaptop, nameVideoCard, price)
  46. mylist.append(myTuple)
  47. with open('pickle.pkl', 'wb') as f:
  48. pickle.dump(mylist, f)
  49.  
  50.  
  51. def linearSolution():
  52. mostEffective_Employee()
  53. mostSell_Laptop()
  54. top5expensiveVideoCard()
  55.  
  56.  
  57. def threadingSolution():
  58. thread1 = Thread(target=mostEffective_Employee())
  59. thread2 = Thread(target=mostSell_Laptop())
  60. thread3 = Thread(target=top5expensiveVideoCard())
  61. thread1.start()
  62. thread2.start()
  63. thread3.start()
  64.  
  65. thread1.join()
  66. thread2.join()
  67. thread3.join()
  68.  
  69.  
  70. def processSolution():
  71. pool = multiprocessing.Pool()
  72. pool.map(lambda f: f(), [mostEffective_Employee])
  73. pool.map(lambda f: f(), [mostSell_Laptop])
  74. pool.map(lambda f: f(), [top5expensiveVideoCard])
  75. pool.close()
  76. pool.join()
  77.  
  78.  
  79. n = input('\n1-линейное решение\n2-решение с потоками\n3-решение с процессами\n4-добавить запись в '
  80. 'pickle\nexit-выход\nВвод ')
  81.  
  82. while n != 'exit':
  83. if n == '1':
  84. linearSolution()
  85. if n == '2':
  86. threadingSolution()
  87. if n == '3':
  88. processSolution()
  89. if n == '4':
  90. addNewRow()
  91. if n == 'exit':
  92. break
  93. n = input('\n1-линейное решение\n2-решение с потоками\n3-решение с процессами\n4-добавить запись в'
  94. ' pickle\nexit-выход\nВвод: ')
  95.  
Advertisement
Add Comment
Please, Sign In to add comment