def test_only_sell_one_position(self): mutator = Seller( 30.0, [Position('AGNC', 2)], {'AGNC': 1}, {'AGNC': 49.0}) self.assertItemsEqual(mutator.optimal_trades(), [Sell(1, 'AGNC')])
def test_simple_optimal_trade(self): mutator = Seller( 30.0, [Position('AGNC', 1)], {'AGNC': 1}, {'AGNC': 49.0}) self.assertItemsEqual(mutator.optimal_trades(), [Sell(1, 'AGNC')])
def test_only_sell_two_positions(self): mutator = Seller( 60.0, [ Position('AGNC', 2), Position('NLY', 2), ], {'AGNC': 1, 'NLY': 1}, {'AGNC': 49.0, 'NLY': 35.00}) self.assertItemsEqual(mutator.optimal_trades(), [Sell(1, 'AGNC'), Sell(1, 'NLY')])
def chooseNextAction(self): previous_action = self.current_action # set next state as the correct action listen, buy, monitor,sell next_action = Action("null") if (previous_action.descr == "Listen"): next_action = Buyer(self.data, previous_action.position, previous_action.log, 0.5) elif (previous_action.descr =="Buy"): next_action = Monitor(self.data, previous_action.position, previous_action.log, self.model) elif (previous_action.descr == "Monitor"): next_action = Seller(self.data, previous_action.position, previous_action.log, 0.5) elif (previous_action.descr == "Sell"): next_action = Listener(self.data, previous_action.position, previous_action.log, self.model) else: next_action.descr = "Abort!!!" self.current_action = next_action return (next_action)
def add_seller(self, s): i = s.branch_name self.sellers[s.id] = Seller(s.id, s.store_name, s.address, s.longitude, s.latitude) self.sellers[s.id].set_branch_name(s.branch_name) self.sellers[s.id].set_visit_frequency(self.visit_frequency[i]) self.sellers[s.id].set_consumption(self.consumption[i]) self.sellers[s.id].set_top_item(self.top_item[i][0].description)
def test_transactions_list(self): with Stub() as first_transaction: first_transaction.seller_id >> 1 first_transaction.month >> 10 with Stub() as second_transaction: second_transaction.seller_id >> 1 second_transaction.month >> 10 with Stub() as third_transaction: third_transaction.seller_id >> 1 third_transaction.month >> 11 Transaction.objects = { 1: first_transaction, 2: second_transaction, 3: third_transaction } # October's transactions Seller.transactions_list(10) |should| equal_to( [first_transaction, second_transaction] )
def test_transactions_list(self): with Stub() as first_transaction: first_transaction.seller_id >> 1 first_transaction.month >> 10 with Stub() as second_transaction: second_transaction.seller_id >> 1 second_transaction.month >> 10 with Stub() as third_transaction: third_transaction.seller_id >> 1 third_transaction.month >> 11 Transaction.objects = { 1: first_transaction, 2: second_transaction, 3: third_transaction } # October's transactions Seller.transactions_list(10) | should | equal_to( [first_transaction, second_transaction])
def initialize_seller(): sellers = [] db = connect_db() cursor = db.cursor() sql = "SELECT * FROM seller" try: cursor.execute(sql) results = cursor.fetchall() for row in results: seller_id = row[0] seller_name = row[1] seller_wallet = row[2] seller_status = row[3] seller_products = initialize_stock(seller_id) seller = Seller(id=seller_id, name=seller_name, products=seller_products, wallet=seller_wallet) sellers.append(seller) except Exception as e: print(e) db.close() return sellers
from seller import Seller from customer import Customer sellers = Seller() customers = Customer() # Create 3 sellers sellers.create('1st seller', 3) sellers.create('2nd seller', 4.1) sellers.create('3rd seller', 5.0) # delete 2nd seller #print(sellers.fetch_all()) #sellers.delete('2nd seller') #print(sellers.fetch_all()) # publish feeds sellers.publish('3rd seller', '1st product', 150) sellers.publish('1st seller', '2nd product', 200) sellers.publish('1st seller', '4th product', 250) sellers.publish('1st seller', '3rd product', 350) sellers.publish('3rd seller', '5rd product', 5000) sellers.publish('2nd seller', '6th product', 5555) # create customers customers.create('1st customer') customers.create('2nd customer') #customers.create('3rd customer') customers.subscribe('1st customer', '1st seller') customers.subscribe('1st customer', '2nd seller')
def __init__(self, n_buyers, n_sellers, min_sell_price, max_sell_price): self._sellers_lock = threading.Lock() self._buyers = [Buyer(random.uniform(min_sell_price, max_sell_price)) for i in range(0, n_buyers)] self._sellers = [Seller(random.uniform(min_sell_price, max_sell_price)) for i in range(0, n_sellers)] self._locked_sellers = set()
aes = [aes[sorted_idx[i]] for i in range(num_users)] bs = [bs[sorted_idx[i]] for i in range(num_users)] Eos = [Eos[sorted_idx[i]] for i in range(num_users)] Emaxs = [Emaxs[sorted_idx[i]] for i in range(num_users)] ab_over_bEos.sort() # ab_over_bEos 순으로 정렬된 buyer 생성 for i in range(num_users): users.append(Buyer(aes[i], bs[i], Eos[i], Emaxs[i])) # seller 생성 a_seller = a * np.random.random() b_seller = b * np.random.random() Emax_seller = Emax * np.random.random() + Emax E_sold = Emax_seller # 맨 처음으로는 가지고 있는 모든 에너지를 판다. seller = Seller(a_seller, b_seller, E_sold, Emax_seller) # 시장거래를 위한 manager 생성 manager = Manager(E_sold, users) # 파는 E (E_sold)에 따른 유저별 w,E,utility를 임시 저장하기 위한 배열 생성 ws = [None] * num_users Es = [None] * num_users us = [None] * num_users final_E = E_sold # E_sold를 -1씩 감소시키면서 utility_seller를 관찰 while True: manager.initialize(E_sold) E = manager.KKT() unit_price = manager.unit_price
''' Created on Sep 11, 2019 @author: rjhumphrey ''' print("Coin Seller") from seller import Seller from position import Position from logger import Logger from data_loader import DataLoader import datetime position = Position('LTC-USD') position.qty = 20 timenow = datetime.datetime.utcnow() data = DataLoader(position.ticker, timenow, False) log = Logger() tolerance = 5.0 seller = Seller(data, position, log, tolerance) seller.sell()
def main(): california_warehouse = WareHouse("California") california_warehouse.increment("APP", 500) california_warehouse.increment("ORG", 200) newyork_warehouse = WareHouse("NewYork") newyork_warehouse.increment("APP", 1200) newyork_warehouse.increment("ORG", 700) cairo_warehouse = WareHouse("Cairo") cairo_warehouse.increment("APP", 1500) cairo_warehouse.increment("ORG", 1000) john_seller = Seller("John") john_seller.add_warehouse(california_warehouse) john_seller.add_warehouse(newyork_warehouse) john_seller.add_warehouse(cairo_warehouse) global threadLock threadLock = threading.Lock() threads = [] # Create new threads thread1 = myThread(1, "Thread-1", 1, seller=john_seller) thread2 = myThread(2, "Thread-2", 2, seller=john_seller) thread3 = myThread(3, "Thread-3", 3, seller=john_seller) thread4 = myThread(4, "Thread-4", 4, seller=john_seller) thread5 = myThread(5, "Thread-5", 5, seller=john_seller) thread6 = myThread(6, "Thread-6", 6, seller=john_seller) thread7 = myThread(7, "Thread-7", 7, seller=john_seller) thread8 = myThread(8, "Thread-8", 8, seller=john_seller) thread9 = myThread(9, "Thread-9", 9, seller=john_seller) thread10 = myThread(10, "Thread-10", 10, seller=john_seller) # Start new Threads thread1.start() thread2.start() thread3.start() thread4.start() thread5.start() thread6.start() thread7.start() thread8.start() thread9.start() thread10.start() # Add threads to thread list threads.append(thread1) threads.append(thread2) threads.append(thread3) threads.append(thread4) threads.append(thread5) threads.append(thread6) threads.append(thread7) threads.append(thread8) threads.append(thread9) threads.append(thread10) # Wait for all threads to complete for t in threads: t.join() print("Exiting Main Thread") print_seller_info(john_seller)
from seller import Seller from buyer import Buyer nick = input("Hello! I'm AliAnalyzer.\nTo help you, "\ + "I need to know what is your name?\n") print() usertype = input("Are you Buyer(enter 1) or Seller(enter 2)?\n") print() while usertype != '1' and usertype != '2': usertype = input("Wrong type of user!\nEnter '1' or '2'\n") print() # Seller's author is Solomiia Dubnevych if usertype == '2': seller = Seller(nick) print("Print 'stop' to finish program.") print() categories = [] for category in seller.main_categories: categories.append(category) while True: print(seller) print() command = input("Choose command №: ")
#'consumer_' + str(i) # Create 500 Consumers objects and assign initial with tolerance and wallet customers = [ Customer(name=names.get_full_name(), wallet=500, tolerance=0.5 + 0.4 * random.random()) for i in range(1, (para.numberofcustomer + 1)) ] # Construct a product object with following attributes iphone = Product(name='iphoneX', price=300, quality=0.9) galaxy = Product(name='Note', price=200, quality=0.8) sony = Product(name='Xperia', price=100, quality=0.6) # Create a Seller object with product as one of the attributes seller_apple = Seller(name='APPLE INC', product=iphone, wallet=1000) seller_samsung = Seller(name='SAMSUNG MOBILES', product=galaxy, wallet=500) seller_sony = Seller(name='SONY', product=sony, wallet=500) # Wait till the simulation ends try: time.sleep(10) except KeyboardInterrupt: pass # kill seller thread seller_apple.kill() seller_samsung.kill() seller_sony.kill() # Plot the sales and expenditure trends plot(seller_apple)
from map.constant_map import ConstantMap from coordinate import Coordinate from seller import Seller world = ConstantMap(Coordinate(5, 5), 1, 10) Sasha = Seller() world.new_store(Sasha.new_score(Coordinate(0, 0), 3)) Petr = Seller() world.new_store(Petr.new_score(Coordinate(4, 4), 3)) Baba_Nura = Seller() world.new_store(Baba_Nura.new_score(Coordinate(2, 2), 2)) world.calc_profit() print(Sasha.get_profit()) print(Petr.get_profit()) print(Baba_Nura.get_profit())
def setUp(self): self.seller = Seller('Oswaldo das Covi', '1234567')
def seller(): print('Hello SELLER!') # loading and creating an account correct2 = 0 while correct2 == 0: seller = input( 'Options:\n1: Load existing account\n2: Create a new one\n') if seller == '1': username = input('Enter username: '******'Username does not exist.') else: print('Hello', username, '!\n') correct2 = 1 elif seller == '2': username = input('Enter username: '******'Hello', username, '!\n') correct2 = 1 else: print('Username exists already.') else: print('Error: Incorrect input.') # OPTIONS while 1: option = input( 'A: Marketplace\nB: Auctions\nC: View Sold Items\nD: Messages\nE: Exit Program\n' ) if option == 'A': # marketplace checker = 0 market = input( 'Options:\n1: Post new item\n2: View all items\n3: Back\n') while checker == 0: if market == '1': print('Posting new item') newitem = input("Enter New Item: ") pexist = Item(newitem, username) if pexist == 0: inp = input( "Item exists already, do you want to update stock? Y or N " ) if inp == 'Y': newstock = input("New Stock: ") update_stock(newitem, newstock, username) item = find_item(newitem) print(item) else: newstock = input("Stock: ") newprice = input("Price: ") dummy_item = Items(newitem, newprice, newstock, username) insert_item(dummy_item) checker = 1 elif market == '2': print('Viewing all items') i = 0 c2.execute("SELECT * FROM Items WHERE seller= :seller", {'seller': username}) results = c2.fetchall() num_items = len(results) while i < num_items: i += 1 print(results[i - 1][0]) checker = 1 elif market == '3': checker = 1 else: print('Invalid input') elif option == 'B': print('Welcome to AUCTIONS') elif option == 'C': print('Welcome to SOLD ITEMS') c3.execute("SELECT * FROM SoldItems WHERE seller= :seller", {'seller': username}) results = c3.fetchall() num_items = len(results) print("Item Name - Quantity") i = 0 while i < num_items: i += 1 print("{} - {}".format(results[i - 1][0], results[i - 1][2])) elif option == 'D': print('Welcome to MESSAGES') elif option == 'E': exit('Goodbye') else: print('Invalid Input.')
from flipkart import Flipkart from admin import Admin from seller import Seller from product import Product from product_categories import Product_Categories from customer import Customer from order import Order from datetime import datetime a1 = Admin("Baba") flip = Flipkart() flip.add_admin(a1) seller1 = Seller("Mohit") seller2 = Seller("Hitesh") flip.add_seller(seller1) flip.add_seller(seller2) product1 = Product("Mobile") product2 = Product("Top") product3 = Product("Chhapal") product4 = Product("light") seller1.add_product_and_quanity(product1, 20) seller1.add_product_and_quanity(product2, 12) seller2.add_product_and_quanity(product2, 10) seller2.add_product_and_quanity(product3, 43) seller2.add_product_and_quanity(product4, 3) seller1.add_product_and_quanity(product4, 5)
from pprint import pprint from seller import Seller from buyer import Buyer #Uncomment the following blocks to test them if __name__ == '__main__': seller = Seller("Solomiia") # print(seller) # print("Best Selling:") # for product in seller.get_best_products(): # print(product) # print("\n\n\n") # # print("Demand:") # pprint(seller.find_demand()) # print("\n\n\n") # # print("Best Sellers:") # pprint(seller.get_best_sellers()) # print("\n\n\n") # # print("Statistic about 'phone charger':") # pprint(seller.get_product_statistic('phone charger')) # print("\n\n\n") # print("Analyzed:") # for i in seller.get_personal_recommendations([32922653638, 32954832491]): # print(i) # print("\n\n\n")
Customer(name='consumer_' + str(i), wallet=3000, products_list=prd_list, tolerance=0.7 + 0.2 * random.random()) for i in range(300) ] insensitive_customers = [ Customer(name='consumer_' + str(i), wallet=3000, products_list=prd_list, tolerance=0.5 + 0.4 * random.random()) for i in range(300, 500) ] # Create Sellers with some budget # Each seller can sell multiple products seller_apple = Seller(name='apple', products_list=[iphone, airpods, phonecase], wallet=1000) seller_samsung = Seller(name='samsung', products_list=[galaxy, tv], wallet=800) seller_xiaomi = Seller(name='xiaomi', products_list=[redmi, robotvac], wallet=500) seller_huawei = Seller(name='huawei', products_list=[mate, laptop], wallet=600) # Wait till the simulation ends print( '\nHello! Welcome to the Market ^_^ Transaction in progress. Lets wait...') try: time.sleep(10) except KeyboardInterrupt: pass
crisp_sets=(0.3 + 0.2 * (random.random() - 0.5), 0.7 + 0.2 * (random.random() - 0.5)), price_tolerance=0.5 + 0.4 * random.random(), quality_tolerance=0.5 + 0.4 * random.random()) for i in range(700)] # Create a product iphone7 = Product(name='iphone7', product_id=0, price=300, quality=0.9, prob_map={'galaxy': [(1, 0.6)]}) galaxy = Product(name='galaxy', product_id=1, price=200, quality=0.7, prob_map={'iphone7': [(0, 0.6)]}) iphone5 = Product(name='iphone5', product_id=2, price=220, quality=0.85, prob_map={'iphone7': [(0, 0.7)], 'galaxy': [(1, 0.8)]}) note = Product(name='note', product_id=3, price=240, quality=0.88, prob_map={'iphone7': [(0, 0.7)], 'iphone5': [(2, 0.5)], 'galaxy': [(1, 0.6)]}) headphone = Product(name='headphone', product_id=4, price=80, quality=0.85, prob_map={'iphone7': [(0, 0.9)], 'galaxy': [(1, 0.9)], 'iphone5': [(2, 0.9)], 'note': [(3, 0.9)]}) # # Create a Seller with some budget seller_apple = Seller(name='apple', product_dict={iphone5: 1470, iphone7: 1500, headphone: 2000}, wallet=1000, dataCenter=dataCenter, email='*****@*****.**') seller_samsung = Seller(name='samsung', product_dict={galaxy: 1650, note: 1200, headphone: 2000}, wallet=500, dataCenter=dataCenter, email='*****@*****.**') # Wait till the simulation ends try: time.sleep(ticks) except KeyboardInterrupt: pass # kill seller thread seller_apple.kill() seller_samsung.kill() Save(seller_apple, object_type='seller') Save(seller_samsung, object_type='seller')