def approve_bids_information(self): if self.current_stage in self._bids_data: LOGGER.info( "Current stage bids {}".format(self._bids_data[self.current_stage]), extra={"JOURNAL_REQUEST_ID": self.request_id} ) bid_info = get_latest_bid_for_bidder( self._bids_data[self.current_stage], self.auction_document["stages"][self.current_stage]['bidder_id'] ) if bid_info['yearlyPaymentsPercentage'] == -0.01: LOGGER.info( "Latest bid is bid cancellation: {}".format(bid_info), extra={"JOURNAL_REQUEST_ID": self.request_id, "MESSAGE_ID": AUCTION_WORKER_BIDS_LATEST_BID_CANCELLATION} ) return False bid_info = {key: bid_info[key] for key in BIDS_KEYS_FOR_COPY} bid_info["bidder_name"] = self.mapping[bid_info['bidder_id']] bid_info['amount'] = bid_info['amount'] if self.features: bid_info['amount_features'] = Fraction(bid_info['amount']) * self.bidders_coeficient[bid_info['bidder_id']] self.auction_document["stages"][self.current_stage] = prepare_bids_stage( self.auction_document["stages"][self.current_stage], bid_info ) self.auction_document["stages"][self.current_stage]["changed"] = True return True else: return False
def prepare_auction_stages(self): # Initital Bids self.auction_document[ 'auction_type'] = 'meat' if self.features else 'default' for bid_info in self.bidders_data: self.auction_document["initial_bids"].append( prepare_initial_bid_stage( time="", bidder_id=bid_info["id"], bidder_name=self.mapping[bid_info["id"]], amount="0", yearlyPaymentsPercentage="0", contractDurationYears="0", contractDurationDays="0", annualCostsReduction=[])) self.auction_document['stages'] = [] next_stage_timedelta = self.startDate 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) if round_id == 0: next_stage_timedelta += timedelta(seconds=FIRST_PAUSE_SECONDS) else: next_stage_timedelta += timedelta(seconds=PAUSE_SECONDS) # 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")) self.auction_document['endDate'] = next_stage_timedelta.isoformat()
def update_future_bidding_orders(self, bids): current_round = self.get_round_number( self.auction_document["current_stage"]) for round_number in range(current_round + 1, ROUNDS + 1): for index, stage in enumerate( range(*self.get_round_stages(round_number))): self.auction_document["stages"][stage] = prepare_bids_stage( self.auction_document["stages"][stage], bids[index]) self.auction_document["results"] = [] for item in bids: self.auction_document["results"].append( prepare_results_stage(**item))
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