]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/commit
Fix coffee graph for start of the month
authorJaroslav Klapalek <klapajar@fel.cvut.cz>
Mon, 3 Sep 2018 16:03:43 +0000 (18:03 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Mon, 3 Sep 2018 16:18:39 +0000 (18:18 +0200)
commite21678bdd78e26ef9586ebbd641cb39239d74d8f
tree6334bc7060e7e9b03450ee9b94838d4b7823fcb6
parentd99857c0068d590bfea0a0bd00bc8bc1dd6fc4f1
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'.
app.py
coffee_db.py