static gboolean gs_plugin_odrs_refine_ratings (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); GArray *review_ratings; gint rating; g_autoptr(AsProfileTask) ptask = NULL; /* profile */ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin), "odrs::refine-ratings"); g_assert (ptask != NULL); /* get ratings */ review_ratings = g_hash_table_lookup (priv->ratings, gs_app_get_id (app)); if (review_ratings == NULL) return TRUE; gs_app_set_review_ratings (app, review_ratings); /* find the wilson rating */ rating = gs_utils_get_wilson_rating (g_array_index (review_ratings, guint32, 1), g_array_index (review_ratings, guint32, 2), g_array_index (review_ratings, guint32, 3), g_array_index (review_ratings, guint32, 4), g_array_index (review_ratings, guint32, 5)); if (rating > 0) gs_app_set_rating (app, rating); return TRUE; }
/** * gs_plugin_refine_ratings: */ static gboolean gs_plugin_refine_ratings (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { const guint to_percentage[] = { 0, 20, 40, 60, 80, 100 }; guint32 cnt = 0; guint32 acc = 0; guint i; g_autoptr(GArray) array = NULL; /* get ratings */ array = xdg_app_review_get_ratings (plugin, app, error); if (array == NULL) return FALSE; gs_app_set_review_ratings (app, array); /* find the correct global rating */ for (i = 1; i <= 5; i++) { guint32 tmp = g_array_index (array, guint32, i); acc += to_percentage[i] * tmp; cnt += tmp; } if (cnt == 0) gs_app_set_rating (app, cnt); else gs_app_set_rating (app, acc / cnt); return TRUE; }
static gboolean refine_rating (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); GPtrArray *sources; guint i; /* Load database once */ if (g_once_init_enter (&priv->db_loaded)) { gboolean ret = load_database (plugin, cancellable, error); g_once_init_leave (&priv->db_loaded, TRUE); if (!ret) return FALSE; } /* Skip if already has a rating */ if (gs_app_get_rating (app) != -1) return TRUE; sources = gs_app_get_sources (app); for (i = 0; i < sources->len; i++) { const gchar *package_name; gint rating; gint review_ratings[6]; gboolean ret; /* Otherwise use the statistics */ package_name = g_ptr_array_index (sources, i); ret = get_review_stats (plugin, package_name, &rating, review_ratings, error); if (!ret) return FALSE; if (rating != -1) { g_autoptr(GArray) ratings = NULL; g_debug ("ubuntu-reviews setting rating on %s to %i%%", package_name, rating); gs_app_set_rating (app, rating); ratings = g_array_sized_new (FALSE, FALSE, sizeof (gint), 6); g_array_append_vals (ratings, review_ratings, 6); gs_app_set_review_ratings (app, ratings); if (rating > 80) gs_app_add_kudo (app, GS_APP_KUDO_POPULAR); } } return TRUE; }