Skip to content

Commit

Permalink
Recipes: dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Hélouis committed Sep 30, 2015
1 parent b207e39 commit f7bb330
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 16,538 deletions.
4 changes: 1 addition & 3 deletions testing/recipe_engine/db_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ def save_recipe(recipe):
r.category = recipe.meal_type
r.save()

# TODO: check uniqueness of relation recipe/ingredient
# link to ingredients
matching = get_matching_ingredients(recipe.ingredients)
for parsed, matched in matching.items():
if matched:
if matched and not r.ingredients.filter(name=matched.name):
rtoi = RecipeToIngredient(
recipe=r,
ingredient=matched,
Expand All @@ -113,4 +112,3 @@ def save_recipe(recipe):
parsed_name=parsed.name,
)
rtoi.save()

16,521 changes: 0 additions & 16,521 deletions testing/recipe_engine/good_recipes.txt

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions testing/recipe_engine/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ def retrieve_recipes():
urls = f.readlines();
for i, url in enumerate(urls):
url = url.strip('\n')
recipe = Recipe(url)
if not menus.models.Recipe.objects.filter(name=recipe.title):
try:
try:
recipe = Recipe(url)
if not menus.models.Recipe.objects.filter(name=recipe.title):
save_recipe(recipe)
except:
break
print("Saved %s" % recipe.title)
else:
print("Skipping %s, already in database" % recipe.title)
if i % 1000 == 0:
time.sleep(600)
print("Saved %s (%s)" % (recipe.title, url))
else:
print("Skipping %s, already in database" % recipe.title)
except:
continue
if (i + 1) % 700 == 0:
print("%s - Sleeping 15 minutes" % time.strftime("%H:%M"))
time.sleep(900)
11 changes: 11 additions & 0 deletions testing/static/vendor/js/Chart.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions testing/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@
{% endblock %}

<script src="{% static 'vendor/js/bootstrap.js' %}"></script>

{% block js %}
{% endblock %}

</body>
</html>
188 changes: 188 additions & 0 deletions testing/templates/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
{% extends 'base.html' %}
{% load staticfiles %}

{% block content %}
<div class="container">

<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="{% url 'testing.views.index' %}">Dashboard</a>
</div>
</div>
</nav>

<button class="btn btn-primary">{{ nb_recipes }} Recettes</button>
<button class="btn btn-info">{{ nb_ingreds }} Ingrédients</button>
<button class="btn btn-warning">{{ nb_nut }} Nutriments</button>
<br/>
<br/>
<br/>
<br/>

<div class="row">
<label for="difficultyPieChart">Difficulté des recettes</label>
<canvas id="difficultyPieChart" width="200" height="200"></canvas>
<label for="peopleAmountPieChart">Nombre de personnes</label>
<canvas id="peopleAmountPieChart" width="200" height="200"></canvas>
<label for="pricePieChart">Prix des recettes</label>
<canvas id="pricePieChart" width="200" height="200"></canvas>
</div>
<div class="row">
<label for="mealTypesPieChart">Catégories de recettes</label>
<canvas id="mealTypesPieChart" width="200" height="200"></canvas>
</div>

</div>
{% endblock %}

{% block js %}
<script src="{% static 'vendor/js/Chart.min.js' %}"></script>
<script>
var data_difficulty = [
{
value: {{ nb_very_easy }},
color:"#33CC33",
highlight: "#70DB70",
label: "Très Facile"
},
{
value: {{ nb_easy }},
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Facile"
},
{
value: {{ nb_medium }},
color: "#FDB45C",
highlight: "#FFC870",
label: "Moyenne"
},
{
value: {{ nb_difficult }},
color:"#F7464A",
highlight: "#FF5A5E",
label: "Difficile"
}
];
var ctxDPC = $("#difficultyPieChart").get(0).getContext("2d");
new Chart(ctxDPC).Pie(data_difficulty);

var data_people_amount = [
{
value: {{ amount_1 }},
color:"#33CC33",
highlight: "#70DB70",
label: "Pour 1 personne"
},
{
value: {{ amount_2 }},
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Pour 2 personnes"
},
{
value: {{ amount_3 }},
color: "#FDB45C",
highlight: "#FFC870",
label: "Pour 3 personnes"
},
{
value: {{ amount_4 }},
color:"#F7464A",
highlight: "#FF5A5E",
label: "Pour 4 personnes"
},
{
value: {{ amount_many }},
color:"#660066",
highlight: "#751975",
label: "Pour 5 personnes ou plus"
}
];
var ctxPPC = $("#peopleAmountPieChart").get(0).getContext("2d");
new Chart(ctxPPC).Pie(data_people_amount);

var data_price = [
{
value: {{ price_0 }},
color:"#33CC33",
highlight: "#70DB70",
label: "Bon marché"
},
{
value: {{ price_1 }},
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Moyen"
},
{
value: {{ price_2 }},
color:"#F7464A",
highlight: "#FF5A5E",
label: "Assez cher"
}
];
var ctxPPC = $("#pricePieChart").get(0).getContext("2d");
new Chart(ctxPPC).Pie(data_price);

