def need_ingredients(self): amountInv = 0 amountNeeded = 0 listOfKeys = [] listOfTypes = [] listOfAmounts = [] listOfNeeded = [] # get list of keys for the types in inventory for (typ, amount) in self.needIngredients: for mfg, liquor in db.check_inventory_for_type(typ): listOfKeys.append((mfg, liquor)) listOfTypes.append((typ, listOfKeys)) listOfKeys = [] for (t, lk) in listOfTypes: amountInv = 0 for (m, l) in lk: if (m, l) in db._inventory_db or listOfTypes[1] == []: if db._inventory_db[(m, l)] > amountInv: amountInv = db._inventory_db[(m, l)] listOfAmounts.append((t, amountInv)) for (t, a) in self.needIngredients: for (typ, amount) in listOfAmounts: if t == typ: amountNeeded = float(convert.convert_to_ml(a)) - float(amount) if amountNeeded > 0: listOfNeeded.append((typ, amountNeeded)) return listOfNeeded
def need_ingredients(self): notFound = [] for typ, amount in self.ingredients: ingNeeded = db.convert_to_ml(amount) print type(ingNeeded) #print ingNeeded ingInInventory = db.check_inventory_for_type(typ) print type(ingInInventory) print typ, amount, ingInInventory, ingNeeded if float(ingInInventory) <= float(ingNeeded): ingMissing = float(ingNeeded) - float(ingInInventory) missingTup = (typ, ingMissing) notFound.append(missingTup) else: continue return notFound
def need_ingredients(self): needed = [] #loop through ingredients for (typ, needed_amount) in self.ingredients: needed_amount = db.convert_to_ml(needed_amount) #check supply supply = db.check_inventory_for_type(typ) print supply if supply: total_amount = 0 for m,l,_ in supply: total_amount = db.get_liquor_amount(m,l) if needed_amount - total_amount > 0: #we don't have enough :( needed_amount = needed_amount - total_amount else: continue needed.append((typ, needed_amount)) if needed == []: return False else: return needed
def need_ingredients(self): print "SELF.IN: ",self.Ingredients missing = [] stock = dict() #contains key: (mfg,liquor,typ) value: amount #First: fill a dict with our stock that matches the liquor type for i in self.Ingredients: for item in db.check_inventory_for_type(i[0]): #returns mfg/liquor tuples with liquor == {ingredient name} #fetches from the inventory the amount db._c.execute("SELECT amount FROM inventory WHERE \ mfg = ? AND liquor = ?",(item[1],item[2])) amount = int(db._c.fetchone()[0]) if item in stock.keys(): #add to temp dictionary stock[(item[2],item[3])] += float(amount) else: stock[(item[2],item[3])] = float(amount) if len(stock) == 0: #no ingredients of that type(s) in db for i in self.Ingredients: amount = db.convert_to_ml(i[1]) missing.append((i[0],amount)) return missing #next: check to see if we have bottles with enough liquor for each ingredient in the recipe (to refrain from mixing bottles) for i in self.Ingredients: needed = db.convert_to_ml(i[1]) #print "\nWe need %s ml of %s" % (needed, i[0]) most = 0 #greatest amount per bottle, overwritable flag = False #False implies not enough liquor in any given bottle to satisfy the ingredient amount for item, amt in stock.items(): #print "looking for greatest amount: %s -- %s?" % (item, amt) print item[1], i[0] if str(item[1]) == str(i[0]): if amt >= needed: flag = True #print " greater than needed!" if amt > most: most = stock[item] #print " new greatest amount!" if flag == False: miss = i[0],(needed-most) missing.append(miss) if len(missing) != 0: return missing else: return False
def need_ingredients(self): missingList = list() for ingredient in self._ingredients: #go through current ingredients listOfTuples = db.check_inventory_for_type(ingredient[0]) stockAmount = 0 for tuple in listOfTuples: amt = db.get_liquor_amount(tuple[0],tuple[1]) if amt>stockAmount: stockAmount = amt debtAmount = stockAmount - db.convert_to_ml(ingredient[1]) if ( debtAmount < 0 ): missingList.append((ingredient[0],debtAmount*-1.)) return missingList
def need_ingredients(self): myList = list() for currentIngredient in self._myIngredients: listOfMandLTuples = db.check_inventory_for_type(currentIngredient[0]) amountInStock = 0 for myTuple in listOfMandLTuples: val = db.get_liquor_amount(myTuple[0],myTuple[1]) if val>amountInStock: amountInStock = val amountInDebt = amountInStock - db.convert_to_ml(currentIngredient[1]) if ( amountInDebt < 0 ): myList.append((currentIngredient[0],amountInDebt*-1.)) return myList
def need_ingredients(self): need = [] amount = 0 for i in self.ingredients: typehave = db.check_inventory_for_type(i[0]) most = 0 for (m, l) in typehave: if db.get_liquor_amount(m, l) > most: amount = db.get_liquor_amount(m, l) most = amount amount = db.convert_to_ml(i[1])-amount if amount > 0: need.append((i[0], amount)) return need
def need_ingredients(self): """ This methode takes in the recipe and returns how many components are needed to complete the recipe. It returns the components in the form of a list of 2-tuples""" needed = [] for t, amount in self.comp: in_inventory = db.check_inventory_for_type(t) required = db.convert_to_ml(amount) if in_inventory < required: print required print in_inventory needed.append((t,required - in_inventory)) else: continue return needed
def need_ingredients(self): volume = 0 missing = [] for type, quantity in self.singridients: needed = convert.convert_to_ml(quantity) available = db.check_inventory_for_type(type) for (m,l) in available: vol = db.get_liquor_amount(m,l) if vol > volume: volume = vol if volume < needed: missing.append((type,needed - volume)) volume = 0 else: continue return missing
def need_ingredients(self): needed = [] for (generic_type, amount) in self.ingredients: matching = db.check_inventory_for_type(generic_type) max_m = '' max_l = '' max_amount = 0.0 for (m, l, t) in matching: if t > max_amount: max_amount = t amount_needed = db.convert_to_ml(amount) if max_amount < amount_needed: needed.append((generic_type, amount_needed - max_amount)) return needed
def need_ingredients(self): # Start by creating a temp dict of remaining liquor needed in ml ingredientsRemaining = {} for (n, a) in self.ingredients: ingredientsRemaining[n] = db.convertToMl(a) # Then gets total liquor of each type from db, subtracts, and returns final list filledIngredients = [] for n in ingredientsRemaining: ingredientsRemaining[n] -= db.check_inventory_for_type(n) if ingredientsRemaining[n] <= 0: filledIngredients.append(n) for n in filledIngredients: del ingredientsRemaining[n] returnedList = [] for n in ingredientsRemaining: returnedList.append((n, ingredientsRemaining[n])) return returnedList
def need_ingredients(self): types_needed = [] ingredients_needed = [] for (typ, amt) in self.ingredients: amt = convert.convert_to_ml(amt) brands_owned = db.check_inventory_for_type(typ) if len(brands_owned) == 0: types_needed.append((typ, amt)) else: amounts_from_brands = [] for (m, l) in brands_owned: amount_owned_of_brand = db.get_liquor_amount(m, l) amounts_from_brands.append(amount_owned_of_brand) if (amount_owned_of_brand <= amt): amount_needed = amt - amount_owned_of_brand ingredients_needed.append((typ, amount_needed)) for (type_needed, amount_needed) in types_needed: ingredients_needed.append((type_needed, amount_needed)) return ingredients_needed
def need_ingredients(self): missing = [] for (type, amt) in self.ingredients: # get a list of what types are in inventory have_types = db.check_inventory_for_type(type) # get the amount of the needed type that is already in the inventory have_amount = 0.0 for (mfg, lqr) in have_types: # only the highest amount of one type counts as the total amount # this prevents mixing alcohols if db.get_liquor_amount(mfg,lqr) > have_amount: have_amount = db.get_liquor_amount(mfg,lqr) # find out how much is needed need_amount = have_amount - to_ml(amt) if need_amount < 0.0: missing.append((type, need_amount*-1)) return missing
def need_ingredients(self): Available = [] Needed = {} List = list() for i in self._ingredients: items = db.check_inventory_for_type(i[0]) #this is the amt we need in ml amt = db.convert_to_ml(i[1]) Needed[i[0]] = amt for x in items: amt_avl = db.get_liquor_amount(x[0], x[1]) #if the current amt_avl is the largest so far then remove it from the amount needed if (amt - amt_avl) < Needed[i[0]]: Needed[i[0]] = amt - amt_avl #The amount needed for the recipe will be less than 0 after this point if there is enough liquor available. So remove it from the Dictionary of needed ingredients if Needed[i[0]] <= 0.0: del Needed[i[0]] #put all the elements from the dictionary into a List for i in Needed: List.append( (i, Needed[i]) ) return List
def need_ingredients(self): missingList = [] for (alcohol, amount) in self._ingredients: #Get a list of the bottleTypes from the inventory bottleTypeList = db.check_inventory_for_type(alcohol) #Create an amounts dictionary to determine how much of an amount of #a bottle type is needed. Stores the key as (m,l,t) to ensure there #is no mixing of alcohol types amounts=dict() for(mlg, liquor, alcoholType, inventoryAmount) in bottleTypeList: if(alcoholType == alcohol): if((mlg, liquor,alcoholType) not in amounts): amounts[(mlg,liquor,alcoholType)] = amount - inventoryAmount else: amounts[(mlg,liquor,alcoholType)] -= inventoryAmount #Find out if the bottle type was found, if so, find the type that you have #the most of (called lowestAmount, which represents the amount needed. #Therefore a negative amount means that you have enough for the recipe.) lowestAmount = 99999999999 amountFound = False for(m, l, t) in amounts: if(amounts[(m,l,t)] < lowestAmount): lowestAmount = amounts[(m,l,t)] amountFound = True #Appends the lowestAmount needed if an amount at all was found, otherwise #append the fact that you need the entire amount for your recipe if(lowestAmount > 0 and amountFound == True): missingList.append((alcohol, lowestAmount)) elif(amountFound == False): missingList.append((alcohol,amount)) return missingList