Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import collections
- import threading
- import multiprocessing.dummy as multiprocessing
- def mostSell_Car():
- sellArray = loadJsonSell()
- dictCarAndCount = collections.Counter()
- for d in sellArray:
- dictCarAndCount[d['car']] += 1
- c = collections.Counter(dictCarAndCount).most_common()
- print('\nСамый продаваемый автомобиль')
- for elem in c[:1]:
- print(elem[0])
- def mostEffective_Employee():
- sellArray = loadJsonSell()
- dictEmpAndCount = collections.Counter()
- for d in sellArray:
- dictEmpAndCount[d['employee']] += 1
- c = collections.Counter(dictEmpAndCount).most_common()
- print('\nСамый эффективный сотрудник')
- for elem in c[:1]:
- print(elem[0])
- def top5Spare_high_price():
- spareArray = loadJsonSpare()
- dictSpareAndPrice = collections.Counter()
- for d in spareArray:
- dictSpareAndPrice[d['name']] += d['price']
- print("\nТоп 5 запчастей по стоимости: ")
- for spare in dictSpareAndPrice.most_common()[:5]:
- print(spare)
- def linearSolution():
- mostSell_Car()
- top5Spare_high_price()
- mostEffective_Employee()
- def timerSolution():
- timer = threading.Timer(0, mostSell_Car)
- timer1 = threading.Timer(1, top5Spare_high_price)
- timer2 = threading.Timer(2, mostEffective_Employee)
- timer.start()
- timer1.start()
- timer2.start()
- def processSolution():
- pool = multiprocessing.Pool()
- pool.map(lambda f: f(), [mostSell_Car])
- pool.map(lambda f: f(), [top5Spare_high_price])
- pool.map(lambda f: f(), [mostEffective_Employee])
- pool.close()
- pool.join()
- def addSellRecord():
- sellArray = loadJsonSell()
- employee = input('Введите сотрудника\n')
- car = input('Введите название машины\n')
- newSell = {'employee': employee, 'car': car}
- sellArray.append(newSell)
- newJson = {"sell": sellArray, "spare": loadJsonSpare()}
- with open("json.json", "w") as write_file:
- json.dump(newJson, write_file)
- def addSpareRecord():
- spareArray = loadJsonSpare()
- name = input('Введите название детали\n')
- price = input('Введите цену детали\n')
- newSpare = {'name': name, 'price': price}
- spareArray.append(newSpare)
- newJson = {"sell": loadJsonSell(), "spare": spareArray}
- with open("json.json", "w") as write_file:
- json.dump(newJson, write_file)
- def loadJsonSpare():
- jDict = json.load(open('json.json', 'r'))
- return jDict.get('spare')
- def loadJsonSell():
- jDict = json.load(open('json.json', 'r'))
- return jDict.get('sell') # возвращает список со словарями
- n = input('\n1-линейное решение\n2-решение с событиями таймера\n3-решение с процессами\n4-добавить запись о продаже в '
- 'json\n5-добавить новую запчасть\nexit-выход\nВвод ')
- while n != 'exit':
- if n == '1':
- linearSolution()
- if n == '2':
- timerSolution()
- if n == '3':
- processSolution()
- if n == '4':
- addSellRecord()
- if n == '5':
- addSpareRecord()
- if n == 'exit':
- break
- n = input('\n1-линейное решение\n2-решение с потоками\n3-решение с процессами\n4-добавить запись о продаже в '
- 'json\n5-добавить новую запчасть\nexit-выход\nВвод ')
Advertisement
Add Comment
Please, Sign In to add comment