Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
727e2f60c4 | |||
a411f59e00 | |||
be531a7ccf | |||
6e94925fda |
@ -38,7 +38,7 @@ 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 = [
|
||||||
schulrunden(kcal * weight / 100), # kcal gerundet auf ganze Zahl
|
schulrunden(kcal * weight / 100, ist_kcal=True), # kcal gerundet auf ganze Zahl
|
||||||
schulrunden(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle
|
schulrunden(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle
|
||||||
schulrunden(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle
|
schulrunden(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle
|
||||||
schulrunden(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle
|
schulrunden(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle
|
||||||
@ -55,7 +55,11 @@ def calculate_nutrition(food, weight):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def schulrunden(zahl, stellen=0):
|
def schulrunden(zahl, stellen=0, ist_kcal=False):
|
||||||
|
# Wenn es sich um kcal handelt und der Wert vor der Rundung zwischen 0 und 1 liegt
|
||||||
|
if ist_kcal and 0 < zahl < 1:
|
||||||
|
return 1
|
||||||
|
|
||||||
faktor = 10 ** stellen
|
faktor = 10 ** stellen
|
||||||
zahl = zahl * faktor
|
zahl = zahl * faktor
|
||||||
basis = floor(zahl)
|
basis = floor(zahl)
|
||||||
|
@ -177,6 +177,17 @@ function updateRowWithNewData(row, weight, nutritionData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function schulrunden(zahl) {
|
||||||
|
// Multipliziere die Zahl mit 10, um die relevante Dezimalstelle vor das Komma zu bekommen
|
||||||
|
zahl = zahl * 10;
|
||||||
|
// Wende Math.ceil an, um auf die nächste ganze Zahl aufzurunden,
|
||||||
|
// aber nur, wenn der Dezimalteil >= 0.5 ist. Andernfalls verwende Math.floor.
|
||||||
|
zahl = (zahl - Math.floor(zahl) >= 0.5) ? Math.ceil(zahl) : Math.floor(zahl);
|
||||||
|
// Teile durch 10, um die ursprüngliche Skalierung wiederherzustellen,
|
||||||
|
// aber mit der erforderlichen Rundung
|
||||||
|
return zahl / 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function addProduct() {
|
function addProduct() {
|
||||||
const foodInput = document.getElementById('my_combobox');
|
const foodInput = document.getElementById('my_combobox');
|
||||||
@ -187,7 +198,7 @@ function updateRowWithNewData(row, weight, nutritionData) {
|
|||||||
const portions = portionsInput.value ? parseInt(portionsInput.value, 10) : 1;
|
const portions = portionsInput.value ? parseInt(portionsInput.value, 10) : 1;
|
||||||
|
|
||||||
// Teilen des Gewichts durch die Anzahl der Portionen und Aufrunden
|
// Teilen des Gewichts durch die Anzahl der Portionen und Aufrunden
|
||||||
weight = Math.ceil(weight / portions);
|
weight = schulrunden(weight / portions);
|
||||||
|
|
||||||
|
|
||||||
fetch(`/add_lm?food=${encodeURIComponent(food)}&weight=${encodeURIComponent(weight)}`)
|
fetch(`/add_lm?food=${encodeURIComponent(food)}&weight=${encodeURIComponent(weight)}`)
|
||||||
@ -270,7 +281,8 @@ function updateTotalNutrition() {
|
|||||||
<datalist id="products">
|
<datalist id="products">
|
||||||
<!-- Produkte werden hier dynamisch eingefügt -->
|
<!-- Produkte werden hier dynamisch eingefügt -->
|
||||||
</datalist>
|
</datalist>
|
||||||
<input type="number" id="weight" name="weight" placeholder="Gramm" oninput="updateButtonState()">
|
<input type="number" id="weight" name="weight" placeholder="Gramm" step="0.1" min="0" oninput="updateButtonState()">
|
||||||
|
|
||||||
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
|
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
Reference in New Issue
Block a user