Separate rolling average downloads from score

This commit is contained in:
rubenwardy 2020-07-09 01:26:01 +01:00
parent 2617c53abf
commit 9d033acfff
4 changed files with 46 additions and 2 deletions

@ -141,6 +141,7 @@ def download_release(package, id):
Package.query.filter_by(id=package.id).update({
"downloads": Package.downloads + 1,
"score_downloads": Package.score_downloads + bonus,
"score": Package.score + bonus
})

@ -431,7 +431,8 @@ class Package(db.Model):
approved = db.Column(db.Boolean, nullable=False, default=False)
soft_deleted = db.Column(db.Boolean, nullable=False, default=False)
score = db.Column(db.Float, nullable=False, default=0)
score = db.Column(db.Float, nullable=False, default=0)
score_downloads = db.Column(db.Float, nullable=False, default=0)
downloads = db.Column(db.Integer, nullable=False, default=0)
review_thread_id = db.Column(db.Integer, db.ForeignKey("thread.id"), nullable=True, default=None)
@ -720,6 +721,12 @@ class Package(db.Model):
if self.getMainScreenshotURL() is None:
self.score *= 0.8
self.recalcScore()
def recalcScore(self):
self.score_downloads = self.score
class MetaPackage(db.Model):
id = db.Column(db.Integer, primary_key=True)

@ -20,5 +20,10 @@ from app.tasks import celery
@celery.task()
def updatePackageScores():
Package.query.update({ "score": Package.score * 0.95 })
Package.query.update({ "score_downloads": Package.score_downloads * 0.95 })
db.session.commit()
for package in Package.query.all():
package.recalcScore()
db.session.commit()

@ -0,0 +1,31 @@
"""empty message
Revision ID: dd27f1311a90
Revises: c141a63b2487
Create Date: 2020-07-09 00:20:39.501355
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'dd27f1311a90'
down_revision = 'c141a63b2487'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('package', sa.Column('score_downloads', sa.Float(), nullable=False, server_default="0"))
op.execute("""
UPDATE "package" SET "score_downloads"="score";
""")
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('package', 'score_downloads')
# ### end Alembic commands ###