@@ -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,18 +287,20 @@ 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():
+ for date in sorted(db.days.keys()):
+ day = db.days[date]
day_rows = "
"\
"
%s
"\
"
%.1f
"\
@@ -314,11 +319,9 @@ class MyServer(BaseHTTPRequestHandler):
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: