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

import aurweb.db


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

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

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

    conn.commit()
    conn.close()


if __name__ == '__main__':
    main()