[gnome-software] Add a concept of rating confidence to each application



commit 716497a31533fa9e8f127fdadbde8f2aad0b5fcf
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jan 30 19:54:13 2014 +0000

    Add a concept of rating confidence to each application
    
    The idea is that if a 30 number of people have rated an application at 80% it is
    prefered over an application rated at 100% by just one person.
    
    It will allow us to filter out spurious results when choosing picks automatically.

 src/gs-app.c                          |   35 +++++++++++++++++++++++++++++++++
 src/gs-app.h                          |    3 ++
 src/plugins/gs-plugin-local-ratings.c |    1 +
 3 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 4921d12..42baeeb 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -81,6 +81,7 @@ struct GsAppPrivate
        gchar                   *update_details;
        gchar                   *management_plugin;
        gint                     rating;
+       gint                     rating_confidence;
        GsAppRatingKind          rating_kind;
        guint64                  size;
        GsAppKind                kind;
@@ -266,6 +267,8 @@ gs_app_to_string (GsApp *app)
                g_string_append_printf (str, "\tmenu-path:\t%s\n", priv->menu_path);
        if (priv->rating != -1)
                g_string_append_printf (str, "\trating:\t%i\n", priv->rating);
+       if (priv->rating_confidence != -1)
+               g_string_append_printf (str, "\trating-confidence:\t%i\n", priv->rating_confidence);
        if (priv->rating_kind != GS_APP_RATING_KIND_UNKNOWN)
                g_string_append_printf (str, "\trating-kind:\t%s\n",
                                        priv->rating_kind == GS_APP_RATING_KIND_USER ?
@@ -1260,6 +1263,37 @@ gs_app_set_rating (GsApp *app, gint rating)
 }
 
 /**
+ * gs_app_get_rating_confidence:
+ * @app:       A #GsApp instance
+ *
+ * Return value: a predictor from 0 to 100, or -1 for unknown or invalid
+ */
+gint
+gs_app_get_rating_confidence (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), -1);
+       return app->priv->rating_confidence;
+}
+
+/**
+ * gs_app_set_rating_confidence:
+ * @app:       A #GsApp instance
+ * @rating_confidence: a predictor from 0 to 100, or -1 for unknown or invalid
+ *
+ * This is how confident the rating is statistically valid, expressed as a
+ * percentage.
+ * Applications with a high confidence typically have a large number of samples
+ * and can be trusted, but low confidence could mean that only one person has
+ * rated the application.
+ */
+void
+gs_app_set_rating_confidence (GsApp *app, gint rating_confidence)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       app->priv->rating_confidence = rating_confidence;
+}
+
+/**
  * gs_app_get_rating_kind:
  */
 GsAppRatingKind
@@ -1688,6 +1722,7 @@ gs_app_init (GsApp *app)
 {
        app->priv = GS_APP_GET_PRIVATE (app);
        app->priv->rating = -1;
+       app->priv->rating_confidence = -1;
        app->priv->rating_kind = GS_APP_RATING_KIND_UNKNOWN;
        app->priv->sources = g_ptr_array_new_with_free_func (g_free);
        app->priv->source_ids = g_ptr_array_new_with_free_func (g_free);
diff --git a/src/gs-app.h b/src/gs-app.h
index 24e7180..53946d6 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -213,6 +213,9 @@ void                 gs_app_set_metadata            (GsApp          *app,
 gint            gs_app_get_rating              (GsApp          *app);
 void            gs_app_set_rating              (GsApp          *app,
                                                 gint            rating);
+gint            gs_app_get_rating_confidence   (GsApp          *app);
+void            gs_app_set_rating_confidence   (GsApp          *app,
+                                                gint            rating_confidence);
 GsAppRatingKind         gs_app_get_rating_kind         (GsApp          *app);
 void            gs_app_set_rating_kind         (GsApp          *app,
                                                 GsAppRatingKind rating_kind);
diff --git a/src/plugins/gs-plugin-local-ratings.c b/src/plugins/gs-plugin-local-ratings.c
index be631ef..6036652 100644
--- a/src/plugins/gs-plugin-local-ratings.c
+++ b/src/plugins/gs-plugin-local-ratings.c
@@ -235,6 +235,7 @@ gs_plugin_refine (GsPlugin *plugin,
                rating = gs_plugin_local_find_app (plugin, gs_app_get_id (app));
                if (rating != -1) {
                        gs_app_set_rating (app, rating);
+                       gs_app_set_rating_confidence (app, 100);
                        gs_app_set_rating_kind (app, GS_APP_RATING_KIND_USER);
                }
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]