def arrive(self, count): """Прибытие новой партии книг данного издания.""" self.count += count self.is_frozen = 0 summ = count*self.price BookStore.log(f'arrived book {str(self)} {count}. It has value {summ} with {self.retail_markup}.') return summ
def __init__(self, buyer, wishlist): """создание заказа: покупатель и пожелания.""" self.buyer = buyer self.wishes = wishlist self.buyer.order += 1 self.buyer.books.extend(wishlist) BookStore.log( f'created buyer {buyer} {[str(wish) for wish in wishlist]}')
def start_simulation(self): self.setupUi(self) self.pushButton.clicked.connect(self.buttonClicked) self.pushButton2.clicked.connect(self.restart) self.pushButton3.clicked.connect(self.exit) self.mainStore = BookStore() for book in self.mainStore.book_index: self.listWidget.addItem(str(book)) self.progressBar.value = self.mainStore.current_day self.lcdNumber.value = 0
def get(self, wish=None): """получение книги автора.""" BookStore.log(f'book {wish} got from {self.author}') temp = None for book in self.bibliography: if wish.title == book.title: temp = book if temp.count > 0: return temp return temp
def booking(self): """оформление заказа.""" # каждая книга обрабатывается summ = 0 flag = True for wish in self.wishes: edition = wish.one_book.get_edition() if (edition is None): flag = False else: summ += edition.booking() BookStore.log((str(self), flag), 'Order') self.buyer.summ += summ return summ
def __init__(self, **kwargs): self.name = 'John' self.surname = 'Doe' self.address = 'nothing' self.telephone_number = '000-000-00-00' self.email = '*****@*****.**' for key, value in kwargs.items(): attr = key.lower() if attr in self.__slots__: setattr(self, attr, value) BookStore.log(f'created buyer {str(self)} ') self.books = [] self.order = 0 self.summ = 0
def __init__(self, **kwargs): """Инициализация по списку параметров, определение списка изданий и. прочих параметров. """ self.editions = [] self.author = 'nobody' self.title = 'nothing' self.first_published = 2019 self.income = 0 for key, value in kwargs.items(): attr = key.lower() if (attr == 'year'): temp = int(value) if temp < self.first_published: self.first_published = temp elif (attr == 'topics') or (attr == 'category'): set_value = value.split() else: set_value = value if attr in self.__slots__: setattr(self, attr, set_value) self.editions = [Edition(self, **kwargs)] BookStore.log(f'created book {str(self)} ')
def __init__(self, book, **kwargs): """Инициализация по списку параметров, определение неустановленных. параметров. """ self.book = book for key, value in kwargs.items(): attr = key.lower() set_value = value if value.isdigit(): set_value = int(value) if (attr == 'topics') or (attr == 'categories'): set_value = value.split() if attr in self.__slots__: setattr(self, attr, set_value) self.pages_used = random_pages() self.price = random_price(self) self.retail_markup = markup(self.price) self.demand = 0 self.sold = 0 self.newness = 0 self.count = random_count(self.price) self.is_frozen = 0 BookStore.log(f'created book {str(self)} ')
def booking(self): """Заказ издания.""" if self.count > 0: self.count -= 1 self.demand += 1 self.sold += 1 self.book.income += self.retail_markup BookStore.log(f'bought book {str(self)} for {self.retail_markup}') return self.retail_markup else: self.demand += 1 BookStore.bid_book(self) BookStore.log(f"can't buy book {str(self)} ") return 0
def test_buy_one_book_in_each_five_kinds(self): book_store = BookStore() cost = book_store.buy([1,1,1,1,1]) self.assertEqual(30, cost, 'cost should be 30 against ' + str(cost))
def test_buy_as_22211(self): book_store = BookStore() cost = book_store.buy([2,2,2,1,1]) self.assertEqual(51.6, cost, 'cost should be 51.6 against ' + str(cost))
def test_buy_two_books_in_one_kind(self): book_store = BookStore() cost = book_store.buy([2,0,0,0,0]) self.assertEqual(16, cost, 'cost should be 16 against ' + str(cost))
def test_buy_nothing(self): book_store = BookStore() cost = book_store.buy([0,0,0,0,0]) self.assertEqual(0, cost, 'cost should be 0 against ' + str(cost))
def test_buy_one_book_in_each_four_kinds(self): book_store = BookStore() cost = book_store.buy([1,1,1,1,0]) self.assertEqual(25.6, cost, 'cost should be 25.6 against ' + str(cost))
def test_buy_one_book_in_each_two_kinds(self): book_store = BookStore() cost = book_store.buy([1,1,0,0,0]) self.assertEqual(15.2, cost, 'cost should be 15.2 against ' + str(cost))
def test_buy_one_book_in_one_kind(self): book_store = BookStore() cost = book_store.buy([1,0,0,0,0]) self.assertEqual(8, cost, 'cost should be 8 against ' + str(cost))
def arrive(self, editionlist): for edition, count in editionlist: self.cash += edition.arrive(count) BookStore.log(f'{self.name} book {edition.book.title} arrived ')
def add(self, one_edition): self.editions += [one_edition] BookStore.log(f'{self.name} added {one_edition.book.title}')
def __init__(self, name): self.AVT = 3 self.name = name self.editions = [] self.cash = 0 BookStore.log(f'Publisher {name} created')
def add(self, one_book): """добавление книги в библиографию.""" self.bibliography.append(one_book) BookStore.log(f'author{self.author} book {one_book.title} added')
class Example(QDialog, gui.Ui_Dialog): def __init__(self): super().__init__() self.start = 1 self.startUi(self) self.pushButton.clicked.connect(self.buttonClicked) def start_simulation(self): self.setupUi(self) self.pushButton.clicked.connect(self.buttonClicked) self.pushButton2.clicked.connect(self.restart) self.pushButton3.clicked.connect(self.exit) self.mainStore = BookStore() for book in self.mainStore.book_index: self.listWidget.addItem(str(book)) self.progressBar.value = self.mainStore.current_day self.lcdNumber.value = 0 def restart(self): self.clear() self.start = 1 self.startUi() self.pushButton.clicked.connect(self.buttonClicked) def exit(self): self.close() def buttonClicked(self): if self.start == 1: self.start = 0 import settings lst = [s for s in dir(settings) if not s.startswith('_')] for index, var_name in enumerate(settings._strings): setattr(settings, var_name, self.spins[index].value()) self.spins[index].close() self.labels[index].close() del self.spins del self.labels self.pushButton.close() self.gridLayout.update() self.start_simulation() else: income = int(self.mainStore.params['income']) self.label[3].setText(f"Общий доход за весь период:{income}") if self.mainStore.current_day == self.settings.finalDay: self.listWidget.clear() for index, label in enumerate(self.label): if index == 0: self.label[index].setText( f"Статистика проданных книг.") elif index == 1: self.label[index].setText( f"Список заявок, которые придут после горизонта событий моделирования:" ) elif index == 2: self.label[index].setText( f"Список всех покупателей, приходивших в магазин, с их данными" ) elif index == 3: self.label[index].setText( f"Общий доход за всё время моделирования составил {income}." ) else: self.label[index].setText('') self.lcdNumber.display(len(self.mainStore.buyer_index)) for book in self.mainStore.book_statistic(): temp = QListWidgetItem(book) self.listWidget.addItem(temp) self.listWidget2.clear() for buyer in self.mainStore.buyer_statistic(): temp = QListWidgetItem(buyer) self.listWidget2.addItem(temp) self.listWidget3.clear() for bid in self.mainStore.get_bids(): temp = QListWidgetItem(bid) self.listWidget3.addItem(temp) Dialog.setWindowTitle(_translate("Dialog", "Статистика")) else: if self.settings._const_DEBUG: print(str(self.mainStore.tick())) else: mainStore.tick() self.listWidget2.clear() for order, flag in self.mainStore.orderlog: temp = QListWidgetItem(order) if not flag: temp.setForeground(QColor(255, 0, 0)) self.listWidget2.addItem(temp) self.listWidget.clear() for book in self.mainStore.book_index: temp = QListWidgetItem(str(book)) if book.is_low_count(): temp.setForeground(QColor(255, 0, 0)) self.listWidget.addItem(temp) self.listWidget3.clear() for bid in self.mainStore.get_bids(): temp = QListWidgetItem(bid) self.listWidget3.addItem(temp) self.lcdNumber.display(len(self.mainStore.orderlog)) self.progressBar.setProperty( 'value', self.mainStore.current_day * 100 / self.settings.finalDay) self.progressBar.setFormat('Day ' + str(self.mainStore.current_day))
def __init__(self, name): """создание нового автора, с заданным именем и пустой библиографией.""" self.author = name self.bibliography = [] BookStore.log(f'author {name} created/n')