コード例 #1
0
ファイル: perfectmeal.py プロジェクト: CJOlsen/perfect-meal
def get_fields(nutritional_groupings=['elements', 'vitamins', 'energy',
                                      'sugars', 'amino_acids', 'other',
                                      'composition']):
    print 'get_fields groupings:', nutritional_groupings
    food = Food(nutritional_groupings)
    fields = dict()
    for group in food.get_nutrgroups():
        fields[group] = food.__dict__[group].keys()
        fields[group] = food.get_nutrgroup_members()
    return fields
コード例 #2
0
ファイル: perfectmeal.py プロジェクト: CJOlsen/perfect-meal
def complete_meal(current_meal, min_meal, max_meal, algorithm, food_groups):
    """ Acts as a go-between for the GUI and ackpl.py
        Returns a "completed" meal, completed either because it violated a max
        constraint or because it satisfied all of its min constraints.
        """
    ## should this Name_Filter class be derprecated or just renamed?
    all_foods = get_food_objects(food_group_filter=Food_Group_Filter(food_groups),
                                 name_filter=Name_Filter(),
                                 nutrient_group_filter=current_meal.get_nutrgroups())
    possibilities = []
    serving_sizes = {}
    for food in all_foods:
        serving_sizes[food.get_name()] = food.get_servingsize()
        possibilities.append([food.get_name(), food.flatten()])
    minimums = ('minimums', min_meal.flatten())
    maximums = ('maximums', max_meal.flatten())
    currents = [[food.get_name(), food.flatten()]
                for food
                in current_meal.get_foods()]
    #algorithm = algorithm

    completed_flat = ackpl.ackp(possibilities, minimums, maximums, currents, 
                                algorithm)
    if completed_flat is None:
        return None
    if type(completed_flat) is not list:
        return completed_flat ## maybe?
    foods = []
    for food in completed_flat:
        new_food = Food.unflatten(food[1], food[0])
        new_food.set_servingsize(serving_sizes[new_food.get_name()])
        foods.append(new_food)
    print 'number foods', len(foods)
    new_meal = Meal(foods[0].get_nutrgroups(), foods)
    return new_meal
コード例 #3
0
ファイル: perfectmeal.py プロジェクト: CJOlsen/perfect-meal
def get_fields_for_group(group):
    food = Food([group])
    fields = food.get_nutrgroup_members(group)
    return fields