letterboxdpy icon indicating copy to clipboard operation
letterboxdpy copied to clipboard

Add classic rating method and other bugfixes

Open jmcruz14 opened this issue 1 year ago • 4 comments

This PR adds an additional method which calculates a film's classic rating* (the old algorithm which Letterboxd employed before they switched to a more global algorithm for calculating the ratings shown to the user) via its histogram and, if there aren't enough ratings, a standard rating of 3.5 which is proportionally weighed alongside the aggregate histogram rating according to a threshold.

Algorithm (for the full code, check the ratings.py file for more information):

RATING_COUNT_THRESHOLD = 40

AVERAGE_RATING = total_rating / review_count if review_count > 0 else 0
RATING_PROPORTION = (RATING_COUNT_THRESHOLD - review_count) / RATING_COUNT_THRESHOLD if review_count < RATING_COUNT_THRESHOLD else 1
aggregate_rating = AVERAGE_RATING * (1 - RATING_PROPORTION) if RATING_PROPORTION != 1 else AVERAGE_RATING
standard_rating = 3.5 * RATING_PROPORTION if RATING_PROPORTION != 1 else 0

CLASSIC_RATING = round(standard_rating + aggregate_rating, 2)

Other Bugfixes

  • Added f-string syntax to get_rating_histogram_url
  • Included additional error handling for the movie_banner method
  • (5/10/13) Updated DOM variables obtained for select class attributes due to a possible update made by Letterboxd w/c affected the attributes of elements in the lazy-loaded DOM

Relevance

This PR is also important for calculating ratings for films that currently don't have visible ratings in their page. Examples include Global South films, student films, obscure documentaries, shorts, and films that basically don't have as much visibility outside of a single country.


*The sweet spot of 40 minimum ratings before the standard rating of 3.5 is removed is an estimate. But this contributor would like to point out that in his history of handling his own list to check for films that fit the criteria, its worth pointing out the rating used to show up at about 40 recorded ratings per film.

jmcruz14 avatar Apr 29 '24 23:04 jmcruz14

Could you change this to a function rather than a method? It should be outside the class.

fastfingertips avatar Apr 30 '24 10:04 fastfingertips

Could you change this to a function rather than a method? It should be outside the class.

Been poring my thoughts over where to best place this. Should I make it its own function or do you think it looks nice being bunched together in the movie_watchers function?

jmcruz14 avatar May 03 '24 09:05 jmcruz14

@fastfingertips Check the latest commits and their messages. Seems like Letterboxd recently updated some nomenclature and this affected a couple of functions. (On top of what you requested me to do of course)

jmcruz14 avatar May 09 '24 16:05 jmcruz14

@Jain-m3392 appreciate the suggestions! Just gonna test before pushing the commit to the remote.

jmcruz14 avatar May 17 '24 01:05 jmcruz14