mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-23 06:22:24 +01:00
Improve package scoring
This commit is contained in:
parent
94426e97aa
commit
33b2b38308
@ -75,7 +75,7 @@ def admin_page():
|
||||
return redirect(url_for("admin.admin_page"))
|
||||
elif action == "recalcscores":
|
||||
for p in Package.query.all():
|
||||
p.recalcScore()
|
||||
p.setStartScore()
|
||||
|
||||
db.session.commit()
|
||||
return redirect(url_for("admin.admin_page"))
|
||||
|
@ -130,9 +130,18 @@ def download_release(package, id):
|
||||
if not has_key(key):
|
||||
set_key(key, "true")
|
||||
|
||||
bonus = 1
|
||||
if not package.getIsFOSS():
|
||||
bonus *= 0.1
|
||||
|
||||
PackageRelease.query.filter_by(id=release.id).update({
|
||||
"downloads": PackageRelease.downloads + 1
|
||||
})
|
||||
|
||||
Package.query.filter_by(id=package.id).update({
|
||||
"score": Package.score + bonus
|
||||
})
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return redirect(release.url, code=300)
|
||||
|
@ -24,6 +24,7 @@ from flask import Flask, url_for
|
||||
from flask_sqlalchemy import SQLAlchemy, BaseQuery
|
||||
from flask_migrate import Migrate
|
||||
from flask_user import login_required, UserManager, UserMixin, SQLAlchemyAdapter
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.orm import validates
|
||||
from sqlalchemy_searchable import SearchQueryMixin
|
||||
from sqlalchemy_utils.types import TSVectorType
|
||||
@ -425,6 +426,9 @@ class Package(db.Model):
|
||||
for e in PackagePropertyKey:
|
||||
setattr(self, e.name, getattr(package, e.name))
|
||||
|
||||
def getIsFOSS(self):
|
||||
return self.license.is_foss and self.media_license.is_foss
|
||||
|
||||
def getState(self):
|
||||
if self.approved:
|
||||
return "approved"
|
||||
@ -602,16 +606,20 @@ class Package(db.Model):
|
||||
else:
|
||||
raise Exception("Permission {} is not related to packages".format(perm.name))
|
||||
|
||||
def recalcScore(self):
|
||||
self.score = 10
|
||||
def setStartScore(self):
|
||||
downloads = db.session.query(func.sum(PackageRelease.downloads)). \
|
||||
filter(PackageRelease.package_id == self.id).scalar() or 0
|
||||
|
||||
if self.forums is not None:
|
||||
topic = ForumTopic.query.get(self.forums)
|
||||
if topic:
|
||||
days = (datetime.datetime.now() - topic.created_at).days
|
||||
months = days / 30
|
||||
years = days / 365
|
||||
self.score = topic.views / max(years, 0.0416) + 80*min(max(months, 0.5), 6)
|
||||
forum_score = 0
|
||||
forum_bonus = 0
|
||||
topic = self.forums and ForumTopic.query.get(self.forums)
|
||||
if topic:
|
||||
months = (datetime.datetime.now() - topic.created_at).days / 30
|
||||
years = months / 12
|
||||
forum_score = topic.views / max(years, 0.0416) + 80*min(max(months, 0.5), 6)
|
||||
forum_bonus = topic.views + topic.posts
|
||||
|
||||
self.score = max(downloads, forum_score * 0.6) + forum_bonus
|
||||
|
||||
if self.getMainScreenshotURL() is None:
|
||||
self.score *= 0.8
|
||||
@ -619,6 +627,7 @@ class Package(db.Model):
|
||||
if not self.license.is_foss or not self.media_license.is_foss:
|
||||
self.score *= 0.1
|
||||
|
||||
|
||||
class MetaPackage(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(100), unique=True, nullable=False)
|
||||
|
@ -69,6 +69,10 @@ CELERYBEAT_SCHEDULE = {
|
||||
'topic_list_import': {
|
||||
'task': 'app.tasks.forumtasks.importTopicList',
|
||||
'schedule': crontab(minute=1, hour=1),
|
||||
},
|
||||
'package_score_update': {
|
||||
'task': 'app.tasks.pkgtasks.updatePackageScores',
|
||||
'schedule': crontab(minute=10, hour=1),
|
||||
}
|
||||
}
|
||||
celery.conf.beat_schedule = CELERYBEAT_SCHEDULE
|
||||
|
@ -171,7 +171,4 @@ def importTopicList():
|
||||
topic.views = int(info["views"])
|
||||
topic.created_at = info["date"]
|
||||
|
||||
for p in Package.query.all():
|
||||
p.recalcScore()
|
||||
|
||||
db.session.commit()
|
||||
|
23
app/tasks/pkgtasks.py
Normal file
23
app/tasks/pkgtasks.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Content DB
|
||||
# Copyright (C) 2018 rubenwardy
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from app.models import Package, PackageRelease
|
||||
from app.tasks import celery
|
||||
|
||||
@celery.task()
|
||||
def updatePackageScores():
|
||||
Package.query.update({ "score": PackageRelease.score * 0.8 })
|
Loading…
Reference in New Issue
Block a user