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 @@

{% if title %}{{title}}{% else %}{% trans "All plugins" % {% endif %} {{ object.latest_version_date|local_timezone:"SHORT_NATURAL_DAY" }} {{ object.created_on|local_timezone:"SHORT" }} -
({{ object.rating_votes }})
+ +
+
+ +
({{ object.rating_votes }}) +
+ {% if object.stable %}{{ object.stable.version }}{% else %}—{% endif %} {% if object.experimental %}{{ object.experimental.version }}{% else %}—{% endif %} diff --git a/qgis-app/plugins/templates/plugins/plugin_list_sort.html b/qgis-app/plugins/templates/plugins/plugin_list_sort.html index 9b88a5a..8967420 100644 --- a/qgis-app/plugins/templates/plugins/plugin_list_sort.html +++ b/qgis-app/plugins/templates/plugins/plugin_list_sort.html @@ -9,7 +9,7 @@ - +

diff --git a/qgis-app/plugins/views.py b/qgis-app/plugins/views.py index fd54d21..23260f1 100644 --- a/qgis-app/plugins/views.py +++ b/qgis-app/plugins/views.py @@ -848,7 +848,7 @@ def get_queryset(self): sort_by = '-' + sort_by # Prepend '-' to sort in descending order # Validate the sort field - if sort_by.lstrip('-') in ['average_vote', 'latest_version_date'] or self._is_valid_field(sort_by.lstrip('-')): + if sort_by.lstrip('-') in ['average_vote', 'latest_version_date', 'weighted_rating'] or self._is_valid_field(sort_by.lstrip('-')): qs = qs.order_by(sort_by) elif not qs.ordered: qs = qs.order_by(Lower("name"))