Add review count to scores API

This commit is contained in:
rubenwardy 2024-06-01 00:06:25 +01:00
parent 37bff46f33
commit 1fad818f05
3 changed files with 12 additions and 2 deletions

@ -572,7 +572,7 @@ def all_package_stats():
@bp.route("/api/scores/")
@cors_allowed
@cached(300)
@cached(900)
def package_scores():
qb = QueryBuilder(request.args)
query = qb.build_package_query()

@ -522,6 +522,10 @@ Supported query parameters:
* `score`: total package score.
* `score_reviews`: score from reviews.
* `score_downloads`: score from downloads.
* `reviews`: a dictionary of
* `positive`: int, number of positive reviews.
* `neutral`: int, number of neutral reviews.
* `negative`: int, number of negative reviews.
* GET `/api/homepage/` ([View](/api/homepage/)) - get contents of homepage.
* `count`: number of packages
* `downloads`: get number of downloads

@ -759,13 +759,19 @@ class Package(db.Model):
return states
def as_score_dict(self):
reviews = self.get_review_summary()
return {
"author": self.author.username,
"name": self.name,
"score": self.score,
"score_downloads": self.score_downloads,
"score_reviews": self.score - self.score_downloads,
"downloads": self.downloads
"downloads": self.downloads,
"reviews": {
"positive": reviews[0],
"neutral": reviews[1],
"negative": reviews[2],
},
}
def recalculate_score(self):