Add score bonus to reviews

This commit is contained in:
rubenwardy 2020-07-09 04:32:13 +01:00
parent d0aecd0ee5
commit ac7adde4b1
5 changed files with 26 additions and 26 deletions

View File

@ -87,7 +87,7 @@ def admin_page():
return redirect(url_for("admin.admin_page")) return redirect(url_for("admin.admin_page"))
elif action == "recalcscores": elif action == "recalcscores":
for p in Package.query.all(): for p in Package.query.all():
p.setStartScore() p.recalcScore()
db.session.commit() db.session.commit()
return redirect(url_for("admin.admin_page")) return redirect(url_for("admin.admin_page"))

View File

@ -42,8 +42,7 @@ def package_scores():
qb = QueryBuilder(request.args) qb = QueryBuilder(request.args)
query = qb.buildPackageQuery() query = qb.buildPackageQuery()
pkgs = [{ "author": package.author.username, "name": package.name, "score": package.score } \ pkgs = [package.getScoreDict() for package in query.all()]
for package in query.all()]
return jsonify(pkgs) return jsonify(pkgs)

View File

@ -82,6 +82,8 @@ def review(package):
db.session.commit() db.session.commit()
package.recalcScore()
notif_msg = None notif_msg = None
if was_new: if was_new:
notif_msg = "New review '{}' on package {}".format(form.title.data, package.title) notif_msg = "New review '{}' on package {}".format(form.title.data, package.title)

View File

@ -2,8 +2,12 @@ title: Top Packages Algorithm
## Score ## Score
A package's score is currently equal to a pseudo rolling average of downloads. A package's score is currently equal to a pseudo rolling average of downloads,
In the future, a package will also gain score through reviews. plus the sum of review scores.
A review score is 100 if positive, -100 if negative.
score = avg_downloads + Σ 100 * (positive ? 1 : -1)
## Pseudo rolling average of downloads ## Pseudo rolling average of downloads
@ -35,7 +39,8 @@ which was 20% of the above value.
## Manual adjustments ## Manual adjustments
The admin occasionally reduces all packages by a set percentage to speed up The admin occasionally reduces all packages by a set percentage to speed up
convergence. Convergence is when convergence. Convergence is when the pseudo-rolling average matches the actual
rolling average - the effect of the legacy heuristic is gone.
## Transparency and Feedback ## Transparency and Feedback

View File

@ -712,28 +712,19 @@ class Package(db.Model):
else: else:
raise Exception("Permission {} is not related to packages".format(perm.name)) raise Exception("Permission {} is not related to packages".format(perm.name))
def setStartScore(self): def getScoreDict(self):
downloads = self.downloads return {
"author": self.author.username,
forum_score = 0 "name": self.name,
forum_bonus = 0 "score": self.score,
topic = self.forums and ForumTopic.query.get(self.forums) "score_downloads": self.score_downloads,
if topic: "score_reviews": self.score - self.score_downloads,
months = (datetime.datetime.now() - topic.created_at).days / 30 "downloads": self.downloads
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
self.recalcScore()
def recalcScore(self): def recalcScore(self):
self.score_downloads = self.score review_scores = [ 100 * r.asSign() for r in self.reviews ]
self.score = self.score_downloads + sum(review_scores)
class MetaPackage(db.Model): class MetaPackage(db.Model):
@ -1134,6 +1125,9 @@ class PackageReview(db.Model):
thread = db.relationship("Thread", uselist=False, back_populates="review") thread = db.relationship("Thread", uselist=False, back_populates="review")
def asSign(self):
return 1 if self.recommends else -1
def getEditURL(self): def getEditURL(self):
return url_for("packages.edit_review", return url_for("packages.edit_review",
author=self.package.author.username, author=self.package.author.username,