37 Commits
0.0.4 ... 0.2.0

Author SHA1 Message Date
f39c902ace fail
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-30 19:15:48 +01:00
ff26644f06 fail
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 18:51:52 +01:00
5f63092a67 f
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 18:51:02 +01:00
1fc9dd70df Merge branch 'main' of gitea.hottis.de:moerp/Elo-rezept-rechner
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 18:48:08 +01:00
794b50e041 token 2024-01-30 18:47:57 +01:00
5583bc2b60 color 2024-01-30 18:44:45 +01:00
5f34449601 token
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-30 18:26:27 +01:00
8bc3857482 Merge branch 'main' of gitea.hottis.de:moerp/elo-rezept-rechner
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 18:19:14 +01:00
5c7fe128c8 token 2024-01-30 18:19:05 +01:00
3a17338358 Merge branch 'main' of gitea.hottis.de:moerp/Elo-rezept-rechner
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 18:08:15 +01:00
4761910092 changes 2024-01-30 18:07:16 +01:00
2c499b363b Merge branch 'main' of gitea.hottis.de:moerp/elo-rezept-rechner
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 17:03:14 +01:00
39e2f2634d small
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-30 17:03:00 +01:00
ffa6944e7b fix auth for add_nut... 2024-01-30 17:02:58 +01:00
449dba1d7e Merge branch 'main' of gitea.hottis.de:moerp/elo-rezept-rechner
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 16:56:03 +01:00
b6d1367019 test 2024-01-30 16:55:44 +01:00
2ff8757b74 style 2024-01-30 16:50:15 +01:00
7f06e900bb test 2024-01-30 16:27:16 +01:00
4c2338c34a test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-30 16:24:45 +01:00
5f8d49f054 test 2024-01-30 16:19:08 +01:00
5cfba1c068 favicon
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 15:52:49 +01:00
09a670727f favicon
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-30 15:50:39 +01:00
f4a4597223 start pipeline, 2 2024-01-30 15:49:37 +01:00
70815f0172 start pipeline 2024-01-30 15:49:06 +01:00
e4e8e19466 small cahnges
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
2024-01-30 15:33:54 +01:00
2228f0cfb5 db fix 2024-01-30 15:29:46 +01:00
24fb1c2941 libpq, 3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 15:00:51 +01:00
cc3a6381d5 libpq 2024-01-30 14:59:46 +01:00
938562b9d8 requirements, 3
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-01-30 14:53:47 +01:00
103d60764b requirements, 2 2024-01-30 14:53:06 +01:00
8a446b8a8d requirements 2024-01-30 14:52:32 +01:00
5948cf3840 postgres, fix 3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 14:48:31 +01:00
63dbfcc89f postgres, fix 2 2024-01-30 14:47:36 +01:00
439f6085e7 postgres 2024-01-30 14:47:07 +01:00
21479212f8 fix 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 14:18:52 +01:00
5d8997d45e fix 2024-01-30 14:16:59 +01:00
6e6effb1bc fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-30 14:07:42 +01:00
9 changed files with 167 additions and 141 deletions

View File

@ -7,7 +7,9 @@ COPY start.sh ${APP_DIR}/
WORKDIR ${APP_DIR}
RUN pip install -r requirements.txt
RUN \
apk add --no-cache build-base libpq-dev && \
pip install -r requirements.txt
EXPOSE 8080

View File

