Пример #1
0
def valid_rec(book, page, name, servings, prep_time, cook_time):
    # 1. test whether all values filled
    if book is None or page is None or name is None or servings is None or prep_time is None or cook_time is None:
        print("Missing some necessary fields!")
        return False
    # 2. test whether code exists already
    rec_id = get_rec_id(book, page)
    if rec_id in list(recipes_db()['RecipeCode'].unique()):
        print("Recipe Code Exists!")
        return False
    print("Recipe Valid!")
    return True
Пример #2
0
def update_week_recipe_list(recipes_selected):

    optns_list = [{'label': recipe, 'value': recipe} for recipe in recipes_selected]

    recipes_db_l = recipes_db()
    recipes_selected_ = [r for r in recipes_selected if r not in EXCL_REC]
    recipes_db_l = recipes_db_l.loc[recipes_db_l['Recipe'].isin(recipes_selected_),
                                    ['Recipe', 'PrepTimeMins', 'CookTimeMins']]
    recipes_db_l = recipes_db_l.drop_duplicates()
    recipes_db_l['TotalMins'] = recipes_db_l['PrepTimeMins'] + recipes_db_l['CookTimeMins']
    recipes_db_l.sort_values(by='TotalMins', inplace=True)
    recipes_db_l = recipes_db_l.drop(columns=['TotalMins'])

    try:
        fig = px.bar(recipes_db_l,
                     y='Recipe',
                     x=['PrepTimeMins', 'CookTimeMins'],
                     orientation='h',
                     labels={
                         'value': 'Minutes',
                         'variable': 'Prep/Cook Time'
                     },
                     color_discrete_map={'PrepTimeMins': 'orangered', 'CookTimeMins': 'lightsalmon'}
                     )
        div = dcc.Graph(
            id='cook_time_graph',
            figure=fig
        )
    except:
        div = dbc.Alert("No recipes selected...", color="warning")
    # recipe_options = dd_options('Recipe', recipes_db_l)
    return optns_list, optns_list, optns_list, optns_list, \
           optns_list, optns_list, optns_list, optns_list, \
           optns_list, optns_list, optns_list, optns_list, \
           optns_list, optns_list, optns_list, optns_list, \
           optns_list, optns_list, optns_list, optns_list, \
           optns_list, optns_list, optns_list, optns_list, \
           optns_list, optns_list, optns_list, optns_list, \
           div
Пример #3
0
def save_recipe(n, data, book, page, name, servings, prep_time, cook_time, months, tags):
    global recipes_db
    if valid_rec(book, page, name, servings, prep_time, cook_time):
        # main rec data
        recipes_db_l = recipes_db()
        rec_df = pd.DataFrame(data)
        rec_df['RecipeCode'] = get_rec_id(book, page)
        rec_df['Recipe'] = name
        rec_df['Servings'] = servings
        rec_df['PrepTimeMins'] = prep_time
        rec_df['CookTimeMins'] = cook_time
        rec_df = rec_df.merge(ingredients_db[['Name', 'Location']].rename(columns={'Name': 'Ingredient'}))
        print(recipes_db_l.shape)
        recipes_db_l = pd.concat([recipes_db_l,rec_df])
        print(recipes_db_l.shape)
        recipes_db_l.to_csv('data/recipes.csv', index=False)
        # rec tags data
        if tags:
            tags_old = pd.read_csv('data/recipes_tags.csv')
            tags_new = pd.DataFrame(data={
                'RecipeCode': [get_rec_id(book, page)] * len(tags),
                'Tags': tags
            })
            tags_df = pd.concat([tags_old, tags_new])
            tags_df.to_csv('data/recipes_tags.csv', index=False)
        # rec months data
        if months:
            months_old = pd.read_csv('data/recipes_months.csv')
            months_new = pd.DataFrame(data={
                'RecipeCode': [get_rec_id(book, page)] * len(months),
                'Months': months
            })
            months_df = pd.concat([months_old, months_new])
            months_df.to_csv('data/recipes_months.csv', index=False)
        return True
    return False
