def get_analytics_by_interval(self, size, interval):
""" Gets analytics data """
array = []
now = datetime.date.today()
# yes, there's probably a way to do this in one query
cur = self._db.cursor()
for i in range(size):
start = _get_datestr_from_dt(now - datetime.timedelta((i * interval) + interval - 1))
end = _get_datestr_from_dt(now - datetime.timedelta((i * interval) - 1))
try:
cur.execute("SELECT fetch_cnt FROM analytics WHERE "
"datestr BETWEEN %s "
"AND %s", (start, end,))
except mdb.Error as e:
raise CursorError(cur, e)
res = cur.fetchall()
# add all these up
tmp = 0
for r in res:
tmp = tmp + int(r[0])
array.append(tmp)
return array
评论列表
文章目录