diff --git a/qgis-app/plugins/models.py b/qgis-app/plugins/models.py index 5b4a7ff..7a4575d 100644 --- a/qgis-app/plugins/models.py +++ b/qgis-app/plugins/models.py @@ -28,6 +28,11 @@ class BasePluginManager(models.Manager): """ Adds a score + * average_vote provides a simple average rating. + * latest_version_date fetches the date of the + most recent approved plugin version. + * weighted_rating uses the Bayesian Average formula + to provide a more balanced rating that mitigates the effect of low vote counts. """ def get_queryset(self): @@ -36,13 +41,18 @@ def get_queryset(self): .get_queryset() .extra( select={ - "average_vote": "rating_score/(rating_votes+0.001)", + "average_vote": "rating_score / (rating_votes + 0.001)", "latest_version_date": ( "SELECT created_on FROM plugins_pluginversion WHERE " "plugins_pluginversion.plugin_id = plugins_plugin.id " "AND approved = TRUE " "ORDER BY created_on DESC LIMIT 1" ), + "weighted_rating": ( + "((rating_votes::FLOAT / (rating_votes + 5)) * " + "(rating_score::FLOAT / (rating_votes + 0.001))) + " + "((5::FLOAT / (rating_votes + 5)) * 3)" + ), } ) ) @@ -172,12 +182,17 @@ def get_queryset(self): .filter(pluginversion__approved=False, deprecated=False) .extra( select={ - "average_vote": "rating_score/(rating_votes+0.001)", + "average_vote": "rating_score / (rating_votes + 0.001)", "latest_version_date": ( "SELECT created_on FROM plugins_pluginversion WHERE " "plugins_pluginversion.plugin_id = plugins_plugin.id " "ORDER BY created_on DESC LIMIT 1" ), + "weighted_rating": ( + "((rating_votes::FLOAT / (rating_votes + 5)) * " + "(rating_score::FLOAT / (rating_votes + 0.001))) + " + "((5::FLOAT / (rating_votes + 5)) * 3)" + ), } ) .distinct() @@ -258,7 +273,7 @@ def get_queryset(self): super(MostRatedPlugins, self) .get_queryset() .filter(deprecated=False) - .order_by("-average_vote") + .order_by("-weighted_rating") .distinct() ) @@ -314,12 +329,17 @@ def get_queryset(self): ) .extra( select={ - "average_vote": "rating_score/(rating_votes+0.001)", + "average_vote": "rating_score / (rating_votes + 0.001)", "latest_version_date": ( "SELECT created_on FROM plugins_pluginversion WHERE " "plugins_pluginversion.plugin_id = plugins_plugin.id " "ORDER BY created_on DESC LIMIT 1" ), + "weighted_rating": ( + "((rating_votes::FLOAT / (rating_votes + 5)) * " + "(rating_score::FLOAT / (rating_votes + 0.001))) + " + "((5::FLOAT / (rating_votes + 5)) * 3)" + ), } ).distinct() ) @@ -351,12 +371,17 @@ def get_queryset(self): ) .extra( select={ - "average_vote": "rating_score/(rating_votes+0.001)", + "average_vote": "rating_score / (rating_votes + 0.001)", "latest_version_date": ( "SELECT created_on FROM plugins_pluginversion WHERE " "plugins_pluginversion.plugin_id = plugins_plugin.id " "ORDER BY created_on DESC LIMIT 1" ), + "weighted_rating": ( + "((rating_votes::FLOAT / (rating_votes + 5)) * " + "(rating_score::FLOAT / (rating_votes + 0.001))) + " + "((5::FLOAT / (rating_votes + 5)) * 3)" + ), } ).distinct() ) @@ -382,12 +407,17 @@ def get_queryset(self): ) .extra( select={ - "average_vote": "rating_score/(rating_votes+0.001)", + "average_vote": "rating_score / (rating_votes + 0.001)", "latest_version_date": ( "SELECT created_on FROM plugins_pluginversion WHERE " "plugins_pluginversion.plugin_id = plugins_plugin.id " "ORDER BY created_on DESC LIMIT 1" ), + "weighted_rating": ( + "((rating_votes::FLOAT / (rating_votes + 5)) * " + "(rating_score::FLOAT / (rating_votes + 0.001))) + " + "((5::FLOAT / (rating_votes + 5)) * 3)" + ), } ).distinct() ) diff --git a/qgis-app/plugins/templates/plugins/plugin_list.html b/qgis-app/plugins/templates/plugins/plugin_list.html index d401929..cb14ca7 100644 --- a/qgis-app/plugins/templates/plugins/plugin_list.html +++ b/qgis-app/plugins/templates/plugins/plugin_list.html @@ -146,7 +146,13 @@