def start_auction(self, switch_to_round=None): self.generate_request_id() self.audit['timeline']['auction_start']['time'] = datetime.now( tzlocal()).isoformat() LOGGER.info('---------------- Start auction ----------------', extra={ "JOURNAL_REQUEST_ID": self.request_id, "MESSAGE_ID": AUCTION_WORKER_SERVICE_START_AUCTION }) self.get_auction_info() self.get_auction_document() # Initital Bids bids = deepcopy(self.bidders_data) self.auction_document["initial_bids"] = [] bids_info = sorting_start_bids_by_amount(bids, features=self.features) for index, bid in enumerate(bids_info): amount = bid["value"]["amount"] audit_info = { "bidder": bid["id"], "date": bid["date"], "amount": amount } if self.features: amount_features = cooking(amount, self.features, self.bidders_features[bid["id"]]) coeficient = self.bidders_coeficient[bid["id"]] audit_info["amount_features"] = str(amount_features) audit_info["coeficient"] = str(coeficient) else: coeficient = None amount_features = None self.audit['timeline']['auction_start']['initial_bids'].append( audit_info) self.auction_document["initial_bids"].append( prepare_initial_bid_stage( time=bid["date"] if "date" in bid else self.startDate, bidder_id=bid["id"], bidder_name=self.mapping[bid["id"]], amount=amount, coeficient=coeficient, amount_features=amount_features)) if isinstance(switch_to_round, int): self.auction_document["current_stage"] = switch_to_round else: self.auction_document["current_stage"] = 0 all_bids = deepcopy(self.auction_document["initial_bids"]) minimal_bids = [] for bid_info in self.bidders_data: minimal_bids.append( get_latest_bid_for_bidder(all_bids, str(bid_info['id']))) minimal_bids = self.filter_bids_keys(sorting_by_amount(minimal_bids)) self.update_future_bidding_orders(minimal_bids) self.save_auction_document()
def prepare_auction_stages_fast_forward(self): self.auction_document['auction_type'] = 'meat' if self.features else 'default' bids = deepcopy(self.bidders_data) self.auction_document["initial_bids"] = [] bids_info = sorting_start_bids_by_amount(bids, features=self.features, reverse=False) for index, bid in enumerate(bids_info): amount = bid["value"]["amountPerformance"] annualCostsReduction = bid["value"]["annualCostsReduction"] if self.features: amount_features = cooking( amount, self.features, self.bidders_features[bid["id"]], reverse=True ) coeficient = self.bidders_coeficient[bid["id"]] else: coeficient = None amount_features = None initial_bid_stage = prepare_initial_bid_stage( time=bid["date"] if "date" in bid else self.startDate, bidder_id=bid["id"], bidder_name=self.mapping[bid["id"]], amount=amount, coeficient=coeficient, amount_features=amount_features, annualCostsReduction=annualCostsReduction, yearlyPaymentsPercentage=bid["value"]["yearlyPaymentsPercentage"], contractDurationDays=bid["value"]["contractDuration"].get("days", None), contractDurationYears=bid["value"]["contractDuration"].get("years", None) ) self.auction_document["initial_bids"].append( initial_bid_stage ) self.auction_document['stages'] = [] next_stage_timedelta = datetime.now(tzlocal()) for round_id in xrange(ROUNDS): # Schedule PAUSE Stage pause_stage = prepare_service_stage( start=next_stage_timedelta.isoformat(), stage="pause" ) self.auction_document['stages'].append(pause_stage) # Schedule BIDS Stages for index in xrange(self.bidders_count): bid_stage = prepare_bids_stage({ 'start': next_stage_timedelta.isoformat(), 'bidder_id': '', 'bidder_name': '', 'amount': '0', "contractDurationDays": "0", "contractDurationYears": "0", "yearlyPaymentsPercentage": "0", 'time': '', }) self.auction_document['stages'].append(bid_stage) next_stage_timedelta += timedelta(seconds=BIDS_SECONDS) self.auction_document['stages'].append( prepare_service_stage( start=next_stage_timedelta.isoformat(), type="pre_announcement" ) ) self.auction_document['stages'].append( prepare_service_stage( start="", type="announcement" ) ) all_bids = deepcopy(self.auction_document["initial_bids"]) minimal_bids = [] for bid_info in self.bidders_data: minimal_bids.append(get_latest_bid_for_bidder( all_bids, str(bid_info['id']) )) minimal_bids = self.filter_bids_keys(sorting_by_amount(minimal_bids, reverse=False)) self.update_future_bidding_orders(minimal_bids) self.auction_document['endDate'] = next_stage_timedelta.isoformat() self.auction_document["current_stage"] = len(self.auction_document["stages"]) - 2