@ -4,6 +4,7 @@ from flask_oidc import OpenIDConnect
from werkzeug.middleware.proxy_fix import ProxyFix
import os
import json
import psycopg2
app = Flask(__name__)
app.config.update({
@ -19,82 +20,40 @@ app.config.update({
oidc = OpenIDConnect(app)
# 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()
try:
conn = psycopg2.connect()
# Abfrage der Nährwertdaten aus der Datenbank
cursor.execute('SELECT kcal, EW, Fett, KH, BST, CA FROM nutrition_table WHERE name = ?', (food,))
with conn.cursor() as cursor:
# Abfrage der Nährwertdaten aus der Datenbank
cursor.execute('SELECT kcal, EW, Fett, KH, BST, CA FROM nutrition_table WHERE name = %s', (food,))
result = cursor.fetchone()
conn.close()
result = cursor.fetchone()
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
finally:
if conn:
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('/')
@oidc.require_login
@oidc.require_keycloak_role('user')
def index():
return render_template('index.html')
@ -102,24 +61,21 @@ def index():
@app.route('/get_products')
@oidc.require_login
@oidc.require_keycloak_role('user')
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]}
try:
conn = psycopg2.connect()
with conn.cursor() as cursor:
cursor.execute('SELECT name FROM nutrition_table')
products = cursor.fetchall()
return {'products': [product[0] for product in products]}
finally:
if conn:
conn.close()
# Route zum Hinzufügen und Berechnen von Lebensmitteln
@app.route('/add_lm', methods=['GET'])
@oidc.require_login
@oidc.require_keycloak_role('user')
def add_lm():
food = request.args.get('food')
weight = float(request.args.get('weight'))
@ -141,36 +97,49 @@ def add_lm():
return "Lebensmittel nicht gefunden.", 404
def convert_decimal(value):
try:
return float(value.replace(',', '.'))
except (ValueError, TypeError):
return 0.0 # Rückgabe eines Standardwertes im Fehlerfall
@app.route('/add_nutrition', methods=['POST'])
@oidc.accept_token(require_token=True, scopes_required=['openid'])
@oidc.accept_token(True)
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'))
kcal = convert_decimal(request.form.get('kcal'))
ew = convert_decimal(request.form.get('ew'))
fett = convert_decimal(request.form.get('fett'))
kh = convert_decimal(request.form.get('kh'))
bst = convert_decimal(request.form.get('bst'))
ca = convert_decimal(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()
try:
conn = psycopg2.connect()
with conn.cursor() as cursor:
cursor.execute("INSERT INTO nutrition_table (name, kcal, ew, fett, kh, bst, ca) VALUES (%s, %s, %s, %s, %s, %s, %s)",
(food, kcal, ew, fett, kh, bst, ca))
return redirect(url_for('nutrition'))
return redirect(url_for('nutrition'))
finally:
if conn:
conn.close()
@app.route('/nutrition')
@oidc.require_login
@oidc.require_keycloak_role('user')
def nutrition():
return render_template('nutrition.html')
@app.route('/get_token')
@oidc.require_login
def get_token():
return jsonify(token=oidc.get_access_token())
app = ProxyFix(app, x_for=1, x_host=1)

View File

@ -1,14 +1,13 @@
import csv
import sqlite3
import psycopg2
# 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)
conn = psycopg2.connect()
cursor = conn.cursor()
# Erstellen der Tabelle (falls noch nicht vorhanden)
@ -29,8 +28,9 @@ 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)
cursor.execute('INSERT INTO nutrition_table (name, kcal, EW, Fett, KH, BST, Ca) VALUES (%s, %s, %s, %s, %s, %s, %s)', row)
# Änderungen speichern und Verbindung schließen
conn.commit()
conn.close()

View File

@ -13,6 +13,8 @@ itsdangerous==2.1.2
Jinja2==3.1.3
MarkupSafe==2.1.4
packaging==23.2
psycopg==3.1.17
psycopg2==2.9.9
pycparser==2.21
requests==2.31.0
typing_extensions==4.9.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -34,13 +34,20 @@ button:not(:disabled):hover {
}
button#remove-button {
background-color: #f443366f; /* Helles Rot */
background-color: #640000; /* Helles Rot */
}
button#remove-button:disabled {
background-color: #cccccc;
color: #666666;
}
button#remove-button:not(:disabled):hover {
background-color: #d32f2f3d; /* Dunkleres Rot */
background-color: #490000; /* Dunkleres Rot */
}
table {
width: 100%;
border-collapse: collapse;
@ -65,7 +72,7 @@ tr:nth-child(even) {
}
.selected, tr.selected {
background-color: #ffdd99; /* Hervorhebung der Auswahl */
background-color: #e5b5b5; /* Hervorhebung der Auswahl */
}
tr:hover:not(.selected) {
@ -121,3 +128,27 @@ tr:hover:not(.selected) {
padding: 20px;
margin: 20px 0;
}
#nutrition-input-table {
width: 100%; /* Tabelle nimmt die volle Breite ein */
border-collapse: collapse; /* Entfernt doppelte Ränder */
}
#nutrition-input-table th, #nutrition-input-table td {
border: 1px solid #ddd; /* Fügt Ränder hinzu */
padding: 8px; /* Fügt Innenabstand hinzu */
text-align: left; /* Ausrichtung des Textes */
}
#nutrition-input-table input {
width: 100%; /* Eingabefelder nehmen die volle Breite der Zelle ein */
box-sizing: border-box; /* Box-Modell für die Breitenberechnung */
}
@media screen and (max-width: 600px) {
#nutrition-input-table {
display: block;
overflow-x: auto; /* Ermöglicht horizontales Scrollen auf kleinen Bildschirmen */
}
}

View File

