<commit_before>#!/usr/bin/env python
"""
Turn recipes json into a readable menu
"""

import argparse
import json
from collections import OrderedDict

def get_fraction(amount):
    numer, denom = float(amount).as_integer_ratio()
    if denom == 1:
        return numer
    whole = numer / denom
    numer = numer % denom
    return "{}{}/{}".format(str(whole)+' ' if whole > 0 else '', numer, denom)

def get_ingredient_amount(name, amount, unit):
    if isinstance(amount, basestring):
        amount_str = amount
    elif unit == 'oz':
        amount_str = get_fraction(amount)
    else:
        amount_str = str(amount)
    return "\t{} {} {}".format(amount_str, unit, name)

def convert_to_menu(recipes):
    """
    """

    drinks_text = []
    for drink_name, recipe in recipes.iteritems():
        lines = []
        lines.append(drink_name)
        unit = recipe.get('unit', 'oz')
        prep = recipe.get('prep', '')

        for ingredient, amount in recipe['ingredients'].iteritems():
            if ingredient == "optional":
                continue
            lines.append(get_ingredient_amount(ingredient, amount, unit))

        for ingredient, amount in recipe['ingredients'].get('optional', {}).iteritems():
            linestr = "{} (optional)".format(get_ingredient_amount(ingredient, amount, unit))
            lines.append(linestr)


        garnish = ingredients.get('garnish')
        if garnish:
            lines.append("\t{}, for garnish".format(garnish))

        print '\n'.join(lines)



def get_parser():
    p = argparse.ArgumentParser(description="""
Example usage:
    ./program -v -d
""", formatter_class=argparse.RawTextHelpFormatter)
    p.add_argument('-v', dest='verbose', action='store_true')

    return p

def main():

    args = get_parser().parse_args()

    with open('recipes.json') as fp:
        convert_to_menu(json.load(fp, object_pairs_hook=OrderedDict))


if __name__ == "__main__":
    main()
<commit_msg>Dataframes are coming...<commit_after>#!/usr/bin/env python
"""
Turn recipes json into a readable menu
"""

import argparse
import json
from collections import OrderedDict

import pandas as pd
import numpy as np

def get_fraction(amount):
    numer, denom = float(amount).as_integer_ratio()
    if denom == 1:
        return numer
    whole = numer / denom
    numer = numer % denom
    return "{}{}/{}".format(str(whole)+' ' if whole > 0 else '', numer, denom)

def get_ingredient_amount(name, amount, unit):
    if isinstance(amount, basestring):
        amount_str = amount
    elif unit == 'oz':
        amount_str = get_fraction(amount)
    else:
        amount_str = str(amount)
    return "\t{} {} {}".format(amount_str, unit, name)

def convert_to_menu(recipes):
    """
    """

    drinks_text = []
    for drink_name, recipe in recipes.iteritems():
        lines = []
        lines.append(drink_name)
        unit = recipe.get('unit', 'oz')
        prep = recipe.get('prep', '')

        for ingredient, amount in recipe['ingredients'].iteritems():
            if ingredient == "optional":
                continue
            lines.append(get_ingredient_amount(ingredient, amount, unit))

        for ingredient, amount in recipe['ingredients'].get('optional', {}).iteritems():
            linestr = "{} (optional)".format(get_ingredient_amount(ingredient, amount, unit))
            lines.append(linestr)

        garnish = ingredients.get('garnish')
        if garnish:
            lines.append("\t{}, for garnish".format(garnish))

        print '\n'.join(lines)

def calculate_cost(price_df, ingredients, unit):
    pass

def generate_cost_df(barstock_csv):
    import ipdb; ipdb.set_trace()
    df = barstock.from_csv(barstock_csv)


def get_parser():
    p = argparse.ArgumentParser(description="""
Example usage:
    ./program -v -d
""", formatter_class=argparse.RawTextHelpFormatter)
    p.add_argument('-v', dest='verbose', action='store_true')

    return p

def main():

    args = get_parser().parse_args()

    df = generate_cost_df('Barstock - Sheet1.csv')

    with open('recipes.json') as fp:
        convert_to_menu(json.load(fp, object_pairs_hook=OrderedDict))


if __name__ == "__main__":
    main()

{'fraction_non_alphanumeric': 0.13747016706443915, 'fraction_numerical': 0.0011933174224343676, 'mean_word_length': 3.014367816091954, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3039682', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1282, 'n_words': 303}