예제 #1
0
def get_ratio_and_stats(filenames, distinct, merge, zero_columns=None):
    """Parse input files to produce mean recipe ratio and related statistics
    """
    files = [open(filename) for filename in filenames]
    ingredients, proportions = read_files(files)
    proportions = to_grams(ingredients, proportions)
    if distinct:
        proportions = set(proportions)
    ingredients, proportions = merge_columns(ingredients, proportions,
                                                 merge)
    statistics = calculate_statistics(proportions, ingredients, zero_columns)
    ratio = Ratio(ingredients, statistics.bakers_percentage())
    return ingredients, ratio, statistics, len(proportions)
예제 #2
0
def normalize(ingredients, columns):
    """Tests were originally written with the axis swapped, so
         we use zip to swap back here so that the tests don't need
         to change"""
    columns = to_grams(ingredients, columns)
    return zip(*normalize_to_100g(columns))