var data_categories = [
{
value: {{ cat_amuse_gueule }},
color:"#33CC33",
highlight: "#70DB70",
label: "Amuse-gueule"
},
{
value: {{ cat_confiserie }},
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Confiserie"
},
{
value: {{ cat_accompagnement }},
color:"#F7464A",
highlight: "#FF5A5E",
label: "Accompagnement"
},
{
value: {{ cat_conseil }},
color:"#F7464A",
highlight: "#FF5A5E",
label: "Conseil"
},
{
value: {{ cat_dessert }},
color:"#99CC00",
highlight: "#A3D119",
label: "Dessert"
},
{
value: {{ cat_entree }},
color:"#007A7A",
highlight: "#008A8A",
label: "Entrée"
},
{
value: {{ cat_sauce }},
color:"#9900FF",
highlight: "#A319FF",
label: "Sauce"
},
{
value: {{ cat_boisson }},
color:"#3333FF",
highlight: "#4747FF",
label: "Boisson"
},
{
value: {{ cat_plat_principal }},
color:"#FF3300",
highlight: "#FF4719",
label: "Plat principal"
}
];
var ctxPPC = $("#mealTypesPieChart").get(0).getContext("2d");
new Chart(ctxPPC).Pie(data_categories);
</script>
{% endblock %}
6 changes: 5 additions & 1 deletion testing/templates/recipe_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<th>Url:</th>
<td><a href="{{ recipe.origin_url }}">{{ recipe.origin_url }}</a></td>
</tr>
<tr>
<th>Category:</th>
<td>{{ recipe.category }}</td>
</tr>
<tr>
<th>Prep time:</th>
<td>{{ recipe.prep_time }} minutes</td>
Expand Down Expand Up @@ -98,7 +102,7 @@
</div>

<div class="row col-md-4 pull-right">
<img alt="" src="{{ recipe.picture }}"/>
<p><img class="img-thumbnail" alt="" src="{{ recipe.picture }}"/></p>
</div>

</div>
Expand Down
1 change: 1 addition & 0 deletions testing/templates/recipes.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</div>
</nav>


<div class="row">
<table class="table table-striped tab-pane active" id="infos">
<tbody>
Expand Down
1 change: 1 addition & 0 deletions testing/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'testing.views',
url(r'^testing$', 'index'),
url(r'^testing/recipes$', 'recipes'),
url(r'^testing/dashboard$', 'dashboard'),
url(r'^testing/recipe_details/([0-9]+)$', 'recipe_details', name='recipe_details'),
url(r'^testing/recipe_details_marmiton$', 'recipe_details_marmiton', name='recipe_details_marmiton'),
)
34 changes: 31 additions & 3 deletions testing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,43 @@

import testing.recipe_engine.scraper
from testing.recipe_engine.db_link import get_matching_ingredients, save_recipe
from menus.models import Recipe, RecipeToIngredient
from menus.models import Recipe, RecipeToIngredient, Ingredient, Nutriment
from testing.recipe_engine.main import retrieve_recipes

def index(request):
return render(request, 'index.html', {})

def dashboard(request):
return render(request, 'dashboard.html', {
'nb_recipes': Recipe.objects.count(),
'nb_ingreds': Ingredient.objects.count(),
'nb_nut': Nutriment.objects.count(),
'nb_very_easy': Recipe.objects.filter(difficulty=0).count(),
'nb_easy': Recipe.objects.filter(difficulty=1).count(),
'nb_medium': Recipe.objects.filter(difficulty=2).count(),
'nb_difficult': Recipe.objects.filter(difficulty=3).count(),
'amount_1': Recipe.objects.filter(amount=1).count(),
'amount_2': Recipe.objects.filter(amount=2).count(),
'amount_3': Recipe.objects.filter(amount=3).count(),
'amount_4': Recipe.objects.filter(amount=4).count(),
'amount_many': Recipe.objects.filter(amount__gte=5).count(),
'price_0': Recipe.objects.filter(price=0).count(),
'price_1': Recipe.objects.filter(price=1).count(),
'price_2': Recipe.objects.filter(price=2).count(),
'cat_amuse_gueule': Recipe.objects.filter(category='Amuse-gueule').count(),
'cat_confiserie': Recipe.objects.filter(category='Confiserie').count(),
'cat_conseil': Recipe.objects.filter(category='Conseil').count(),
'cat_accompagnement': Recipe.objects.filter(category='Accompagnement').count(),
'cat_dessert': Recipe.objects.filter(category='Dessert').count(),
'cat_entree': Recipe.objects.filter(category='Entrée').count(),
'cat_sauce': Recipe.objects.filter(category='Sauce').count(),
'cat_boisson': Recipe.objects.filter(category='Boisson').count(),
'cat_plat_principal': Recipe.objects.filter(category='Plat principal').count(),
})

def recipes(request):
#retrieve_recipes()
recipes = Recipe.objects.all()
# todo: show all recipe and paginate
recipes = Recipe.objects.all()[:50]
return render(request, 'recipes.html', {
'recipes': recipes
})
Expand Down

0 comments on commit f7bb330

Please sign in to comment.