Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
814c5b17e3 | |||
e66e54c424 | |||
0ad4c9e398 | |||
ce86d35b25 | |||
19552bf774 | |||
b74f136f81 | |||
b52dbaec57 | |||
2769d0a33a | |||
5ac1a9f5a9 | |||
ab3378ec4d |
27
src/Run.py
27
src/Run.py
@ -6,7 +6,7 @@ import os
|
|||||||
import json
|
import json
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import logging
|
import logging
|
||||||
from math import ceil
|
from math import ceil, floor
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.update({
|
app.config.update({
|
||||||
@ -38,12 +38,12 @@ def calculate_nutrition(food, weight):
|
|||||||
# Runden und Berechnen der Nährwerte basierend auf dem Gewicht
|
# Runden und Berechnen der Nährwerte basierend auf dem Gewicht
|
||||||
kcal, ew, fett, kh, bst, ca = result
|
kcal, ew, fett, kh, bst, ca = result
|
||||||
nutrition_values = [
|
nutrition_values = [
|
||||||
round(kcal * weight / 100), # kcal gerundet auf ganze Zahl
|
schulrunden(kcal * weight / 100), # kcal gerundet auf ganze Zahl
|
||||||
round(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle
|
schulrunden(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle
|
||||||
round(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle
|
schulrunden(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle
|
||||||
round(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle
|
schulrunden(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle
|
||||||
round(bst * weight / 100, 1), # BST gerundet auf eine Dezimalstelle
|
schulrunden(bst * weight / 100, 1), # BST gerundet auf eine Dezimalstelle
|
||||||
round(ca * weight / 100) # CA gerundet auf ganze Zahl
|
schulrunden(ca * weight / 100) # CA gerundet auf ganze Zahl
|
||||||
]
|
]
|
||||||
return nutrition_values
|
return nutrition_values
|
||||||
else:
|
else:
|
||||||
@ -54,6 +54,19 @@ def calculate_nutrition(food, weight):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def schulrunden(zahl, stellen=0):
|
||||||
|
faktor = 10 ** stellen
|
||||||
|
zahl = zahl * faktor
|
||||||
|
basis = floor(zahl)
|
||||||
|
if zahl - basis >= 0.5:
|
||||||
|
gerundet = basis + 1
|
||||||
|
else:
|
||||||
|
gerundet = basis
|
||||||
|
return gerundet / faktor
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Index-Route
|
# Index-Route
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@oidc.require_login
|
@oidc.require_login
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
cleanUpLocalStorage();
|
cleanUpLocalStorage();
|
||||||
|
restorePortions()
|
||||||
restoreTableFromLocalStorage();
|
restoreTableFromLocalStorage();
|
||||||
|
|
||||||
updateTotalNutrition();
|
updateTotalNutrition();
|
||||||
fetch('/get_products')
|
fetch('/get_products')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
@ -32,6 +34,22 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById('portions').addEventListener('input', function() {
|
||||||
|
const portions = this.value;
|
||||||
|
localStorage.setItem('savedPortions', portions); // Speichern der Portionen im localStorage
|
||||||
|
recalculateTableBasedOnPortions(); // Bestehende Funktion, um die Tabelle zu aktualisieren
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function restorePortions() {
|
||||||
|
const savedPortions = localStorage.getItem('savedPortions');
|
||||||
|
if (savedPortions) {
|
||||||
|
document.getElementById('portions').value = savedPortions;
|
||||||
|
recalculateTableBasedOnPortions(); // Falls notwendig, um die Tabelle direkt zu aktualisieren
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function recalculateTableBasedOnPortions() {
|
function recalculateTableBasedOnPortions() {
|
||||||
const portions = parseInt(document.getElementById('portions').value, 10) || 1;
|
const portions = parseInt(document.getElementById('portions').value, 10) || 1;
|
||||||
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
|
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
|
||||||
|
@ -137,13 +137,13 @@
|
|||||||
tableBody.innerHTML = '';
|
tableBody.innerHTML = '';
|
||||||
data.forEach(entry => {
|
data.forEach(entry => {
|
||||||
const row = tableBody.insertRow();
|
const row = tableBody.insertRow();
|
||||||
row.insertCell(0).innerText = entry.food;
|
row.insertCell(0).innerHTML = entry.food;
|
||||||
row.insertCell(1).innerText = entry.kcal;
|
row.insertCell(1).innerHTML = entry.kcal;
|
||||||
row.insertCell(2).innerText = entry.ew;
|
row.insertCell(2).innerHTML = entry.ew;
|
||||||
row.insertCell(3).innerText = entry.fett;
|
row.insertCell(3).innerHTML = entry.fett;
|
||||||
row.insertCell(4).innerText = entry.kh;
|
row.insertCell(4).innerHTML = entry.kh;
|
||||||
row.insertCell(5).innerText = entry.bst;
|
row.insertCell(5).innerHTML = entry.bst;
|
||||||
row.insertCell(6).innerText = entry.ca;
|
row.insertCell(6).innerHTML = entry.ca;
|
||||||
|
|
||||||
// ... Fügen Sie weitere Zellen für die anderen Werte hinzu ...
|
// ... Fügen Sie weitere Zellen für die anderen Werte hinzu ...
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user