Skip to content

Commit

Permalink
Update current usage of the term 'rating'
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2611 authored and gentlecat committed Jul 14, 2017
1 parent 4eaa242 commit 3e9d586
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
26 changes: 13 additions & 13 deletions critiquebrainz/db/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_by_id(review_id):
"source_url": str,
"last_revision: dict,
"votes": dict,
"rating": int,
"popularity": int,
"text": str,
"created": datetime,
"license": dict,
Expand Down Expand Up @@ -137,7 +137,7 @@ def get_by_id(review_id):
votes = db_revision.votes(review["last_revision"]["id"])
review["votes_positive_count"] = votes["positive"]
review["votes_negative_count"] = votes["negative"]
review["rating"] = review["votes_positive_count"] - review["votes_negative_count"]
review["popularity"] = review["votes_positive_count"] - review["votes_negative_count"]
return review


Expand Down Expand Up @@ -263,7 +263,7 @@ def create(*, entity_id, entity_type, user_id, is_draft, text,
"source_url": str,
"last_revision: dict,
"votes": dict,
"rating": int,
"popularity": int,
"text": str,
"created": datetime,
"license": dict,
Expand Down Expand Up @@ -310,8 +310,8 @@ def list_reviews(*, inc_drafts=False, inc_hidden=False, entity_id=None,
entity_id (uuid): ID of the entity that has been reviewed.
entity_type (str): Type of the entity that has been reviewed.
user_id (uuid): ID of the author.
sort (str): Order of the returned reviews. Can be either "rating" (order by rating), or "created"
(order by creation time), or "random" (order randomly).
sort (str): Order of the returned reviews. Can be either "popularity" (order by difference in +/- votes),
or "created" (order by creation time), or "random" (order randomly).
limit (int): Maximum number of reviews to return.
offset (int): Offset that can be used in conjunction with the limit.
language (str): Language code of reviews.
Expand Down Expand Up @@ -375,9 +375,9 @@ def list_reviews(*, inc_drafts=False, inc_hidden=False, entity_id=None,
count = result.fetchone()[0]
order_by_clause = str()

if sort == "rating":
if sort == "popularity":
order_by_clause = """
ORDER BY rating DESC
ORDER BY popularity DESC
"""
elif sort == "created":
order_by_clause = """
Expand All @@ -387,7 +387,7 @@ def list_reviews(*, inc_drafts=False, inc_hidden=False, entity_id=None,
order_by_clause = """
ORDER BY RANDOM()
"""
# Note that all revisions' votes are considered in these ratings
# Note that all revisions' votes are considered in this popularity
query = sqlalchemy.text("""
SELECT review.id,
review.entity_id,
Expand Down Expand Up @@ -416,7 +416,7 @@ def list_reviews(*, inc_drafts=False, inc_hidden=False, entity_id=None,
SUM(
CASE WHEN vote = 't' THEN 1
WHEN vote = 'f' THEN -1 WHEN vote IS NULL THEN 0 END
) AS rating,
) AS popularity,
latest_revision.id as latest_revision_id,
latest_revision.timestamp as latest_revision_timestamp,
latest_revision.text as text,
Expand Down Expand Up @@ -477,9 +477,9 @@ def list_reviews(*, inc_drafts=False, inc_hidden=False, entity_id=None,
def get_popular(limit=None):
"""Get a list of popular reviews.
Popularity is determined by rating of a particular review. Rating is a
Popularity is determined by 'popularity' of a particular review. popularity is a
difference between positive votes and negative. In this case only votes
from the last month are used to calculate rating to make results more
from the last month are used to calculate popularity to make results more
varied.
Args:
Expand Down Expand Up @@ -511,7 +511,7 @@ def get_popular(limit=None):
CASE WHEN vote = 't' THEN 1
WHEN vote = 'f' THEN -1
WHEN vote IS NULL THEN 0 END
) AS rating,
) AS popularity,
latest_revision.id AS latest_revision_id,
latest_revision.timestamp AS latest_revision_timestamp,
latest_revision.text AS text
Expand Down Expand Up @@ -544,7 +544,7 @@ def get_popular(limit=None):
) AS randomized_entity_ids
)
GROUP BY review.id, latest_revision.id
ORDER BY rating
ORDER BY popularity
LIMIT :limit
"""), {
"limit": defined_limit,
Expand Down
2 changes: 1 addition & 1 deletion critiquebrainz/db/review_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_list_reviews(self):
self.assertEqual(len(reviews), 1)
self.assertEqual(reviews[0]["text"], "Beautiful!")

reviews, count = db_review.list_reviews(sort="rating")
reviews, count = db_review.list_reviews(sort="popularity")
self.assertEqual(count, 1)
self.assertEqual(len(reviews), 1)

Expand Down
2 changes: 1 addition & 1 deletion critiquebrainz/frontend/views/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def entity(id):

limit = int(request.args.get('limit', default=10))
offset = int(request.args.get('offset', default=0))
reviews, count = db_review.list_reviews(entity_id=id, entity_type='event', sort='rating', limit=limit, offset=offset)
reviews, count = db_review.list_reviews(entity_id=id, entity_type='event', sort='popularity', limit=limit, offset=offset)

return render_template('event/entity.html', id=id, event=event, reviews=reviews,
my_review=my_review, limit=limit, offset=offset, count=count)
2 changes: 1 addition & 1 deletion critiquebrainz/frontend/views/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def entity(id):

limit = int(request.args.get('limit', default=10))
offset = int(request.args.get('offset', default=0))
reviews, count = db_review.list_reviews(entity_id=id, entity_type='place', sort='rating', limit=limit, offset=offset)
reviews, count = db_review.list_reviews(entity_id=id, entity_type='place', sort='popularity', limit=limit, offset=offset)

return render_template('place/entity.html', id=id, place=place, reviews=reviews,
my_review=my_review, limit=limit, offset=offset, count=count)
2 changes: 1 addition & 1 deletion critiquebrainz/frontend/views/release_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def entity(id):
my_review = None
else:
my_review = None
reviews, count = db_review.list_reviews(entity_id=id, entity_type='release_group', sort='rating', limit=limit, offset=offset)
reviews, count = db_review.list_reviews(entity_id=id, entity_type='release_group', sort='popularity', limit=limit, offset=offset)
return render_template('release_group/entity.html', id=id, release_group=release_group, reviews=reviews,
release=release, my_review=my_review, spotify_mappings=spotify_mappings, tags=tags,
soundcloud_url=soundcloud_url, limit=limit, offset=offset, count=count)
8 changes: 4 additions & 4 deletions critiquebrainz/ws/review/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def review_entity_handler(review_id):
"id": "CC BY-NC-SA 3.0",
"info_url": "https:\/\/creativecommons.org\/licenses\/by-nc-sa\/3.0\/"
},
"rating": 0,
"popularity": 0,
"source": "BBC",
"source_url": "http:\/\/www.bbc.co.uk\/music\/reviews\/3vfd",
"text": "REVIEW GOES HERE",
Expand Down Expand Up @@ -283,7 +283,7 @@ def review_list_handler():
"id": "CC BY-NC-SA 3.0",
"info_url": "https:\/\/creativecommons.org\/licenses\/by-nc-sa\/3.0\/"
},
"rating": 0,
"popularity": 0,
"source": "BBC",
"source_url": "http:\/\/www.bbc.co.uk\/music\/reviews\/vh54",
"text": "REVIEW TEXT GOES HERE",
Expand All @@ -303,7 +303,7 @@ def review_list_handler():
:json uuid entity_id: UUID of the release group that is being reviewed
:json string entity_type: One of the supported reviewable entities. 'release_group' or 'event' etc. **(optional)**
:query user_id: user's UUID **(optional)**
:query sort: ``rating`` or ``created`` **(optional)**
:query sort: ``popularity`` or ``created`` **(optional)**
:query limit: results limit, min is 0, max is 50, default is 50 **(optional)**
:query offset: result offset, default is 0 **(optional)**
:query language: language code (ISO 639-1) **(optional)**
Expand All @@ -320,7 +320,7 @@ def review_list_handler():
entity_type = Parser.string('uri', 'entity_type', valid_values=ENTITY_TYPES, optional=True)

user_id = Parser.uuid('uri', 'user_id', optional=True)
sort = Parser.string('uri', 'sort', valid_values=['rating', 'created'], optional=True)
sort = Parser.string('uri', 'sort', valid_values=['popularity', 'created'], optional=True)
limit = Parser.int('uri', 'limit', min=1, max=50, optional=True) or 50
offset = Parser.int('uri', 'offset', optional=True) or 0
language = Parser.string('uri', 'language', min=2, max=3, optional=True)
Expand Down

0 comments on commit 3e9d586

Please sign in to comment.