def test_ble(): sut = AuctionsReporterPrinter() a1 = Auction("test", AuctionType.BUY_NOW, AuctionStatus.ACTIVE, 0, 5) a2 = Auction("test", AuctionType.BID, AuctionStatus.ACTIVE, 1, 0) a3 = Auction("test", AuctionType.BID, AuctionStatus.ACTIVE, 1, 0) a3.add_bid(2) result = sut.create_all_auctions_reporter([a1, a2, a3], StringBuilder()) raise BaseException(result)
def parse_input(self): if isinstance(self.data, str): for row in self.data.splitlines(): tokens_list = row.split('|') if 'SELL' in tokens_list and self.validate( tokens_list, 'SELL'): # Auction(timestamp, user_id, item, reserve_price, close_time) auction = Auction(int(tokens_list[0]), int(tokens_list[1]), str(tokens_list[3]), float(tokens_list[4]), int(tokens_list[5])) self.auction_engine.add_auction(auction) elif 'BID' in tokens_list and self.validate( tokens_list, 'BID'): bid = {} bid['timestamp'] = int(tokens_list[0]) bid['user_id'] = int(tokens_list[1]) bid['item'] = str(tokens_list[3]) bid['bid_amount'] = float(tokens_list[4]) self.auction_engine.place_bid(bid) elif len(tokens_list) == 1 and self.validate( tokens_list, 'HEARTBEAT'): self.auction_engine.check_auctions(int(tokens_list[0])) else: raise RuntimeError( 'Unsupported action for: {}'.format(row))
def get_list_info(self, url_page, html_type, auction_type): response = requests.get(url_page, headers=self.headers) html = response.text tree = etree.HTML(html) div_list = tree.xpath('//div[@class="sflistdiv"]') for i in div_list: info = [] auction = Auction(source, auction_type) auction.province = '上海' auction.city = '上海' auction.html_type = html_type auction.source_html = html auction_id = i.xpath( 'div[@class="sflistdivn2"]/div[@class="f20hei"]/a/@href' )[0].split('/')[-1] is_exist = coll.find_one({ 'auction_id': str(auction_id), 'source': source }) if is_exist: log.info('id已存在,id="{}"'.format(str(auction_id))) continue auction.auction_id = auction_id try: auction_name_ = i.xpath( 'div[@class="sflistdivn2"]/div[@class="f20hei"]/a/text()' )[0] except Exception as e: auction_name_ = '' region = i.xpath( 'div[@class="sflistdivn2"]/div[@class="sflistban"]/text()')[0] auction.region = re.search(' - (.*?)$', region, re.S | re.M).group(1) auction_time_ = i.xpath( 'div[@class="sflistdivn2"]/div[@class="sflisttime"]/text()')[0] address = i.xpath( 'div[@class="sflistdivn2"]/div[@class="sflistcan"]/text()' )[3].encode().decode() auction.auction_name = auction_name_ + address try: auction_time = re.search('拍卖时间:(.*?)$', auction_time_, re.S | re.M).group(1) auction.auction_time = datetime.datetime.strptime( auction_time, "%y.%m.%d") except Exception as e: auction.auction_time = None info.append(i.xpath('string(div[@class="sflistdivn2"])')) area_ = i.xpath( 'div[@class="sflistdivn2"]/div[@class="sflistcan"]/span[1]/text()' )[0] auction.area = re.search('面积:(.*?)$', area_, re.S | re.M).group(1) floor = i.xpath( 'div[@class="sflistdivn2"]/div[@class="sflistcan"]/span[3]/text()' )[0] auction.floor = re.search('楼层:(.*?)$', floor, re.S | re.M).group(1) start_auction_price = i.xpath('//div[@class="f34hong"]/text()')[0] auction.start_auction_price = float( re.search('(\d+),?(\d+)', start_auction_price, re.S | re.M).group(1).replace(',', '')) * 10000 auction.insert_db()
def crawler_detail_page(self, auction_id, province_name, city_name, type_name, auction_type): detail_url = 'http://www.chinesesfpm.com/index/index/info/biao_id/' + auction_id res = requests.get(detail_url) tree = etree.HTML(res.text) a = Auction(source=source, auction_type=auction_type) a.auction_id = auction_id a.auction_name = tree.xpath( '/html/body/div/div[6]/div/div[2]/div[1]/div[1]/text()')[0] a.html_type = type_name auction_time = tree.xpath( '/html/body/div/div[6]/div/div[2]/div[1]/div[2]/div[2]/div[2]/text()' )[0] auction_time_ = re.search('开始时间: (.*?)$', auction_time, re.S | re.M).group(1) a.auction_time = datetime.datetime.strptime(auction_time_, "%Y年%m月%d日 %H时%M分%S秒") a.province = province_name a.city = city_name a.info = [ tree.xpath('string(//*[@id="f4"])'), tree.xpath('string(//*[@id="f6"])') ] start_auction_price = \ tree.xpath('/html/body/div/div[6]/div/div[2]/div[1]/div[2]/div[2]/div[5]/div[1]/em[3]/text()')[0] s = start_auction_price.encode('utf-8').decode() a.start_auction_price = float( re.search('起拍价: ¥(.*)', s, re.S | re.M).group(1)) court = tree.xpath( '/html/body/div/div[6]/div/div[2]/div[1]/div[2]/div[2]/div[5]/div[2]/em[1]/text()' )[0] a.court = re.search('拍卖机构:(.*)', court, re.S | re.M).group(1) a.source_html = res.text a.insert_db()
def parse(self, html): auction_list = html.xpath("//dl/dd/a/@href") for auction_url in auction_list: try: url = 'http://www.shjiapai.cn' + auction_url auction_res = requests.get(url, headers=self.headers) con = auction_res.text auction_id = re.search('id/(\d+).html', auction_url).group(1) if not check_auction(source=source, auction_id=auction_id): auction = Auction(source=source, auction_type=auction_type) auction.source_html = con auction.auction_id = auction_id auction.auction_name = re.search('楼盘名称.*?">(.*?)</td', con, re.S | re.M).group(1) auction.city = '上海' auction.html_type = '房产' auction.start_auction_price = re.search( '预计售价.*?">(.*?)</td', con, re.S | re.M).group(1) auction.floor = re.search('层.*?">(.*?)楼</td', con, re.S | re.M).group(1) auction.area = re.search('户型面积.*?">(.*?)</td', con, re.S | re.M).group(1) auction.build_type = re.search('物业类型.*?">(.*?)</td', con, re.S | re.M).group(1) auction.info = re.search('其它.*?>(.*?)</div', con, re.S | re.M).group(1) auction.insert_db() else: log.info("数据已存在") except Exception as e: log.error("{}解析失败".format(auction_url))
def detail_parse(auction_res, auction_type, html_type, auction_id): con = auction_res.json() auction = Auction(source=source, auction_type=auction_type) auction.source_html = con auction.html_type = html_type auction.auction_id = auction_id auction.auction_name = con['object_title'] auction.start_auction_price = con['start_price'] auction.assess_value = con['appraise_price'] auction.earnest_money = con['bond_price'] auction.court = con['court_name'] auction_time = con['start_time'] location = con['location'] auction.auction_time = datetime.datetime.strptime( auction_time, "%Y-%m-%d %H:%M:%S") province, city, region = location.split(' ') auction.province = province auction.city = city auction.region = region if html_type == '房产': auction.floor = con['detail']['house_floor'] auction.area = con['detail']['gross_floor_area'] elif html_type == '土地': auction.area = con['detail']['l_land_area'] auction.insert_db()
def run_experiment(auction_parameters, iterations_per_configuration): tot_buyer_profit_per_round = 0 tot_seller_profit_per_round = 0 tot_avg_market_price = 0 tot_market_prices = 0 for _ in range(0, iterations_per_configuration): test = Auction(auction_parameters) market_prices, buyer_profits, seller_profits = test.run() market_prices, round_avgs, seller_avgs, avg_buyer_profit_per_round, avg_seller_profit_per_round, avg_market_price = util.process_data( market_prices, auction_parameters, buyer_profits, seller_profits) tot_buyer_profit_per_round += avg_buyer_profit_per_round tot_seller_profit_per_round += avg_seller_profit_per_round tot_avg_market_price += avg_market_price tot_market_prices += market_prices avg_buyer_profit_per_round = tot_buyer_profit_per_round / float( iterations_per_configuration) avg_seller_profit_per_round = tot_seller_profit_per_round / float( iterations_per_configuration) avg_market_price = tot_avg_market_price / float( iterations_per_configuration) market_prices = tot_market_prices / float(iterations_per_configuration) results = { "params": auction_parameters, "avg_buyer_profit_per_round": avg_buyer_profit_per_round, "avg_seller_profit_per_round": avg_seller_profit_per_round, "avg_market_price": avg_market_price, "market_prices": market_prices } return results
def start_auction_process(self, game): seller = self.find_owner(game=game) winning_bid = Auction(game=game, item=self, seller=seller).auction_item() if winning_bid: if winning_bid[0].liquid_holdings < winning_bid[1]: game.run_bankruptcy_process(debtor=winning_bid[0], creditor=seller) else: self.complete_transaction(buyer=winning_bid[0], seller=seller, amount=winning_bid[1], game=game)
def test_while_in_market_lead(): print(' Running test_while_in_market_lead().') print(' CASE 1: One neighbor. Its direction is not assigned.') test_neighbor = Neighbor() test_neighbor.transactive = False test_neighbor.upOrDown = Direction.unknown test_neighbor.name = 'Test_Neighbor' test_market = Auction() test_market.marketState = MarketState.MarketLead dt = datetime.now() test_interval = TimeInterval(dt, timedelta(hours=1), test_market, dt, dt) test_market.timeIntervals = [test_interval] test_agent = TransactiveNode() test_agent.markets = [test_market] test_agent.neighbors = [test_neighbor] assert test_market.marketState == MarketState.MarketLead try: test_market.while_in_market_lead(test_agent) print(' - The method ran without errors') except RuntimeWarning: print(' - ERRORS ENCOUNTERED') assert test_market.marketState == MarketState.MarketLead, \ 'The market should not have changed from the market lead state' assert test_neighbor.upOrDown == Direction.downstream, \ 'The undefined direction should have been assigned downstream' assert len(test_neighbor.scheduledPowers) == 0, \ 'One scheduled power should have been scheduled by the test neighbor' print(' CASE 2: An upstream neighbor is added.') upstream_neighbor = Neighbor() upstream_neighbor.upOrDown = Direction.upstream test_agent.neighbors.append(upstream_neighbor) assert len(test_agent.neighbors) == 2, 'There should be two neighbors' try: test_market.while_in_market_lead(test_agent) print(' - The method ran without errors') except RuntimeWarning: print(' - ERRORS ENCOUNTERED') print(' test_while_in_market_lead() ran to completion.\n')
def main(): bidders = [] n_kind = 3 n = [30, 30, 30] List_Of_Strategy = [ CoefficientStrategy(0.95), CRecorderStrategy(0.95, 4), CoefficientStrategy(1.0) ] for i in range(n_kind): stra[List_Of_Strategy[i].name] = List_Of_Strategy[i] for i in range(n_kind): for j in range(n[i]): bidders.append( Bidder(uniformValuationGenerator(l, r), List_Of_Strategy[i])) sum_n = get_sum_int(n) n_auction, n_circle, n_once, m, n_lost = 10000, 100, 10, 10, 10 ctrs = [(m - i + 0.0) / m for i in range(m)] #x_axis,bidders_revenue,auction_revenue,social_welfare_revenue = [],[[] for i in range(n_kind)],[],[] print(0) out(bidders) for k in range(n_auction): for i in range(sum_n): bidders[i].revenue = 0 bidders[i].cnt = 0 #print([bidders[i].cnt for i in range(len(bidders))]) for k2 in range(n_circle): temp_bidders_i = random.sample(range(sum_n), m) #print(temp_bidders_i) temp_bidders = [] for x in temp_bidders_i: #print('AAA',bidders[x].cnt) bidders[x].cnt += 1 temp_bidders.append(bidders[x]) auction = Auction(temp_bidders, VCG(ctrs)) for k3 in range(n_once): auction.takeAuction() for i in range(len(temp_bidders_i)): bidders[temp_bidders_i[i]].revenue += temp_bidders[i].revenue bidders = deal(bidders) print('case\n', k, '\n') out(bidders) '''
def get_detail_info(self, detail_url, region_name, city_name, province_name, id_, html_type, auction_type): aution = Auction(source, auction_type) try: info = [] response = s.get(detail_url, headers=self.headers) html = response.text tree = etree.HTML(html) aution.region = region_name aution.auction_id = id_ aution.city = city_name aution.html_type = html_type aution.source_html = html aution.province = province_name aution.auction_name = tree.xpath('//div[contains(@class,"pm-main clearfix")]/h1/text()')[0].strip() start_auction_price = tree.xpath('//*[@id="J_HoverShow"]/tr[1]/td[1]/span[2]/span/text()')[0] \ .replace(',', '').replace(' ', '') aution.start_auction_price = float(start_auction_price) earnest_money = tree.xpath('//*[@id="J_HoverShow"]/tr[2]/td[1]/span[2]/span/text()')[0] \ .replace(',', '').replace(' ', '') aution.earnest_money = float(earnest_money) try: assess_value = tree.xpath('//*[@id="J_HoverShow"]/tr[3]/td[1]/span[2]/span/text()')[0].replace(',', '') aution.assess_value = float(assess_value) except Exception: aution.assess_value = None aution.court = tree.xpath('//p[@class="subscribe-unit"]/span/a/text()')[0] aution.contacts = tree.xpath('//p[@class="subscribe-unit"]/span/em/text()')[0] aution.phone_number = tree.xpath('//p[@class="subscribe-unit"][2]/span[2]/text()')[1] info.append(tree.xpath('string(//*[@id="J_DetailTabMain"]/div[4])')) info.append(tree.xpath('string(//*[@id="J_DetailTabMain"]/div[5])')) aution.info = info logo = tree.xpath('//h1[@class="bid-fail"]/text()') if logo: if '撤回' in logo[0] or '以物抵债' in logo[0] or '中止' in logo[0] or '暂缓' in logo[0] \ or '撤拍' in logo[0] or '待确认' in logo[0]: return elif '已结束' in logo[0]: # 时间字符串 auction_time = tree.xpath('//span[@class="countdown J_TimeLeft"]/text()')[0] aution.auction_time = datetime.datetime.strptime(auction_time, "%Y/%m/%d %H:%M:%S") else: # 时间戳 auction_time = tree.xpath('//li[@id="sf-countdown"]/@data-start')[0] aution.auction_time = datetime.datetime.fromtimestamp(int(auction_time) / 1000) else: # 时间戳 auction_time = tree.xpath('//li[@id="sf-countdown"]/@data-start')[0] aution.auction_time = datetime.datetime.fromtimestamp(int(auction_time) / 1000) aution.insert_db() except Exception as e: log.error('解析错误,url="{}",e="{}"'.format(detail_url, e))
def test_end_product(self, end_product): product = Auction().new_product(product_id=189, initial_bid=1000, step=50, duration=5) obj = MessageProcessor().process_object( 'market_comment_new', { "id": 1, "from_id": 123, "date": 1508599919, "text": "#AuctionEnd", "item_id": 189 }) end_product.assert_called_once_with(product_id=189)
def createAuction(self, _tokenId: uint256, _startingPrice: uint256, _endingPrice: uint256, _duration: uint256, _seller: address): # Sanity check that no inputs overflow how many bits we've allocated # to store them in the auction struct. require(_startingPrice == uint256(uint128(_startingPrice))) require(_endingPrice == uint256(uint128(_endingPrice))) require(_duration == uint256(uint64(_duration))) require(msg.sender == address(self.nonFungibleContract)) self._escrow(_seller, _tokenId) auction = Auction(_seller, uint128(_startingPrice), uint128(_endingPrice), uint64(_duration), uint64(now)) self._addAuction(_tokenId, auction)
def get_detail(self, url_real, city_name, auction_type, html_type,auction_id,province,region): response = requests.get(url_real, headers=self.headers) html = response.text if 'Status 500' in html or 'Error report' in html: log.info('请求错误,url="{}"'.format(url_real)) return tree = etree.HTML(html) auction = Auction(source, auction_type) auction.html_type = html_type auction.province = province auction.city = city_name auction.region = region auction.source_html = html if auction_type == '住宅': self.house_detailparse(url_real, auction, tree,auction_id) else: self.other_parse(url_real, auction, tree,auction_id)
def run_bank_auction(self): for item in self.bank.reserved_holdings: winning_bid = Auction(game=self, item=item, seller=self.bank).auction_item() if winning_bid and winning_bid[0]: item.complete_transaction(buyer=winning_bid[0], seller=self.bank, amount=winning_bid[1], game=self) for item in self.bank.reserved_holdings: if isinstance(item, OwnableTile): self.bank.property_holdings.append(item) if isinstance(item, HoldableCard): if item.parent_deck == 'Community Chest': self.community_deck.append(item) else: self.chance_deck.append(item) self.bank.reserved_holdings = []
def start_crawler(self): for type_num in type_list: page_num = self.get_page(type_num.code) for page in range(1, int(page_num) + 1): url = 'http://auction.jd.com/getJudicatureList.html?page=' + str( page) + '&limit=40&childrenCateId=' + type_num.code try: response = s.get(url, headers=self.headers) html = response.json() try: for info in html['ls']: auction = Auction( source=source, auction_type=type_num.auction_type) auction.html_type = type_num.html_type auction.auction_name = info['title'] # 商品名 auction.assess_value = info[ 'assessmentPrice'] # 评估值 try: auction.province = info['province'] # 省 auction.city = info['city'] # 城市 except Exception as e: auction.province = None auction.city = None auction.auction_time = datetime.datetime.fromtimestamp( int(info['startTime']) / 1000) # 评估值 auction.earnest_money = info['currentPrice'] # 保证金 auction.auction_id = str(info['id']) # 商品id is_exist = coll.find_one({ 'auction_id': str(info['id']), 'source': source }) if is_exist: log.info('id已存在,id="{}"'.format(str( info['id']))) continue self.get_detail(str(info['id']), auction) except Exception as e: log.error('解析错误,url="{}"'.format(url)) except Exception as e: log.error('请求错误,url="{}"'.format(url))
def handleCreateAuctionRequest(self, data): log.high_debug("Hit handleCreateAuctionRequest!") log.debug("------------") log.debug(data) if not self.validate_manager_request(data): log.warning( "Request failed because manager failed to be verified or the signature did not match!" ) # TODO: handle gracefully. Should send back an answer to client explaining why it failed return self.buildResponse( data["operation"], {"operation-error": "Certificate or signature check failed!"}) else: log.debug("Manager authenticity verified") self.sign_data(data) # Generate unique serial number # TODO: actually generate a unique serial number data_dict = data["data"] auction = Auction(data_dict["auction-name"], self.__auctionIndex, data_dict["auction-duration"], time.time(), data_dict["auction-description"], data_dict["auction-type"]) self.__auctionIndex = self.__auctionIndex + 1 lock.acquire() self.__auctionsList.append(auction) lock.release() # TODO: SIGN DATA FROM MANAGER log.info("Operation: {} from client-sn: {} => OK [ADDED auction: {}]". format(data["operation"], data["client-sn"], data_dict["auction-name"])) log.debug(data) return self.buildResponse("create-auction", data)
def _execute_auction(self, auction_mode, initiator, board): auction = Auction(auction_mode, initiator, board.get_cards(), board.cheque) for player in self._round_order_generator.one_circle_from_next( auction.initiator): top = auction.highest_bid agent = player.player_agent if player.round_is_over: logging.debug( ' {} PASSes bid because no cheques are available.'.format( agent)) continue avail_cheques_str = ','.join( str(c) for c in player.available_cheques()) if top and player.highest_cheque < top: logging.debug( ' {} PASSes bid because cannot outbid (had {} available).' .format(agent, avail_cheques_str)) continue is_mandated = auction.auction_mode == AuctionMode.ByPlayer and player == auction.initiator game_view = GameView(self, player, self._players, self._board) auction_view = AuctionView(auction) player_view = PlayerView(player) bidded_cheque = player.player_agent.bid(game_view, auction_view, player_view, is_mandated) if bidded_cheque: logging.debug( ' {} BIDs with cheque {} (had {} available).'.format( agent, bidded_cheque, avail_cheques_str)) auction.set_highest_bid(bidded_cheque, player) elif is_mandated: raise Exception('Missing mandated bid.') else: logging.debug( ' {} PASSes bid deliberately (had {} available).'.format( agent, avail_cheques_str)) if auction.highest_bid: self._execute_winning_bid(auction.highest_bidder, auction.highest_bid, board) if not auction.highest_bidder.num_available_cheques: logging.debug(' is out of cheques and out of round') else: logging.debug(' No bids in this auction.')
def store_auction_history(self, starting_price, market_price, winner, price_paid, bid_history, previous_alphas, auction_round, item_kind): """ Store the information of an auction in an auction object and store it in the auctions history :param starting_price: Starting price of the auction :param market_price: market price of the item :param winner: id of the buyer that wins the auction :param price_paid: price that the buyer pays for the item :param bid_history: dictionary with the bid of the buyers :param previous_alphas: bidding factor before the auction :param auction_round: round that this auction took place in :param item_kind: kind of item that is sold :return: auction object with all the information """ auction = Auction(starting_price, market_price, price_paid, winner, bid_history, previous_alphas, item_kind) self.auctions_history[auction_round].append(auction) return auction
def test_while_in_negotiation(): print(' Running test_while_in_negotiation().') print(' CASE: Normal function. Asset should schedule, and market becomes converged') test_asset = LocalAsset() default_power = 4.321 test_asset.defaultPower = default_power test_market = Auction() test_market.converged = False test_market.marketState = MarketState.Negotiation dt = datetime.now() test_interval = TimeInterval(dt, timedelta(hours=1), test_market, dt, dt) test_market.timeIntervals = [test_interval] test_agent = TransactiveNode() test_agent.markets = [test_market] test_agent.localAssets = [test_asset] assert test_market.converged is False, 'The test market should start out not converged' assert test_market.marketState == MarketState.Negotiation try: test_market.while_in_negotiation(test_agent) print(' - The method ran without errors') except RuntimeWarning: print(' - ERRORS ENCOUNTERED') assert test_market.converged is True, 'The market should be converged' assert test_market.marketState == MarketState.Negotiation, \ 'The market should not have changed from the negotiation state' assert len(test_asset.scheduledPowers) == 1, 'Precisely one scheduled power should have been assigned' print(' test_while_in_negotiation() ran to completion.\n') pass
def demo_auction(): """Run a random auction. Stop after max_bids bids.""" # number of bids to accept max_bids = 10 auction = Auction("Vacation to Ko Samui") auction.start() print("Starting", auction, "with min bidding increment", auction.increment) #auction.bid("initial", 20) for n in range(0,max_bids): bidder = get_bidder(auction) amount = int(auction.best_bid() + 10*random.randint(-2,5) + 10) print_and_bid(auction,bidder,amount) # pause the auction if n == max_bids/2: print(">>> stop()") auction.stop() elif n == max_bids/2 + 1: print(">>> start()") auction.start() print("The winner is", auction.winner(), "with a bid of", auction.best_bid())
def read_actions(self): """ This method is reading the type of instruction and deciding what to do with each of them. -For selling instructions it will create an object of type Auction() and added to a structure list_of_auctions. -For bidding instructions it will find the Auction object and make a bid on it. """ # For Selling instructions if len(self.instruction) == 6: # Append a new auction to the list of auctions auction = Auction(timestamp=self.instruction[0], user_id=self.instruction[1], item=self.instruction[3], reserve_price=self.instruction[4], close_time=self.instruction[5]) self.add_auctions(self.instruction[5], auction) # For Bidding instructions elif len(self.instruction) == 5: # Find the auction to bid auction = self.find_auction(self.instruction[3]) if auction is not None: auction.bid(self.instruction)
def process(raw_events: List) -> Generator: auctions = {} errors = [] for raw_event in raw_events: event = Event.decode(raw_event) if event is None: errors.append({'error': raw_event}) if isinstance(event, Listing): auction = Auction(item=event.item, end_time=event.end_time, reserve_price=event.reserve_price, bids=[]) auctions[event.item] = auction continue # Route bid to correct auction if isinstance(event, Bid): if event.item in auctions: auctions[event.item].bid(event) continue # Broadcast HeartBeat to all auctions if isinstance(event, HeartBeat): for _, auction in auctions.items(): auction.update(event) continue for auction in auctions.values(): yield str(auction) if any(errors): yield errors
def get_info(self, url): response = requests.get(url=url, headers=self.headers) html = etree.HTML(response.text) print(url) wrong_list = [] try: wrong = html.xpath("//div[@class='dialog']/h1/text()")[0] wrong_list.append(wrong) except Exception as e: print(e) if "We're sorry, but something went wrong." not in wrong_list: title = html.xpath("//div[@class='title']/text()")[0] start_price = html.xpath( "//table[@class='item-attrs']//tr[1]/td[2]/text()")[0] assess_price = html.xpath( "//table[@class='item-attrs']//tr[1]/td[4]/text()")[0] ensure_price = html.xpath( "//table[@class='item-attrs']//tr[1]/td[6]/text()")[0] auction_id = re.search( "http://auction\.qdauction\.com/items/(\d+)", url).group(1) auction = Auction(source=source, auction_type=auction_type) auction.auction_name = title auction.start_auction_price = start_price auction.assess_value = assess_price auction.earnest_money = ensure_price auction.auction_id = auction_id try: time = html.xpath("//tr[@class='deal']/td[4]/text()")[0] Auction.auction_time = datetime.datetime.strptime( time, "%Y-%m-%d %H:%M:%S") except Exception as e: print(e) auction.source_html = response.text auction.city = '青岛' auction.html_type = '其他' auction.insert_db()
def main(self): if self.log: print("Case K: %d, N: %d, b: %d, M: %d" % (self.K, self.N, self.b, self.M)) # Emulating channel gains using rayleigh fading # this creates a NxK matrix where each row contains channel gains of k channels self.channel_gains = np.random.rayleigh(2, size=(self.N, self.K)) if self.calc_gain is not None: for i in range(self.N): for j in range(self.K): self.channel_gains[i][j] = self.calc_gain( self.channel_gains[i][j]) if self.log: print("Allocated channel gains using rayleigh fading") # We select M best channels from K channels for all user m_best_channels = [ sorted(sorted(range(len(a)), key=lambda i: a[i])[-self.M:]) for a in self.channel_gains ] if self.log: print("Obtained M best channels") #encoded_ = [self.encode_rec(x, self.K) for x in self.channel_gains] #print("test1") #decoded_ = [self.decode_rec(x, self.K, self.M) for x in encoded_ ] # create a list of edges # between a user n, and it's m best channels edges = [] for i in range(self.K): edges = edges + [(i, x) for x in m_best_channels[calc_user(i, self.b)]] if self.log: print("Created edges") # end of test case 2 # Implementation with Auction Algorithm: if self.log: print("Starting auction algorithm: ") self.auc = Auction(self.K, self.b, self.N, self.eps) self.auc.add_edges(edges) self.auc.initialize() if self.log: print("Created graph") self.auc.find_pm() if self.log: print("Calculated PM for auction algorithm") if self.display_mat: self.auc.display_pm() # Implementation with Hungarian Algorithm: if self.log: print("Starting hungarian algorithm: ") self.hun = Hungarian(self.K, self.b, self.N, self.eps) self.hun.add_edges(edges) if self.log: print("Created graph") self.hun.find_pm() if self.log: print("Calculated PM for hungarian algorithm") if self.display_mat: self.hun.display_pm() print("")
def setup(): auction = Auction("Auction Test") auction.start() return auction
def setUp(self): self.auction1 = Auction(timestamp=2, user_id=1, item="pc1", reserve_price=150, close_time=20)
def setUp(self): self.auction = Auction(10, 7, 'car_1', 502.30, 20) self.auction.bid_list = [{ 'timestamp': 12, 'user_id': 8, 'item': 'car_1', 'bid_amount': 300.50 }, { 'timestamp': 13, 'user_id': 5, 'item': 'car_1', 'bid_amount': 425.02 }, { 'timestamp': 17, 'user_id': 8, 'item': 'car_1', 'bid_amount': 634.87 }] self.auction.bid_list_duplicate = self.auction.bid_list.append({ 'timestamp': 18, 'user_id': 7, 'item': 'car_1', 'bid_amount': 634.87 }) self.bid_summary = [(634.87, [{ 'timestamp': 17, 'user_id': 8, 'item': 'car_1', 'bid_amount': 634.87 }]), (425.02, [{ 'timestamp': 13, 'user_id': 5, 'item': 'car_1', 'bid_amount': 425.02 }]), (300.50, [{ 'timestamp': 12, 'user_id': 8, 'item': 'car_1', 'bid_amount': 300.50 }])] self.bid_summary_duplicate = [(634.87, [{ 'timestamp': 18, 'user_id': 8, 'item': 'car_1', 'bid_amount': 634.87 }, { 'timestamp': 17, 'user_id': 7, 'item': 'car_1', 'bid_amount': 634.87 }]), (425.02, [{ 'timestamp': 13, 'user_id': 5, 'item': 'car_1', 'bid_amount': 425.02 }]), (300.50, [{ 'timestamp': 12, 'user_id': 8, 'item': 'car_1', 'bid_amount': 300.50 }])] self.auction_engine = AuctionEngine() self.auction_engine.add_auction(self.auction)
def get_detail(self, id_, auction_time, html_type, auction_type, province, city, region): auction = Auction(source=source, auction_type=auction_type) auction.html_type = html_type auction.auction_type = auction_type auction.province = province auction.city = city auction.region = region detail_url = 'http://www1.rmfysszc.gov.cn/Handle/' + id_ + '.shtml' try: response = requests.get(detail_url, headers=self.headers) html = response.content.decode() auction.source_html = html info_list = [] try: if 'GetRecord()' in html: tree = etree.HTML(html) auction.auction_name = tree.xpath( '//div[@id="Title"]/h1/text()')[0] start_auction_price = tree.xpath( '//*[@id="price"]/div[1]/span/text()')[0] auction.start_auction_price = self.get_float( start_auction_price) assess_value = tree.xpath( '//*[@id="bg1"]/div[1]/table/tr[1]/td/span[2]/text()' )[0] try: auction.assess_value = self.get_float(assess_value) except Exception as e: auction.assess_value = None earnest_money = tree.xpath( '//*[@id="bg1"]/div[1]/table/tr[2]/td/span[2]/text()' )[0] auction.earnest_money = self.get_float(earnest_money) announcement_date = tree.xpath( '//*[@id="bg1"]/div[1]/table/tr[3]/td/span/text()')[0] announcement_date_ = re.search(': (.*?)$', announcement_date, re.S | re.M).group(1) auction.announcement_date = datetime.datetime.strptime( announcement_date_, "%Y.%m.%d") auction_level = tree.xpath( '//*[@id="bg1"]/div[1]/table/tr[4]/td/span/text()')[0] auction.auction_level = re.search(': (.*?)$', auction_level, re.S | re.M).group(1) court = tree.xpath( '//*[@id="bg1"]/div[2]/table/tr[1]/td/span/text()')[0] auction.court = re.search(': (.*?)$', court, re.S | re.M).group(1) info_list.append( tree.xpath( 'string(//*[@id="bdjs11"])').encode().decode()) info_list.append( tree.xpath( 'string(//*[@id="jjjl"])').encode().decode()) contacts = tree.xpath( '//*[@id="bg1"]/div[2]/table/tr[2]/td/span/text()')[0] auction.contacts = re.search(': (.*?)$', contacts, re.S | re.M).group(1) phone_number = tree.xpath( '//*[@id="bg1"]/div[2]/table/tr[3]/td/span/text()')[0] auction.phone_number = re.search(': (.*?)$', phone_number, re.S | re.M).group(1) auction.info = info_list try: auction.build_type = tree.xpath( '//*[@id="bdjs11"]/table[1]/tr[2]/td[4]/text()')[0] except Exception as e: auction.build_type = None auction.auction_id = id_ auction.auction_time = self.get_date(date=auction_time) auction.insert_db() elif 'bmnumber()' in html: tree = etree.HTML(html) auction.auction_name = tree.xpath( '//div[@id="Title"]/h1/text()')[0] start_auction_price = tree.xpath( '//*[@id="price"]/div[1]/span/text()')[0] auction.start_auction_price = self.get_float( start_auction_price) assess_value = tree.xpath( '//*[@id="bg1"]/div[1]/table/tr[1]/td/span[2]/text()' )[0] auction.assess_value = self.get_float(assess_value) earnest_money = tree.xpath( '//*[@id="bg1"]/div[1]/table/tr[2]/td/span[2]/text()' )[0] auction.earnest_money = self.get_float(earnest_money) announcement_date = tree.xpath( '//*[@id="bg1"]/div[1]/table/tr[3]/td/span/text()')[0] announcement_date_ = re.search(': (.*?)$', announcement_date, re.S | re.M).group(1) auction.announcement_date = datetime.datetime.strptime( announcement_date_, "%Y-%m-%d") auction_level = tree.xpath( '//*[@id="bg1"]/div[1]/table/tr[4]/td/span/text()')[0] auction.auction_level = re.search(': (.*?)$', auction_level, re.S | re.M).group(1) court = tree.xpath( '//*[@id="bg1"]/div[2]/table/tr[1]/td/span/text()')[0] auction.court = re.search(': (.*?)$', court, re.S | re.M).group(1) info_list.append( tree.xpath( 'string(//*[@id="bdjs"])').encode().decode()) contacts = tree.xpath( '//*[@id="bg1"]/div[2]/table/tr[2]/td/span/text()')[0] auction.contacts = re.search(': (.*?)$', contacts, re.S | re.M).group(1) phone_number = tree.xpath( '//*[@id="bg1"]/div[2]/table/tr[3]/td/span/text()')[0] auction.phone_number = re.search(': (.*?)$', phone_number, re.S | re.M).group(1) auction.info = info_list try: auction.build_type = tree.xpath( '//*[@id="bdjs11"]/table[1]/tr[2]/td[4]/text()')[0] except Exception as e: auction.build_type = None auction.auction_id = id_ auction.auction_time = self.get_date(date=auction_time) auction.insert_db() else: tree = etree.HTML(html) auction.auction_name = tree.xpath( '//*[@id="xmgg"]/div/div[1]/text()')[0] assess_value = tree.xpath( '/html/body/div[6]/table/tr/td/ul/li[3]/span/text()' )[0] auction.assess_value = self.get_float(assess_value) announcement_date = tree.xpath( '/html/body/div[6]/table/tr/td/ul/li[2]/span/text()' )[0] try: auction.announcement_date = datetime.datetime.strptime( announcement_date, "%Y-%m-%d") except Exception as e: auction.announcement_date = datetime.datetime.strptime( announcement_date, "%Y/%m/%d") auction.court = tree.xpath( '/html/body/div[6]/table/tr/td/ul/li[1]/span/text()' )[0] info_list.append( tree.xpath( 'string(//*[@id="bdxx"]/div)').encode().decode()) info_list.append( tree.xpath('string(//*[@id="tjzl"]/div/div[2])'). encode().decode()) auction.contacts = tree.xpath( '/html/body/div[6]/table/tr/td/ul/li[4]/span/text()' )[0] auction.phone_number = tree.xpath( '/html/body/div[6]/table/tr/td/ul/li[5]/span/text()' )[0] auction.info = info_list try: auction.build_type = tree.xpath( '//*[@id="bdxx"]/div/div[2]/table/tr[2]/td[3]/text()' )[0] except Exception as e: auction.build_type = None auction.auction_id = id_ auction.auction_time = self.get_date(date=auction_time) auction.insert_db() except Exception as e: log.error('解析错误,url="{}",e="{}"'.format(detail_url, e)) except Exception as e: log.error('详情页请求错误,url="{}",e="{}"'.format(detail_url, e))
from auction import Input from auction import Auction import util auction_parameters = Input() test = Auction(auction_parameters) market_prices, buyer_profits, seller_profits = test.run() market_prices, round_avgs, seller_avgs, avg_buyer_profit_per_round, avg_seller_profit_per_round, avg_market_price = util.process_data( market_prices, auction_parameters, buyer_profits, seller_profits) print(f"Market Prices:") for i, round_outcome in enumerate(market_prices): print(f"round {i}: {round_outcome}") print() print( f"Buyer profits for all {auction_parameters.num_round} rounds: \n{buyer_profits}\n" f"AVG Buyer profits per round: \n{avg_buyer_profit_per_round}\n" f"Seller profits for all {auction_parameters.num_round} rounds: \n{seller_profits}\n" f"AVG Seller profits per round: {avg_seller_profit_per_round}\n" f"AVG market price: {avg_market_price}\n")