def test_supplier_resets(): blah_supplier = Supplier("blah") with blah_supplier.use("hello"): pass with pytest.raises(Exception): blah_supplier.get()
def test_supply_decorator(): foo_supplier = Supplier("foo") @supply(foo_supplier) def has_arg(hello): assert hello == "hello" with foo_supplier.use("hello"): has_arg()
def test_supply_decorator_with_arg(): foo_supplier = Supplier("foo") @supply(foo_supplier) def has_arg(hello, there): assert hello == "hello" assert there == "there" with foo_supplier.use("hello"): has_arg("there")
def test_supply_decorator_optional_args(): foo_supplier = Supplier("foo") @supply(foo_supplier) def has_arg(hello, there, pal="pal"): assert hello == "hello" assert there == "there" assert pal == "pal" with foo_supplier.use("hello"): has_arg("there") has_arg("there", "pal")
def run_supplier_tests(self): c = Contact("Some Body", "*****@*****.**") s = Supplier("Sup Plier", "*****@*****.**") print(c.name, c.email, s.name, s.email) c.all_contacts try: c.order("Ineed pliers") # expect error here except AttributeError as e: print("Exception for c.order()") print("exception args: ", e.args) s.order("I need pliers")
def createSupplier(self, supplierName, deliveryTime): # ID will be automatically set supplier = Supplier(self.nextSupplierID(), supplierName, deliveryTime) # This supplier does not have any materials set YET. Add material method must be called to add materials to a # supplier . This is done cause one supplier has the ability to sell multiple materials print("Empty Supplier Created -", str(supplier)) self.suppliers.append(supplier)
def load(self): def loadFromFile(filename): try: with open(filename, "rb") as file: data = pickle.load(file) return data except Exception: file = open(filename, "wb") file.close() self.__stock = Stock() loadedStockData = loadFromFile(self.savePath + self.__companyName + "_stockData.dat") if loadedStockData is not None: self.__stock.setAllData(loadedStockData) self.suppliers = [] loadedSuppliers = loadFromFile(self.savePath + self.__companyName + "_supplierData.dat") if loadedSuppliers is not None: for supplierData in loadedSuppliers: supplierObj = Supplier(0, "PLACEHOLDER_NAME", 0) supplierObj.setAllData(supplierData) self.suppliers.append(supplierObj)
def test_supplier_can_be_used_multiple_times(): foo_supplier = Supplier("foo") with foo_supplier.use("hello"): assert foo_supplier.get() == "hello" with foo_supplier.use("hi"): assert foo_supplier.get() == "hi"
def test_supply_decorator_multiple_suppliers(): foo_supplier = Supplier("foo") bar_supplier = Supplier("bar") @supply(foo_supplier, bar_supplier) def has_arg(hello, there, friend): assert hello == "hello" assert there == "there" assert friend == "friend" with foo_supplier.use("hello"), bar_supplier.use("there"): has_arg("friend")
def main(): simulation = Simulation(name="NORI Token Market Simulation v0.1") print(simulation) # simulation.declare_round_endowment() IS THIS NECESSARY? suppliers = simulation.build_agents( Supplier, 'supplier', 100) # Put these in parameters.csv and use .build_agents_from_file simulation.build_agents(Spotbuyer, 'spotbuyer', 100) simulation.build_agents(Speculator, 'speculator', 1000) simulation.build_agents(Coinex, 'coinex', 1) # Create supplier_queue from 'crc_supply_sample.csv' in order returned from the code in lines 70-75, above # Each supplier has an associated marginal_cost and marginal_qty # For supplier i, if expected_price >= reserve_price, # list_crc and remove from queue # else evaluate the next element in list # LIKE THIS? # Make 100 suppliers #for supplier_number in range(100): # new_supplier = {'marginal_cost': X, 'marginal_qty': Y, 'expected_price': Z} # supplier_queue.append(new_supplier) for round in range(360): # Assume 360 trading days per year simulation.advance_round(round) Supplier().self.list_crc( ) # IS THIS THE RIGHT WAY TO DO THIS? Supplier lists CRC if expected_price > marginal_cost spotbuyer.buy_nori() # Spot Buyer buys NORI from Coinex coinex.exch_sell_nori() # Coinex sells NORI to Spot Buyer spotbuyer.buy_crc() # Spot Buyer purchases CRC spotbuyer.retire_crc() # Spot Buyer (smart contract) retires CRC (supplier + spotbuyer()).panel_log(...) # Log CRC trades speculator.trade_nori() # Speculators trade supplier.sell_nori() # Supplier sells NORI to Coinex speculator.sell_nori() # Speculator sells NORI to Coinex coinex.exch_buy_nori() # Coinex buys coinex.panel_log(...) # Log NORI trades # Do we need to clear trades? If so, how? simulation.graphs() simulation.finalize()
def test_supply_decorator_in_classes(): foo_supplier = Supplier("foo") bar_supplier = Supplier("bar") class Baz: name = "baz" @supply(foo_supplier, bar_supplier) def bound_method(self, hello, there, cool, house): assert hello == "hello" assert there == "there" assert self.name == "baz" assert cool == "cool" assert house == "house" baz = Baz() with foo_supplier.use("hello"), bar_supplier.use("there"): baz.bound_method("cool", "house")
from customer import Customer from supplier import Supplier from item import Item from supply import Supply from order import Order from admin import Administrator from review import Review supply = list() orders = list() items = list() reviews = list() admin1 = Administrator("iamgod", "iamthelaw", "*****@*****.**") supplier1 = Supplier("isupply", "4real", "Crab Shack Company", "Van Crabs", "000-112-35-8", "*****@*****.**") supplier2 = Supplier("isupplytoo", "4real", "Reliable Company", "Van Reliable", "011-112-35-8", "*****@*****.**") customer1 = Customer("iamguido", "4sure", "Guido", "Van Rossum", "000-112-35-8", "*****@*****.**", "09-09-1968") item1 = Item("Banana", "Better than ever before", 799.0, ("Golden", "Fresh Green")) item2 = Item("Best Banana", "Better than others", 899.0, ("Truly Golden", "Fresher Green")) review1 = Review('Brilliant', "iamguido", 5) supply.append(supplier1.add_supply(item1, 10)) supply.append(supplier2.add_supply(item2, 3)) customer1.create_order(item2, 5)
def __init__(self, outfile, maxdocs=0): self.supplier = Supplier(maxdocs=maxdocs) self.analyzer = Analyzer() self.recorder = Recorder(outfile=outfile)
def test_supplier_supplies(): blah_supplier = Supplier("blah") with blah_supplier.use("hello"): assert blah_supplier.get() == "hello"
from customer import Customer from supplier import Supplier from item import Item from supply import Supply from order import Order from admin import Administrator from review import Review supply = list() orders = list() items = list() reviews = list() admin1 = Administrator("iamgod", "iamthelaw", "*****@*****.**") supplier1 = Supplier("isupply", "4real", "Crab Shack Company", "Van Crabs", "000-112-35-8", "*****@*****.**") supplier2 = Supplier("isupplytoo", "4real", "Reliable Company", "Van Reliable", "011-112-35-8", "*****@*****.**") customer1 = Customer("iamguido", "4sure", "Guido", "Van Rossum", "000-112-35-8", "*****@*****.**", "09-09-1968") item1 = Item("Banana", "Better than ever before", 799.0, ("Golden", "Fresh Green")) item2 = Item("Best Banana", "Better than others", 899.0, ("Truly Golden", "Fresher Green")) customer1.add_review(item2, "very tasty", 5) reviews.append(customer1.add_review(item2, "very tasty", 5))
from thief import Thief from retailer import Retailer from supplier import Supplier thief = Thief() retailer = Retailer() supplier = Supplier() nextRound = 50 security = 30 #Suppose the game starts from low security level and stealing $50 i = 0 while i < 10: stolenAmount, nextRound = thief.steal(nextRound, security) securityLevels = supplier.strategy(stolenAmount) security = retailer.strategy(stolenAmount, securityLevels, security) print(security) if stolenAmount < 0: print( "Thief was caught and paid ${} this round and will steal ${} next round" .format(stolenAmount, nextRound)) else: print("Thief stole ${} this round and will steal ${} nextRound".format( stolenAmount, nextRound)) print("Retailer spends ${} on security".format(security)) print( "Security Supplier has profit of (x) and provides {}% level of security" .format(security)) i += 1
import uuid class Supply: def __init__(self, item, supplier, amount): self.id = uuid.uuid4() self.item = item self.supplier = supplier self.amount = amount def __str__(self): return f"{self.id}: {self.item} by {self.supplier}" def __repr__(self): return f"{self.id}: {self.amount} {self.item.title} by {self.supplier.company_name}" if __name__ == '__main__': from item import Item from supplier import Supplier i1 = Item("Banana", "Better than ever you tried before", 809.90, ("Yellow", "Fish Yellow")) s1 = Supplier("isupply", "4real", "Crab Shack Company", "Van Crabs", "000-112-35-8", "*****@*****.**") sup1 = Supply(i1, s1, 3) print(sup1)
def __init__(self): self.databank = { "Fruit": { 1: { "name": "Apple", "shelflife": 9, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 2: { "name": "Banana", "shelflife": 4, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 3: { "name": "Blueberry", "shelflife": 7, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 4: { "name": "Cherry", "shelflife": 4, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 5: { "name": "Grapes", "shelflife": 5, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 6: { "name": "Orange", "shelflife": 7, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 7: { "name": "Pineapple", "shelflife": 5, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 8: { "name": "Pear", "shelflife": 7, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 9: { "name": "Strawberry", "shelflife": 4, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 10: { "name": "Watermelon", "shelflife": 7, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None } }, "Vegetable": { 1: { "name": "Beetroot", "shelflife": 9, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 2: { "name": "Cabbage", "shelflife": 9, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 3: { "name": "Carrot", "shelflife": 9, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 4: { "name": "Cauliflower", "shelflife": 7, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 5: { "name": "Corn", "shelflife": 4, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 6: { "name": "Cucumber", "shelflife": 5, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 7: { "name": "Onion", "shelflife": 9, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 8: { "name": "Potato", "shelflife": 9, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 9: { "name": "Spinach", "shelflife": 7, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None }, 10: { "name": "Tomato", "shelflife": 7, "price": 2, "localinventory": None, "internationalinventory": None, "supplier": None, "stockdate": None, "expirydate": None } } } self.supplier = Supplier() self.suppliers = self.supplier.supplier_name
import uuid from simple_logger import logger class Supply: def __init__(self, item, supplier, amount): self.id = uuid.uuid4() self.item = item self.supplier = supplier self.amount = amount self.log = logger self.log.info(f"Supply is done") def __str__(self): return f"{self.id}: {self.item} by {self.supplier}" def __repr__(self): return f"{self.id}: {self.amount} {self.item.title} by {self.supplier.company_name}" if __name__ == '__main__': from supplier import Supplier from item import Item supplier1 = Supplier("isupply", "4real", "Crab Shack Company", "Van Crabs", "000-112-35-8", "*****@*****.**") item1 = Item("Banana", "Better than ever before", 799.0, ("Golden", "Fresh Green")) supplier1.add_supply(item1, 10)
from grabber import Grabber from processor.zcool import ZCool from supplier import Supplier resources = Supplier.get_resources() for resource in resources: grabber = Grabber(resource) grabber.get() ZCool.parse_article_list(grabber.content) break # grabber.write()
driver.get(base) str_zip_code = str(zip_code).zfill(5) inputElt = driver.find_element_by_xpath('//input[@class="zip"]') inputElt.send_keys(str_zip_code) prev_url = driver.current_url driver.find_element_by_xpath('//input[@value="Go"]').click() while driver.current_url == prev_url: sleep(0.1) if 'search' in driver.current_url: supplier = Supplier(driver, connection, zip_code) empty = True i = 0 for id, href in supplier.parse(): empty = False driver.get(href) vr = ViolationSummary(driver, connection, id) violationSummary = vr.parse() contaminants = Contaminants(driver, connection, id) contaminants.parse() i += 1 if empty: print("UPDATE zip_codes SET suppliers='{}' WHERE zipcode=%d" % zip_code) connection.execute("UPDATE zip_codes SET suppliers='{}' WHERE zipcode=%d" % zip_code) print('Found %d suppliers for %s' % (i, str_zip_code)) else: