]> rtime.felk.cvut.cz Git - coffee/main.git/commitdiff
coffee-flask: Fix coffee graph for start of the month
authorMichal Sojka <michal.sojka@cvut.cz>
Mon, 3 Sep 2018 16:20:15 +0000 (18:20 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Mon, 3 Sep 2018 16:20:15 +0000 (18:20 +0200)
An error was found during the start of new month. To fix this I have
changed the SQL query to use '%s' (unix time) instead of '%d' (day
number).

How does this work?
The SQL query is using relation between two tables based on the date.
This relation is created using these parts of query:
 > "select num,date('now',-num || ' days')" as d from days
 > d = date(c.time)

First line creates timestampes of last 7 days -- time is set to
UTC midnight.
Second line converts data in 'c.time' to date struct - BUT! Even
here the time is set to midnight. This behaviour makes the relation
possible.

How does it behave in app.py?
Result of the query contains data that are ordered by time.
Unfortunately this order is lost during recasting the data to
list/dict (which are unordered). To solve this sorting is used.
Sorting data with unix time is safe, because it is always increasing.

To highlight this change, 'days' variable is refactored to 'unix_days'.

coffee-flask

index d99857c0068d590bfea0a0bd00bc8bc1dd6fc4f1..e21678bdd78e26ef9586ebbd641cb39239d74d8f 160000 (submodule)
@@ -1 +1 @@
-Subproject commit d99857c0068d590bfea0a0bd00bc8bc1dd6fc4f1
+Subproject commit e21678bdd78e26ef9586ebbd641cb39239d74d8f