@ -4,10 +4,9 @@
<meta charset="UTF-8">
<title>Nährwertberechnungs-App</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
<link rel="shortcut icon" href="../static/images/favicon.ico">
<script>
// JavaScript-Funktion, um die Produkte beim Laden der Seite zu holen
document.addEventListener('DOMContentLoaded', function() {
cleanUpLocalStorage();
restoreTableFromLocalStorage();
@ -155,12 +154,12 @@ function updateTotalNutrition() {
// Durchlaufen aller Zeilen in der Haupttabelle und Addition der Werte
Array.from(document.getElementById('nutrition-table').rows).slice(1).forEach(row => {
totalKcal += parseFloat(row.cells[2].innerText);
totalEw += parseFloat(row.cells[3].innerText);
totalFett += parseFloat(row.cells[4].innerText);
totalKh += parseFloat(row.cells[5].innerText);
totalBst += parseFloat(row.cells[6].innerText);
totalCa += parseFloat(row.cells[7].innerText);
totalKcal += parseFloat(row.cells[4].innerText);
totalEw += parseFloat(row.cells[4].innerText);
totalFett += parseFloat(row.cells[5].innerText);
totalKh += parseFloat(row.cells[6].innerText);
totalBst += parseFloat(row.cells[7].innerText);
totalCa += parseFloat(row.cells[8].innerText);
});
// Rundung und Aktualisierung der Gesamtwerte
@ -176,7 +175,7 @@ function updateTotalNutrition() {
</head>
<body>
<nav id="navbar">
<h1>Elos Rezept Rechner</h1>
<h1>Elo's Rezept Rechner</h1>
<ul>
<li><a href="/" class="active">Rechner</a></li>
<li><a href="/nutrition">Neue Lebensmittel</a></li>
@ -211,6 +210,8 @@ function updateTotalNutrition() {
<button id="remove-button" onclick="removeSelectedRow()" disabled>Entfernen</button>
<table id="total-nutrition-table">
<tr>
<th>Lebensmittel</th>
<th>Gewicht (g)</th>
<th>kcal</th>
<th>EW</th>
<th>Fett</th>
@ -219,6 +220,8 @@ function updateTotalNutrition() {
<th>CA</th>
</tr>
<tr>
<td>Gesamtwerte</td>
<td>-</td>
<td id="total-kcal">0</td>
<td id="total-ew">0</td>
<td id="total-fett">0</td>

View File

@ -4,6 +4,8 @@
<meta charset="UTF-8">
<title>Neue Lebensmittel hinzufügen</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
<link rel="shortcut icon" href="../static/images/favicon.ico">
<script>
function updateSubmitButtonState() {
const inputs = document.querySelectorAll('#nutrition-form input');
@ -11,38 +13,53 @@
document.getElementById('submit-button').disabled = !allFilled;
}
function getBearerToken(callback) {
fetch('/get_token')
.then(response => response.json())
.then(data => {
callback(data.token);
})
.catch(error => {
console.error('Fehler beim Abrufen des Tokens:', error);
});
}
function addNutritionEntry() {
getBearerToken(token => {
const form = document.getElementById('nutrition-form');
const formData = new FormData(form);
const form = document.getElementById('nutrition-form');
const formData = new FormData(form);
fetch('/add_nutrition', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + token
},
body: formData
}).then(response => {
// Behandlung der Serverantwort
// Beispielsweise das Formular zurücksetzen
form.reset();
updateSubmitButtonState();
}).catch(error => {
console.error('Fehler:', error);
});
// ... Code, um den Eintrag zur Datenbank hinzuzufügen
fetch('/add_nutrition', {
method: 'POST',
body: formData
}).then(response => {
// Behandlung der Serverantwort
// Beispielsweise das Formular zurücksetzen
form.reset();
updateSubmitButtonState();
}).catch(error => {
console.error('Fehler:', error);
});
// ... Code, um den Eintrag zur Datenbank hinzuzufügen
// Nach dem Hinzufügen, setze alle Eingabefelder zurück
document.querySelectorAll('#nutrition-form input').forEach(input => {
input.value = ''; // Setzt den Wert jedes Eingabefeldes zurück
});
// Nach dem Hinzufügen, setze alle Eingabefelder zurück
document.querySelectorAll('#nutrition-form input').forEach(input => {
input.value = ''; // Setzt den Wert jedes Eingabefeldes zurück
});
// Deaktiviere den "Hinzufügen"-Button wieder
document.getElementById('submit-button').disabled = true;
}
// Deaktiviere den "Hinzufügen"-Button wieder
document.getElementById('submit-button').disabled = true;
});
}
</script>
</head>
<body>
<nav id="navbar">
<h1>Elos Rezept Rechner</h1>
<h1>Elo's Rezept Rechner</h1>
<ul>
<li><a href="/">Rechner</a></li>
<li><a href="/nutrition" class="active">Neue Lebensmittel</a></li>
@ -62,13 +79,13 @@
<th>CA</th>
</tr>
<tr>
<td><input type="text" name="food" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="kcal" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="ew" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="fett" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="kh" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="bst" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="ca" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
<td><input type="text" name="food" placeholder="Lebensmittel" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="kcal" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="ew" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="fett" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="kh" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="bst" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="ca" pattern="\d+([.,]\d{1,2})?" placeholder="mg" oninput="updateSubmitButtonState()"></td>
</tr>
</table>
<button type="submit" id="submit-button" disabled>Hinzufügen</button>

View File

@ -2,3 +2,5 @@
gunicorn 'Run:app' --bind 0.0.0.0:8080 --log-level=info --workers=4