This commit is contained in:
21
src/Run.py
21
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:
|
||||||
@ -53,6 +53,13 @@ def calculate_nutrition(food, weight):
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def schulrunden(zahl):
|
||||||
|
basis = floor(zahl)
|
||||||
|
if zahl - basis >= 0.5:
|
||||||
|
return basis + 1
|
||||||
|
else:
|
||||||
|
return basis
|
||||||
|
|
||||||
|
|
||||||
# Index-Route
|
# Index-Route
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
|
Reference in New Issue
Block a user