Пример #4
0
def shopping_list_update(a1, b1, c1, d1,
                         a2, b2, c2, d2,
                         a3, b3, c3, d3,
                         a4, b4, c4, d4,
                         a5, b5, c5, d5,
                         a6, b6, c6, d6,
                         a7, b7, c7, d7,
                         n, weekdate):
    meal_list = [a1, b1, c1, d1,
                 a2, b2, c2, d2,
                 a3, b3, c3, d3,
                 a4, b4, c4, d4,
                 a5, b5, c5, d5,
                 a6, b6, c6, d6,
                 a7, b7, c7, d7]
    shopping_list_raw = pd.DataFrame(meal_list, columns=['Recipe'])
    shopping_list = shopping_list_raw.dropna().groupby('Recipe').size().reset_index(name='Meals')
    shopping_list = shopping_list.merge(recipes_db(), how='inner', left_on='Recipe', right_on='Recipe')
    shopping_list['Quantity'] = shopping_list['Meals']*shopping_list['Quantity']/shopping_list['Servings']
    shopping_list.sort_values(by=['Location','Ingredient'], ascending=False, inplace=True)
    shopping_list = shopping_list[~shopping_list.Recipe.isin(EXCL_REC)]

    # store data
    shopping_list_raw['Week'] = str(weekdate)
    shopping_list_raw['TS'] = dt.datetime.now().strftime('%Y%m%d%H%M%S')
    sl_store = shopping_list_raw[~shopping_list_raw['Recipe'].isnull()]
    if sl_store.shape[0] >= round((7 * 2 * NO_OF_PERSONS) * REQD_FILL_PCT) or dash_context() == 'manual_save_button':
        # check if there was an update...
        week_meals_new = sl_store.reset_index()[['Recipe']]
        week_meals_old = meal_plan(weekdate).reset_index()[['Recipe']]
        if not(week_meals_new.equals(week_meals_old)):
            print("Save Week")
            print(sl_store.head())
            sl_store.to_csv('data/sl_store.txt', mode='a', header=False)  # dev

    return shopping_list.to_dict('records')
Пример #5
0
                 {
                     'label': i,
                     'value': i
                 } for i in
                 [get_startdate(j, fmt_as_code=True) for j in range(-3, 4)]
             ],
             value=get_startdate(0, fmt_as_code=True),
             clearable=False),
         html.Hr(),
         html.Label("Select meals for this week"),
     ])),
 # meals selection
 dbc.Row([
     dbc.Col([
         dcc.Dropdown(id='ingr_filter',
                      options=dd_options('Ingredient', recipes_db()),
                      multi=True,
                      placeholder='Recipe Ingredient(s)')
     ]),
     dbc.Col([
         dcc.Dropdown(id='month_filter',
                      options=[{
                          'label': optn,
                          'value': optn
                      } for optn in MTH_LIST],
                      multi=True,
                      placeholder='Month(s)')
     ]),
     dbc.Col([
         dcc.Dropdown(id='tag_filter',
                      options=[{
Пример #6
0
from functions import dd_range_options, dd_options
from data import recipes_db, phdf_rec_ingr_tbl, ingredients_db, SEASONS_LIST, MTH_LIST, TAG_LIST, BOOK_LIST

UNITS_LIST = ['g', 'ml', 'medium', 'small', 'large', 'tbsp', 'tsp']

recipe_editor_layout = html.Div([
    # header row
    dbc.Row(dbc.Col([
        html.H3('Recipe Editor'),
        dcc.Dropdown(
            id='recipe_editor_select',
            placeholder='Select Recipe (WIP)',
            options=[{
                'label': r['RecipeCode'] + ' ' + r['Recipe'],
                'value': r['Recipe']
            } for r in recipes_db()[['RecipeCode', 'Recipe']].drop_duplicates(
            ).sort_values(by='RecipeCode').to_dict("records")]),
        dbc.Input(id='r_name_input',
                  placeholder='Recipe Name',
                  autoComplete="off",
                  type="text")
    ]),
            no_gutters=True),
    # recipe info row 1
    dbc.Row(
        [
            dbc.Col([
                dcc.Dropdown(id='r_book_select',
                             placeholder='Book',
                             options=[{
                                 'label': name,
                                 'value': code