Add a field for package base popularity

Create a new field Popularity in the PackageBases table. The field is
updated by the popupdate script and reflects the popularity of a
package. Popularity is the sum of all votes with each vote being
weighted with a factor of 0.98 per day since its creation.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2015-06-11 18:41:58 +02:00
parent 0345914c5c
commit 824744f1d2
3 changed files with 14 additions and 1 deletions

View file

@ -23,5 +23,10 @@ cur = db.cursor()
cur.execute("UPDATE PackageBases SET NumVotes = (SELECT COUNT(*) FROM " +
"PackageVotes WHERE PackageVotes.PackageBaseID = PackageBases.ID)")
cur.execute("UPDATE PackageBases SET Popularity = (" +
"SELECT SUM(POWER(0.98, (UNIX_TIMESTAMP() - VoteTS) / 86400)) " +
"FROM PackageVotes WHERE PackageVotes.PackageBaseID = " +
"PackageBases.ID AND NOT VoteTS IS NULL)")
db.commit()
db.close()