Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pickle
- from threading import Thread
- import multiprocessing.dummy as multiprocessing
- def mostSell_Laptop():
- myList = loadSellPickle()
- laptopList = []
- for elem in myList:
- laptopList.append(elem[1])
- print('\nСамый продаваемый ноутбук')
- print(max(set(laptopList), key=laptopList.count))
- def mostEffective_Employee():
- myList = loadSellPickle()
- employeeList = []
- for elem in myList:
- employeeList.append(elem[0])
- print('\nСамый эффективный сотрудник')
- print(max(set(employeeList), key=employeeList.count))
- def top5expensiveVideoCard():
- myList = loadSellPickle()
- myList.sort(key=lambda x: (int(x[3])))
- myList.reverse()
- mostExpensive = myList[:5]
- print('\nСамые дорогие видеокарты: ')
- for i in mostExpensive:
- print(i[2] + ' ' + i[3])
- def loadSellPickle():
- pList = pickle.load(open('pickle.pkl', 'rb'))
- return pList
- def addNewRow():
- mylist = loadSellPickle()
- nameEmployee = input('\nСотрудник, совершивший продажу: ')
- nameLaptop = input('Название ноутбука: ')
- nameVideoCard = input('Название видеокарты: ')
- price = input('Цена видеокарты: ')
- myTuple = (nameEmployee, nameLaptop, nameVideoCard, price)
- mylist.append(myTuple)
- with open('pickle.pkl', 'wb') as f:
- pickle.dump(mylist, f)
- def linearSolution():
- mostEffective_Employee()
- mostSell_Laptop()
- top5expensiveVideoCard()
- def threadingSolution():
- thread1 = Thread(target=mostEffective_Employee())
- thread2 = Thread(target=mostSell_Laptop())
- thread3 = Thread(target=top5expensiveVideoCard())
- thread1.start()
- thread2.start()
- thread3.start()
- thread1.join()
- thread2.join()
- thread3.join()
- def processSolution():
- pool = multiprocessing.Pool()
- pool.map(lambda f: f(), [mostEffective_Employee])
- pool.map(lambda f: f(), [mostSell_Laptop])
- pool.map(lambda f: f(), [top5expensiveVideoCard])
- pool.close()
- pool.join()
- n = input('\n1-линейное решение\n2-решение с потоками\n3-решение с процессами\n4-добавить запись в '
- 'pickle\nexit-выход\nВвод ')
- while n != 'exit':
- if n == '1':
- linearSolution()
- if n == '2':
- threadingSolution()
- if n == '3':
- processSolution()
- if n == '4':
- addNewRow()
- if n == 'exit':
- break
- n = input('\n1-линейное решение\n2-решение с потоками\n3-решение с процессами\n4-добавить запись в'
- ' pickle\nexit-выход\nВвод: ')
Advertisement
Add Comment
Please, Sign In to add comment