summaryrefslogtreecommitdiffstats
path: root/aurweb/scripts/popupdate.py
blob: b64deedb9b2125cff80c29f72405dd14fa4b2993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python3

import time

import aurweb.db


def main():
    conn = aurweb.db.Connection()

    conn.execute("UPDATE PackageBases SET NumVotes = (" +
                 "SELECT COUNT(*) FROM PackageVotes " +
                 "WHERE PackageVotes.PackageBaseID = PackageBases.ID)")

    now = int(time.time())
    conn.execute("UPDATE PackageBases SET Popularity = (" +
                 "SELECT COALESCE(SUM(POWER(0.98, (? - VoteTS) / 86400)), 0.0) " +
                 "FROM PackageVotes WHERE PackageVotes.PackageBaseID = " +
                 "PackageBases.ID AND NOT VoteTS IS NULL)", [now])

    conn.commit()
    conn.close()


if __name__ == '__main__':
    main()