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
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"
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
+
+ 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
- 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)
+ self.score = max(downloads, forum_score * 0.6) + forum_bonus
if self.getMainScreenshotURL() is None:
self.score *= 0.8
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)
'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
--- /dev/null
+# 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 })