-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Guillaume Hélouis
committed
Jul 1, 2015
1 parent
ac4438d
commit 05a8d4f
Showing
9 changed files
with
1,609 additions
and
12 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__author__ = 'kevin' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__author__ = 'kevin' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.core.management.base import BaseCommand | ||
from testing.models import Ingredient, Nutriment | ||
import time | ||
|
||
class Command(BaseCommand): | ||
""" | ||
Fill database with ingredients from the Ciqual ANSES table | ||
""" | ||
help = '' | ||
|
||
def handle(self, *args, **options): | ||
csv = "testing/CIQUAL2013-Donneescsv.csv" | ||
print("Parsing %s and filling the database..." % csv) | ||
start_time = time.time() | ||
|
||
separator = ";" | ||
with open(csv, 'r', encoding="ISO-8859-1") as f: | ||
|
||
# Nutriments | ||
fields = f.readline().rstrip("\n").split(separator) | ||
for i in range(4, 60): | ||
name = fields[i] if fields[i] and fields[i] != "-" else None | ||
if name: | ||
name = name.split(" ")[1:-1] # remove leading number and trailing unit | ||
nutriment = Nutriment(name=name) | ||
nutriment.save() | ||
|
||
for n, line in enumerate(f.readlines()): | ||
print("%s ingredients processed" % n, end='\r') | ||
fields = line.rstrip("\n").split(separator) | ||
|
||
# Ingredients | ||
name = fields[3] if fields[3] and fields[3] != "-" else None | ||
category = fields[1] if fields[1] and fields[1] != "-" else None | ||
ingredient = Ingredient(name=name, category=category) | ||
ingredient.save() | ||
|
||
print('Done in %s seconds.' % (time.time() - start_time)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
from django.db import models | ||
|
||
class Ingredient(models.Model): | ||
name = models.CharField(max_length=256) | ||
category = models.CharField(max_length=512) | ||
nutriments = models.ManyToManyField('Nutriment') | ||
|
||
class Nutriment(models.Model): | ||
name = models.CharField(max_length=256) | ||
|
||
class Comment(models.Model): | ||
url = models.URLField() | ||
text = models.TextField() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters