diff --git a/Run.py b/Run.py deleted file mode 100644 index 752b1da..0000000 --- a/Run.py +++ /dev/null @@ -1,158 +0,0 @@ -from flask import Flask, request, render_template, jsonify, redirect, url_for -import psycopg2 -import sqlite3 - -app = Flask(__name__) - -# Datenbankverbindung konfigurieren -def get_db_connection(): - conn = sqlite3.connect('nutrition.db') # 'nutrition.db' ist der Name der Datenbankdatei - conn.row_factory = sqlite3.Row # Ermöglicht den Zugriff auf Daten durch Spaltennamen - return conn - - -def init_db(): - conn = get_db_connection() - cursor = conn.cursor() - - # Erstellen der Tabelle - cursor.execute(''' - CREATE TABLE IF NOT EXISTS nutrition_table ( - id INTEGER PRIMARY KEY, - name TEXT NOT NULL, - kcal REAL, - EW REAL, - Fett REAL, - KH REAL, - BST REAL, - CA REAL - ) - ''') - - # Testdaten einfügen - test_data = [ - ('Apfel', 52, 0.3, 0.2, 14, 0.2, 6), - ('Banane', 89, 1.1, 0.3, 23, 0.3, 5), - ('Karotte', 41, 0.9, 0.2, 10, 0.2, 3), - ('Tomate', 18, 0.9, 0.2, 3.9, 0.2, 4), - ('Brokkoli', 34, 2.8, 0.4, 6.6, 0.4, 2), - ('Spinat', 23, 2.9, 0.4, 3.6, 0.4, 99), - ('Kartoffel', 77, 2, 0.1, 17, 0.1, 12), - ('Huhn', 239, 27, 14, 0, 0, 2), - ('Lachs', 208, 20, 13, 0, 0, 1), - ('Ei', 155, 13, 11, 1.1, 1, 1) - ] - - cursor.executemany('INSERT INTO nutrition_table (name, kcal, EW, Fett, KH, BST, CA) VALUES (?, ?, ?, ?, ?, ?, ?)', test_data) - - conn.commit() - conn.close() - - - -def calculate_nutrition(food, weight): - conn = get_db_connection() - cursor = conn.cursor() - - # Abfrage der Nährwertdaten aus der Datenbank - cursor.execute('SELECT kcal, EW, Fett, KH, BST, CA FROM nutrition_table WHERE name = ?', (food,)) - - result = cursor.fetchone() - conn.close() - - if result: - # Runden und Berechnen der Nährwerte basierend auf dem Gewicht - kcal, ew, fett, kh, bst, ca = result - nutrition_values = [ - round(kcal * weight / 100), # kcal gerundet auf ganze Zahl - round(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle - round(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle - round(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle - round(bst * weight / 100, 1), # BST gerundet auf eine Dezimalstelle - round(ca * weight / 100) # CA gerundet auf ganze Zahl - ] - return nutrition_values - else: - return None - - -# Index-Route -@app.route('/') -def index(): - return render_template('index.html') - -# ... - -@app.route('/get_products') -def get_products(): - conn = get_db_connection() - cursor = conn.cursor() - cursor.execute('SELECT name FROM nutrition_table') - products = cursor.fetchall() - conn.close() - print("ter") - return {'products': [product[0] for product in products]} - -# ... - - - - -# Route zum Hinzufügen und Berechnen von Lebensmitteln -@app.route('/add_lm', methods=['GET']) -def add_lm(): - food = request.args.get('food') - weight = float(request.args.get('weight')) - - nutrition = calculate_nutrition(food, weight) - if nutrition: - # Extrahieren der einzelnen Nährwerte - kcal, ew, fett, kh, bst, ca = nutrition - return jsonify({ - "food": food, - "kcal": kcal, - "ew": ew, - "fett": fett, - "kh": kh, - "bst": bst, - "ca": ca - }) - else: - return "Lebensmittel nicht gefunden.", 404 - - - -@app.route('/add_nutrition', methods=['POST']) -def add_nutrition(): - food = request.form.get('food') - kcal = float(request.form.get('kcal')) - ew = float(request.form.get('ew')) - fett = float(request.form.get('fett')) - kh = float(request.form.get('kh')) - bst = float(request.form.get('bst')) - ca = float(request.form.get('ca')) - - print("test") - # Verbindung zur Datenbank herstellen und Daten einfügen - conn = get_db_connection() - cursor = conn.cursor() - cursor.execute("INSERT INTO nutrition_table (name, kcal, ew, fett, kh, bst, ca) VALUES (?, ?, ?, ?, ?, ?, ?)", - (food, kcal, ew, fett, kh, bst, ca)) - conn.commit() - conn.close() - - return redirect(url_for('nutrition')) - - -@app.route('/nutrition') -def nutrition(): - return render_template('nutrition.html') - - - - -if __name__ == '__main__': - #init_db() - app.run(debug=True) - - diff --git a/db.py b/db.py deleted file mode 100644 index b52c315..0000000 --- a/db.py +++ /dev/null @@ -1,36 +0,0 @@ -import csv -import sqlite3 - -# Pfad zur Ihrer CSV-Datei -csv_file_path = 'nu.csv' - -# Pfad zur Ihrer SQLite-Datenbank -sqlite_db_path = 'nutrition.db' - -# Verbindung zur SQLite-Datenbank herstellen -conn = sqlite3.connect(sqlite_db_path) -cursor = conn.cursor() - -# Erstellen der Tabelle (falls noch nicht vorhanden) -cursor.execute(''' - CREATE TABLE IF NOT EXISTS nutrition_table ( - name TEXT, - kcal REAL, - EW REAL, - Fett REAL, - KH REAL, - BST REAL, - Ca REAL - ) -''') - -# Öffnen der CSV-Datei und Einfügen der Daten in die Datenbank -with open(csv_file_path, newline='', encoding='utf-8') as csvfile: - reader = csv.reader(csvfile) - next(reader, None) # Überspringen der Kopfzeile - for row in reader: - cursor.execute('INSERT INTO nutrition_table (name, kcal, EW, Fett, KH, BST, Ca) VALUES (?, ?, ?, ?, ?, ?, ?)', row) - -# Änderungen speichern und Verbindung schließen -conn.commit() -conn.close() diff --git a/nu.csv b/nu.csv deleted file mode 100644 index 69a2e3d..0000000 --- a/nu.csv +++ /dev/null @@ -1,86 +0,0 @@ -name,kcal,EW,Fett,KH,BST,Ca -Zitronensaft,38,0.4,0.5,3.8,0.1,11 -Zucker,405,0.0,0.0,100.0,0.0,2 -Trinkmilch3.5,65,3.4,3.6,4.7,0.0,120 -Hühnerei50,137,11.9,9.3,1.5,0.0,51 -Pflanzenmargarine,722,0.2,80.0,0.4,0.0,8 -Sahne30,309,2.4,31.7,3.4,0.0,80 -Maisstärke,353,0.4,0.1,85.9,1.0,0 -Paniermehl,368,10.1,2.1,73.5,5.3,50 -Weizengrieß,335,9.6,0.8,69.0,7.1,17 -Mehl405,343,9.8,1.0,71.8,4.0,15 -Rapsöl,884,0,100.0,0,0,0 -Kartoffeln,76,1.9,0.1,15.6,1.2,6 -Butter,754,0.7,83.2,0.7,0,13 -Zwiebeln,30,1.2,0.3,4.9,1.4,31 -Kartoffelstärke,341,0.6,0.1,83.1,0.1,35 -Olivenöl,884,0,99.8,0.2,0,0 -Möhre,39,0.8,0.2,6.8,3.6,21 -Rote linsen,350,23.9,2.2,52.3,10.8,48 -Gemüsebruhe verz,7,1.6,0,1,0,12 -Rindfleisch keule,148,20.0,7.6,0,0,6 -Rinderbouillon,4,0.2,0,1,0,5 -Meerettich iD,78,2.8,0.3,11.7,7.5,105 -Saure sahne10,117,3.1,10.0,3.7,0,110 -Joghurt3.5, 64,3.3,3.5,4.4,0,120 -Dill,65,3.7,0.8,8.0,5.3,230 -Schnittlauch,40,3.6,0.7,1.6,6.0,129 -Gartenkresse,41,4.2,0.7,2.5,3.5,214 -Petersilie,60,4.4,0.4,7.4,4.3,179 -Mandelstifte,610,18.7,54.1,5.4,13.5,252 -Porree,29,2.2,0.3,3.3,2.3,63 -Champignons,20,2.7,0.3,0.6,2.0,10 -Sellerie,27,1.6,0.3,2.3,4.2,50 -Apfelsine,47,1.0,0.2,8.3,2.2,42 -Birne,58,0.5,0.3,12.4,2.8,9 -Apfel,57,0.3,0.6,11.4,2.0,7 -Kiwi grün,55,0.9,0.6,9.1,3.0,28 -Banane,93,1.2,0.2,20.0,1.8,8 -Schweinefleisch bug,217,17.0,16.5,0.0,0.0,9 -Gouda48,370,22.7,29.9,0,0,811 -Blumenkohl,28,2.5,0.3,2.3,2.9,22 -Knoblauch,145,6.1,0.1,28.4,1.8,38 -Senf,88,6.0,4.0,6.0,1.0,124 -Blattspinat roh,21,2.7,0.3,0.6,2.6,117 -Buttermilch,37,3.5,0.5,4.0,0.0,109 -Himbeere,37,1.3,0.3,4.8,4.7,40 -Salz dill gurken,9,0.4,0.1,1.3,0.5,18 -Schmand20,205,2.8,20.0,3.6,0.0,100 -Aspikpulver,338,84.2,0.1,0.0,0.0,11 -Lachs atlantischer,210,20.4,13.4,0.3,0.0,4 -Pinienkerne,589,24.0,50.7,7.3,7.2,26 -Zwieback,385,9.9,4.3,73.1,5.2,42 -Speisequark,72,13.5,0.3,3.2,0.0,92 -Basilikum,47,3.1,0.8,5.1,3.1,369 -Mayonaise50,490,0.5,52.0,5.0,0.0,10 -Weizenbrötchen,292,10.2,1.8,55.9,3.6,49 -Seelachs köhler,81,18.3,0.9,0,0,14 -Bohnen grün,21,1.7,0.1,2.0,2.3,34 -Aprikosen dose,70,0.5,0.1,15.1,1.4,11 -Orangenfilets,47,1.0,0.2,8.3,2.2,42 -Mirabellen dose,66,0.7,0.2,15.0,0.9,12 -Pfirsich dose,67,0.4,0.1,15.5,1.1,4 -Vanillezucker,405,0.0,0.0,100.0,0,2 -Vanille pp,346,0.5,0.0,86.0,1,15 -Brokkoli,34,3.8,0.2,2.7,3.0,58 -Cornichons,15,1,0.1,2.0,0.8,0 -Kopfsalat,14,1.2,0.2,1.1,1.4,20 -Rosenkohl,43,4.5,0.3,3.3,4.4,31 -Rotkohl,27,1.5,0.2,3.5,2.5,35 -Spinat,19,2.3,0.3,0.5,2.3,120 -Tomate,18,1.0,0.2,2.6,1.0,9 -Tomatenmark,177,9.7,2.0,25.1,1.6,106 -Wirsing,30,3.0,0.4,2.9,2.5,64 -Zucchini,23,2.0,0.3,2.3,1.1,25 -Mais Dose,81,3.2,1.2,12.6,2.8,8 -Pfefferminze,50,3.8,0.7,5.3,3.0,179 -Erdbeere,36,0.8,0.4,5.5,2.0,24 -Himbeere,37,1.3,0.3,4.8,4.7,40 -Orange/apfelsine,47,1.0,0.2,8.3,2.2,42 -Orangensaft frisch,44,0.7,0.1,8.7,0.4,11 -Weintraube,69,0.7,0.3,15.2,1.5,12 -Naturreis,349,7.2,2.2,74.1,2.2,16 -Mehl405,343,9.8,1.0,71.8,4.0,15 -Mehl550,346,9.8,1.1,72.0,4.3,17 -Milchreis,316,6.4,0.8,80.2,1.1,6 -Kartoffelstärke,341,0.6,0.1,83.1,0.1,35 \ No newline at end of file diff --git a/nutrition.db b/nutrition.db deleted file mode 100644 index 2384afc..0000000 Binary files a/nutrition.db and /dev/null differ diff --git a/static/style.css b/static/style.css deleted file mode 100644 index 3f4a3f8..0000000 --- a/static/style.css +++ /dev/null @@ -1,123 +0,0 @@ -body { - font-family: Arial, sans-serif; - background-color: #f4f4f4; - margin: 0; - padding: 20px; -} - -form { - margin-bottom: 20px; -} - -input, button { - padding: 10px; - margin: 5px; - border: 1px solid #ddd; - border-radius: 4px; -} - -button { - cursor: pointer; - background-color: #008C50; /* Helles Blau */ - color: white; - border: none; -} - -button:disabled { - background-color: #cccccc; - color: #666666; - cursor: not-allowed; -} - -button:not(:disabled):hover { - background-color: #007344; /* Dunkleres Blau */ -} - -button#remove-button { - background-color: #f443366f; /* Helles Rot */ -} - -button#remove-button:not(:disabled):hover { - background-color: #d32f2f3d; /* Dunkleres Rot */ -} - -table { - width: 100%; - border-collapse: collapse; -} - -table, th, td { - border: 1px solid #ddd; -} - -th, td { - text-align: left; - padding: 8px; -} - -th { - background-color: #4CAF50; /* Grün */ - color: white; -} - -tr:nth-child(even) { - background-color: #f2f2f2; -} - -.selected, tr.selected { - background-color: #ffdd99; /* Hervorhebung der Auswahl */ -} - -tr:hover:not(.selected) { - background-color: #ddd; /* Hover-Effekt für nicht ausgewählte Zeilen */ -} - -#navbar { - background-color: #01351d; /* Sehr dunkles Grün */ - color: white; - padding: 10px 20px; - display: flex; - align-items: center; - justify-content: space-between; - border-radius: 10px; -} - -#navbar h1 { - margin: 0; - font-size: 24px; -} - -#navbar ul { - list-style: none; - display: flex; - margin: 0; - padding: 0; -} - -#navbar ul li { - margin-left: 20px; -} - -#navbar a { - color: white; - text-decoration: none; - padding: 8px 15px; - border-radius: 4px; - transition: background-color 0.3s; -} - -#navbar a:hover { - background-color: #007344; /* Etwas helleres Grün */ -} - -#navbar a.active { - background-color: #008C50; /* Mittleres Grün */ -} - - -.content { - background-color: #ebf2eb; /* Helles Grau */ - border-radius: 10px; - padding: 20px; - margin: 20px 0; -} diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 5d9d04a..0000000 --- a/templates/index.html +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Nährwertberechnungs-App - - - - - - - - -
-
- - - - - - - -
- - - - - - - - - - - - - -
LebensmittelGewicht (g)kcalEWFettKHBSTCA
- - - - - - - - - - - - - - - - - - -
kcalEWFettKHBSTCA
000000
-
- - \ No newline at end of file diff --git a/templates/nutrition.html b/templates/nutrition.html deleted file mode 100644 index a9a2848..0000000 --- a/templates/nutrition.html +++ /dev/null @@ -1,78 +0,0 @@ - - - - - Neue Lebensmittel hinzufügen - - - - - - -
-
- - - - - - - - - - - - - - - - - - - -
LebensmittelkcalEWFettKHBSTCA
- -
-
- -