]> rtime.felk.cvut.cz Git - coffee/main.git/commit
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)
commit0b1b7634f2b77270e903c14aa14340eb70bbc044
treeaaaf5eaa1c95223e021264ff7125be192552d1e3
parent055b96a7181b8fd5e86a5ee8d1b0ed82fb3f1199
coffee-flask: Fix coffee graph for start of the month

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