mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-08 22:17:34 +01:00
Separate rolling average downloads from score
This commit is contained in:
parent
2617c53abf
commit
9d033acfff
@ -141,6 +141,7 @@ def download_release(package, id):
|
|||||||
|
|
||||||
Package.query.filter_by(id=package.id).update({
|
Package.query.filter_by(id=package.id).update({
|
||||||
"downloads": Package.downloads + 1,
|
"downloads": Package.downloads + 1,
|
||||||
|
"score_downloads": Package.score_downloads + bonus,
|
||||||
"score": Package.score + bonus
|
"score": Package.score + bonus
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -431,7 +431,8 @@ class Package(db.Model):
|
|||||||
approved = db.Column(db.Boolean, nullable=False, default=False)
|
approved = db.Column(db.Boolean, nullable=False, default=False)
|
||||||
soft_deleted = 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)
|
downloads = db.Column(db.Integer, nullable=False, default=0)
|
||||||
|
|
||||||
review_thread_id = db.Column(db.Integer, db.ForeignKey("thread.id"), nullable=True, default=None)
|
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:
|
if self.getMainScreenshotURL() is None:
|
||||||
self.score *= 0.8
|
self.score *= 0.8
|
||||||
|
|
||||||
|
self.recalcScore()
|
||||||
|
|
||||||
|
def recalcScore(self):
|
||||||
|
self.score_downloads = self.score
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MetaPackage(db.Model):
|
class MetaPackage(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
@ -20,5 +20,10 @@ from app.tasks import celery
|
|||||||
|
|
||||||
@celery.task()
|
@celery.task()
|
||||||
def updatePackageScores():
|
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()
|
db.session.commit()
|
||||||
|
31
migrations/versions/dd27f1311a90_.py
Normal file
31
migrations/versions/dd27f1311a90_.py
Normal file
@ -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 ###
|
Loading…
Reference in New Issue
Block a user