popupdate.py 674 Bytes
Newer Older
Lukas Fleischer's avatar
Lukas Fleischer committed
1
2
#!/usr/bin/python3

3
4
import time

Lukas Fleischer's avatar
Lukas Fleischer committed
5
import aurweb.db
Lukas Fleischer's avatar
Lukas Fleischer committed
6
7


Lukas Fleischer's avatar
Lukas Fleischer committed
8
9
def main():
    conn = aurweb.db.Connection()
Lukas Fleischer's avatar
Lukas Fleischer committed
10

Lukas Fleischer's avatar
Lukas Fleischer committed
11
12
13
    conn.execute("UPDATE PackageBases SET NumVotes = (" +
                 "SELECT COUNT(*) FROM PackageVotes " +
                 "WHERE PackageVotes.PackageBaseID = PackageBases.ID)")
Lukas Fleischer's avatar
Lukas Fleischer committed
14

15
    now = int(time.time())
Lukas Fleischer's avatar
Lukas Fleischer committed
16
    conn.execute("UPDATE PackageBases SET Popularity = (" +
17
                 "SELECT COALESCE(SUM(POWER(0.98, (? - VoteTS) / 86400)), 0.0) " +
Lukas Fleischer's avatar
Lukas Fleischer committed
18
                 "FROM PackageVotes WHERE PackageVotes.PackageBaseID = " +
19
                 "PackageBases.ID AND NOT VoteTS IS NULL)", [now])
Lukas Fleischer's avatar
Lukas Fleischer committed
20
21
22

    conn.commit()
    conn.close()
23
24
25
26


if __name__ == '__main__':
    main()