def getRange(): # c = Counter() # c['0'] = 5 # c['1'] = 2 # c['2'] = 4 # maxKey = 'dummy' # maxVal = 0 # for key in c: # if c[key] >= maxVal: # maxVal = c[key] # maxKey = key # print maxVal # print maxKey # print util.getIngredientRange('olive oil', 5) util.gramsToUnitAmount(500, 'milk') util.gramsToUnitAmount(200, 'milk')
def printResults(traits): if traits["amount_choices"] == {} or traits["amount_choices"] == []: return ND = traits["ND"] print totals = [0.0 for _ in range(max(traits["nutrientIndices"].values()) + 2)] for k, v in traits["amount_choices"].items(): print "%s: " % traits["amountVarToAlias"][k] print " amount: %.1f %s" % util.gramsToUnitAmount(v[0], traits["amountVarToAlias"][k]) totals[0] += v[0] for nu in traits["focusNutrients"]: nuInd = traits["nutrientIndices"][nu] print " %s: %.1f %s" % (nu, v[nuInd], ND.getNutrientUnit(nu)) totals[nuInd] += v[nuInd] print print "Total mass: " for nu in traits["focusNutrients"]: nuInd = traits["nutrientIndices"][nu] dummyIng = traits["amountVarToAlias"][traits["amount_choices"].keys()[0]] print "Total %s: %.1f %s" % (nu, totals[nuInd], ND.getNutrientUnit(nu))