def priceCalc(self, i): #natural rate of profit- 4% return on capital nrp = 1.04 #K is a constant weight- adjust if needed. At .5 one period is the half life. K = .5 #natural price if d.getMaterials()[i] in d.planted: #2 days, tech same for planting and harvesting ratio = self.incubator.ratios[d.getMaterials()[i]] labor = 2 / (self.tech[i] * ratio) else: labor = 1 / self.tech[i] naturalPrice = (self.DMC[i] + labor) * nrp #if never sold before if self.price[i] == 0: price = round(naturalPrice, 2) oPrice = price #if sold before else: #optimal price, set price. demand = self.sales[i] + self.failSales[i] oPrice = (demand / self.output[i]) * naturalPrice priceAdjustment = (K * (oPrice - self.price[i])) price = round(self.price[i] + priceAdjustment, 2) return (price, oPrice, naturalPrice)
def __init__(self, parent, controller, root): tk.Frame.__init__(self, parent) self.controller = controller self.root = root self.hotkeys = ["<Return>", "<Escape>"] header = tk.Label(self, text="New Product Line", font=TITLE_FONT) products = copy.copy(d.getMaterials()) self.order_var = tk.StringVar() order = tk.OptionMenu(self, self.order_var, *products) self.amount_var = tk.StringVar() vcmd = (self.register(self.controller.isInt), '%P') amount = tk.Entry(self, validatecommand=vcmd, validate="key", textvariable=self.amount_var) ok = tk.Button(self, text="OK", font=BUTTON_FONT, command=self.controller.create_transfer(self.order_var, self.amount_var)) back = tk.Button(self, text="Back", font=BUTTON_FONT, command=lambda: controller.show_frame("market")) main = tk.Button(self, text="esc. Back to office", font=BUTTON_FONT, command=lambda: controller.show_frame("main_keyboard")) header.pack() order.pack() amount.pack() ok.pack() back.pack() main.pack()
def __init__(self, unitName, unitLocality, unitLocationTuple, business): self.name = unitName self.bigdata = big.bigdata(self) stockLength = range(len(d.getMaterials())) missionsLength = range(len(d.getUnitMissions())) self.locality = unitLocality self.location = unitLocationTuple self.business = business self.jobList = [] self.incubator = inc.incubator(self) self.bigdata = big.bigdata(self) self.stock = [0 for material in stockLength] self.output = [0 for material in stockLength] self.tech = [1 for material in stockLength] #current prices self.price = [0 for material in stockLength] self.purchases = [0 for material in stockLength] #yesterday's number of sales for each item self.sales = [0 for material in stockLength] self.failSales = [0 for material in stockLength] self.transports = [0 for material in stockLength] self.failTransports = [0 for material in stockLength] #Direct Materials Cost of a SINGLE instance of each product self.DMC = [0 for material in stockLength] # self.orders = [0 for material in stockLength] self.crafted = [0 for material in stockLength] self.planted = [0 for material in stockLength] self.harvested = [0 for material in stockLength] self.missions = [False for mission in missionsLength] self.can_make = [False for material in stockLength] self.laborTotal = 0 # self.rentTotal = 0 self.customers = []
def dailyRevenue(self): materials = d.getMaterials() revenue = self.getRevenue() noSales = True toString = ("\n" + self.name + " made") for i in range(len(revenue)): if revenue[i] != 0: if not noSales: toString += "," toString += (" $" + str(revenue[i]) + " from " + str(self.sales[i]) + "/" + str(self.sales[i] + self.failSales[i]) + " sales of " + materials[i]) noSales = False toString += "." if noSales: toString = ("\n" + self.name + " made no sales today.") return toString
def getRatio(self, materialIndex): mat = d.getMaterials()[materialIndex] return self.ratios[mat] # #test # inc = incubator(None) # inc.plant("wheat", 50) # inc.plant("beer", 20) # inc.next_day() # inc.next_day() # inc.plant("wheat", 21) # inc.plant("beer", 53) # print("grow_timers: ", inc.grow_timers) # print("growing: ", inc.growing) # inc.next_day() # inc.next_day() # inc.next_day() # inc.next_day() # inc.next_day() # inc.next_day() # inc.next_day() # print("grow_timers: ", inc.grow_timers) # print("growing: ", inc.growing) # print("rot_timers: ", inc.rot_timers) # print("ripe:", inc.ripe) # print("harvest wheat: ", inc.harvest("wheat", 5)) # print("harvest beer: ", inc.harvest("beer", 5)) # print("ripe:", inc.ripe)
def raise_frame(self): for entry in self.dynamic_entries: entry.destroy() char = self.root.getChar() self.manager = self.controller.get_unit().getJobList()[0] raw_orders = self.manager.getBusiness().getTransferOrders() orders = self.cull_wrong_orders(raw_orders) for order in orders: newFrame = tk.Frame(self) newCaption = tk.Label(newFrame, font=BUTTON_FONT, text=d.getMaterials()[order.getProductIndex()] + ":") amountVar = tk.StringVar() amountVar.set(order.getAmount()) vcmd = (self.register(self.controller.isInt), '%P') newEntry = tk.Entry(newFrame, validatecommand=vcmd, validate="key", textvariable=amountVar) newButton = tk.Button(newFrame, font=BUTTON_FONT, text="Ok", command=self.controller.set_order_amount(order, amountVar)) newCaption.pack(side=tk.LEFT) newEntry.pack(side=tk.LEFT) newButton.pack(side=tk.LEFT) newFrame.pack() self.dynamic_entries.append(newFrame) self.back.pack_forget() self.main.pack_forget() self.back.pack(fill=tk.X) self.main.pack(fill=tk.X) self.set_hotkeys() self.tkraise()
def listtostr(self, array): string = "" for i in range(len(array)): if array[i] > 0: string += str(array[i]) + " " + d.getMaterials()[i] + ", " string = string[:-2] return string
def __init__(self, store, heardabout=None): dayNum = store.getLocality().getDayNum() self.store = store self.location = store.getLocation() self.locality = store.getLocality() self.name = store.name self.avgPrices = ([0 for i in d.getMaterials()], dayNum) self.heardabout = str(heardabout.name if heardabout is not None else "Discovered") + " on " + str(store.getLocality().date())
def tempPossibilities(self, investor): possibilities = [True for i in d.getMaterials()] for business in investor.getBusinesses(): for order in business.getCraftOrders(): possibilities[order.getProductIndex()] = False return possibilities
def getSales(self): sales = [0 for i in d.getMaterials()] for unit in self.m_unitList: thisSales = unit.getSales() for i in range(len(thisSales[1])): sales[i] += thisSales[1][i] return ([0,1,2,3,4,5,6,7,8], sales)
def callback(): import orders as o business = self.get_business() job = self.get_job() materialIndex = d.getMaterials().index(order_var.get()) order = business.craftOrderManager(job, materialIndex) order.setAmount(int(amount_var.get())) self.root.event_generate("<<refresh>>", when="tail")
def callback(): import orders as o business = self.get_business() manager = self.get_unit().getJobList()[0] materialIndex = d.getMaterials().index(order_var.get()) transfer = business.transferOrderManager(manager, self.get_unit(), materialIndex) transfer.setAmount(int(amount_var.get())) self.root.event_generate("<<refresh>>", when="tail")
def priceGen(self): yDayNum = self.getDayNum() - 1 oPrice = [0 for i in d.getMaterials()] naturalPrice = [0 for i in d.getMaterials()] for i in range(len(self.price)): if self.output[i] != 0: (self.price[i], oPrice[i], naturalPrice[i]) = self.priceCalc(i) #debug # if self.name in ("Bill's Farm", "Bill's Mill", "Bill's Bakery"): # print(self.name) # print("DMC: ", self.DMC) # print("sales: ", self.sales) # print("output: ", self.output) # print("nPrice: ", naturalPrice) # print("oPrice: ", oPrice) # print("price: ", self.price) # print("") self.resetSales() self.resetCustomers()
def optimalList(self, investor): peopleProfiles = investor.getKnownPeople() highestMU = [0 for i in d.getMaterials()] for profile in peopleProfiles: muList = profile.getMuList()[0] maxMu = muList.index(max(muList)) if muList[maxMu] != 0: highestMU[maxMu] += 1 return highestMU
def purchase(self, store): buyMore = True price = store.getPrice() cash = self.capital muList = self.muList buy = [0 for i in d.getMaterials()] value = [ self.muList[i] / price[i] if price[i] != 0 else 0 for i in range(len(self.muList)) ] #we don't want them to spend all their money on overpriced stuff- they'll need it tomorrow! Utility of money is CONSTANT. MONEYUTIL = 1 while True: i = value.index(max(value)) if (value[i] < MONEYUTIL) or (cash < price[i]): break bestPrice = price[i] cash -= bestPrice buy[i] += 1 value[i] = (self.singleMu(i, self.home.output[i] + buy[i]) / price[i]) if sum(buy) > 0: (amounts, cost, sold) = store.sell(self, copy.copy(buy)) if sold: if (amounts == buy): self.think("I bought " + self.listtostr(amounts) + " for " + str(cost) + " today at " + store.name + ".") else: self.think("I went to buy " + self.listtostr(buy) + " at " + store.name + " but they only had " + self.listtostr(amounts) + ".") else: self.think("I went to " + store.name + " to buy " + self.listtostr(buy) + " but they ran out. I hate that place!") else: sold = False self.think("I don't really need anything from " + store.name + ". What a waste of time.") #update profile self.updateStore(store, sold)
def __init__(self, person, father=(None, 0), mother=(None, 0), spouse=(None, 0), siblings = (None, 0), children = (None, 0)): dayNum = person.getLocality().model.getDayNum() # self.name = person.name self.firstname = person.firstname self.lastname = person.lastname self.locality = person.locality self.meton = person.locality.date() self.children = (dayNum) self.person = person self.muList = ([0 for i in d.getMaterials()], 0) # self.skills = ([0 for i in d.getSkills()], 0) self.father = father self.mother = mother self.spouse = spouse self.siblings = siblings self.children = children self.opinion = 0
def craft(self, productIndex, amount): components = d.getComponents(productIndex) tech = self.unit.getTech(productIndex) DMClist = self.unit.getDMC() productDMC = 0 #reduce to components for component in components: materialIndex = component[0] inStock = self.unit.getStock(materialIndex) ratio = component[1] enoughFor = inStock / ratio if amount > (enoughFor): amount = enoughFor #DMC componentDMC = DMClist[materialIndex] productDMC += componentDMC * ratio #reduce to available employees capability = (len(self.idlers) * tech) if amount > capability: amount = capability #take employees from idlers (so they can't do anything else today) working = math.ceil(amount / tech) workers = self.takeIdlers(working) #take components for component in components: materialIndex = component[0] ratio = component[1] used = amount * ratio self.unit.addStock(materialIndex, -used) #add product- goes to stock for assembly lines. Crafted is for natural price calculation. self.unit.addCrafted(productIndex, amount) self.unit.addStock(productIndex, amount) #set product DMC self.unit.setDMC(productIndex, productDMC) for craftsman in workers: craftsman.think("We crafted " + str(amount) + " " + d.getMaterials()[productIndex] + " today.")
def harvest(self, productIndex): tech = self.unit.getTech(productIndex) product = d.getMaterials()[productIndex] amount = (len(self.idlers) * tech) ripe = self.unit.ripePlants(productIndex) if amount > ripe: amount = ripe #take employees from idlers (so they can't do anything else today) working = math.ceil(amount / tech) workers = self.takeIdlers(working) self.unit.harvest(productIndex, amount) self.unit.addHarvested(productIndex, amount) for farmer in workers: farmer.think("We harvested " + str(amount) + " " + product + " today.")
def dailyCrafted(self): materials = d.getMaterials() toString = ("\n" + self.name + " created") noCrafted = True for i in range(len(self.crafted)): if self.crafted[i] != 0: if not noCrafted: toString += "," toString += (" " + str(self.crafted[i]) + " " + str(materials[i])) noCrafted = False toString += "." if noCrafted: toString = ("\n" + self.name + " didn't craft anything today.") return toString
def harvest(self, materialIndex, amount): if self.ripePlants(materialIndex) >= amount: amount = self.incubator.harvest(d.getMaterials()[materialIndex], amount) self.addCrafted(materialIndex, amount) self.addStock(materialIndex, amount)
def plant(self, productIndex, amount): product = d.getMaterials()[productIndex] if d.isInSeason(productIndex, self.business.model.calendar.state): components = d.getComponents(productIndex) tech = self.unit.getTech(productIndex) growing = self.unit.growingPlants(productIndex) DMClist = self.unit.getDMC() isEnough = True productDMC = 0 #subtract already growing if amount > growing: amount = amount - growing isAllPlanted = False else: amount = 0 isAllPlanted = True #plant if not isAllPlanted: #reduce to components for component in components: materialIndex = component[0] inStock = self.unit.getStock(materialIndex) ratio = component[1] enoughFor = inStock / ratio if amount > (enoughFor): amount = enoughFor isEnough = False #DMC componentDMC = DMClist[materialIndex] productDMC += componentDMC * ratio #reduce to employees capability = (len(self.idlers) * tech) if amount > capability: amount = capability #take employees from idlers (so they can't do anything else today) working = math.ceil(amount / tech) workers = self.takeIdlers(working) #take components for component in components: materialIndex = component[0] ratio = component[1] used = amount * ratio self.unit.addStock(materialIndex, -used) #add product- goes to stock for assembly lines. Crafted is for natural price calculation. self.unit.plantSeeds(productIndex, amount) self.unit.addPlanted(productIndex, amount) #set product DMC self.unit.setDMC(productIndex, productDMC) for farmer in workers: if not isEnough: farmer.think("We ran out of materials for " + product + " at work today.") farmer.think("We planted " + str(amount) + " " + product + " today.") else: for farmer in self.getEmployees(): farmer.think("We've already planted enough " + product + " for the season.") else: for farmer in self.getEmployees(): farmer.think("It's not the planting season for " + product + ".")
def complain(self, who): failSale = [0 for i in range(len(d.getMaterials()))] cost = 0 self.customers.append( (who, failSale, copy.copy(self.output), cost, who.capital, False))
def show_stock(self, entity): display_cont = self.root.get_display_cont() x = d.getMaterials() y = entity.getAllStock() display_cont.bar_chart(x, y, "Materials", "Amount", entity.name +" Stock")
def growingPlants(self, materialIndex): return self.incubator.getGrowing(d.getMaterials()[materialIndex])
def plantSeeds(self, materialIndex, amount): # if self.stock[materialIndex] <= amount: # amount = self.stock[materialIndex] # self.stock[materialIndex] -= amount self.incubator.plant(d.getMaterials()[materialIndex], amount)
def show_production(self, entity): display_cont = self.root.get_display_cont() xy = entity.getProduction() products = [d.getMaterials()[xy[0][i]] for i in range(len(xy[0]))] display_cont.bar_chart(products, xy[1], "Products", "Crafted", entity.name + " Production")
def ripePlants(self, materialIndex): return self.incubator.getRipe(d.getMaterials()[materialIndex])
def getGrowDays(self, materialIndex): mat = d.getMaterials()[materialIndex] return self.grow_days[mat]