X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/test.html?a=blobdiff_plain;f=calories.py;h=23234b2e0924718dfbca7edb3f725ac3e79039c5;hb=0e3baa007880c4c6c27899df85f9ff21626f7c36;hp=54fb64e2d94be3f98ce2a743823c2c3db241a60a;hpb=8d8bb938a9d2248bd44ed53fdb0b87eff9ee2dd9;p=misc
diff --git a/calories.py b/calories.py
index 54fb64e..23234b2 100644
--- a/calories.py
+++ b/calories.py
@@ -3,6 +3,9 @@ import os
import json
import datetime
+hostName = "localhost"
+serverPort = 8081
+
def build_page(eatable_rows, consumption_rows, eatables_selection, day_rows):
return """
@@ -26,7 +29,7 @@ td, th {
|
- |
+ |
|
@@ -59,7 +62,7 @@ for (let i = 0; i < unit_count_inputs.length; i++) {
button.innerHTML = '+1';
button.onclick = function(event) {
event.preventDefault();
- input.value = parseInt(input.value) + 1;
+ input.value = parseFloat(input.value) + 1.0;
};
input.insertAdjacentElement('afterend', button);
}
@@ -250,7 +253,7 @@ class MyServer(BaseHTTPRequestHandler):
if c.unit_count > 0:
db.eatables[c.eatable_key].popularity += 1
db.consumptions = []
- default_slots = 7
+ default_slots = 10
for k, v in sorted(db.eatables.items(), key=lambda item: -item[1].popularity):
db.add_consumption(Consumption(k, 0))
default_slots -= 1
@@ -284,24 +287,26 @@ class MyServer(BaseHTTPRequestHandler):
" | "\
"" % (k, v.title, v.cals, v.sugar_g, v.standard_g, v.comments, k)
consumptions = ""
+ db.consumptions = sorted(db.consumptions, key=lambda x: db.eatables[x.eatable_key].title)
for c in db.consumptions:
r = db.calc_consumption(c)
consumptions += "
"\
""\
" | "\
- " | "\
+ " | "\
" | "\
"%.1f | "\
"%.1f | "\
"" % (db.eatables_selection(c.eatable_key), c.unit_count, r["cals"], r["sugar"])
day_rows = ""
- for date, day in db.days.items():
- day_rows += ""\
+ for date in sorted(db.days.keys()):
+ day = db.days[date]
+ day_rows = "
"\
"%s | "\
"%.1f | "\
"%.1f | "\
- "
" % (date, date[:10], day.calories, day.calories, day.sugar_g, day.sugar_g)
- day_rows += ""\
+ "
" % (date, date[:10], day.calories, day.calories, day.sugar_g, day.sugar_g) + day_rows
+ day_rows = ""\
"today: | | | archive? | "\
"
"\
""\
@@ -309,16 +314,14 @@ class MyServer(BaseHTTPRequestHandler):
"%.1f | "\
"%.1f | "\
" | "\
- "
" % (db.today_date, db.today.calories, db.today.calories, db.today.sugar_g, db.today.sugar_g)
+ "" % (db.today_date, db.today.calories, db.today.calories, db.today.sugar_g, db.today.sugar_g) + day_rows
page = build_page(eatables, consumptions, db.eatables_selection(), day_rows)
self.wfile.write(bytes(page, "utf-8"))
-hostName = "localhost"
-serverPort = 8081
if __name__ == "__main__":
webServer = HTTPServer((hostName, serverPort), MyServer)
- print("Server started http://%s:%s" % (hostName, serverPort))
+ print(f"Server started http://{hostName}:{serverPort}")
try:
webServer.serve_forever()
except KeyboardInterrupt: