def get_top_recent_voters(count=10, days=14): """Returns top 10 voters for last 2 weeks.""" if not count: return [] delta = int(time.time()) - days * 86400 emails = database.fetchcol("SELECT `email`, COUNT(*) AS `c` FROM `votes` " "WHERE `ts` >= ? GROUP BY `email` ORDER BY `c` DESC " "LIMIT %u" % count, (delta, )) return emails
def test_mark_liked_by(self): db.execute("DELETE FROM tracks") db.execute("DELETE FROM votes") db.execute("DELETE FROM labels") jids = ["*****@*****.**", "*****@*****.**", "*****@*****.**"] for idx in range(len(jids)): track_id = idx + 1 db.execute("INSERT INTO tracks (id) VALUES (?)", (track_id, )) for jid in range(idx, len(jids)): db.execute("INSERT INTO votes (track_id, email, vote) VALUES (?, ?, ?)", (track_id, jids[jid], 1, )) count = ardj.tracks.add_label_to_tracks_liked_by("tmp", jids[1:], "test") self.assertEquals(2, count) rows = db.fetchcol("SELECT track_id FROM labels WHERE label = ?", ("tmp", )) self.assertEquals([1, 2], rows)