[gnome-software/wip/rancell/reviews] Recommend highly rated apps
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/rancell/reviews] Recommend highly rated apps
- Date: Fri, 1 Apr 2016 03:38:12 +0000 (UTC)
commit ddeae716c9b18bd471047fe9bac45a04873e5d43
Author: Robert Ancell <robert ancell canonical com>
Date: Fri Apr 1 16:37:45 2016 +1300
Recommend highly rated apps
src/plugins/gs-plugin-ubuntu-reviews.c | 87 ++++++++++++++++++++++++++++++++
1 files changed, 87 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index d719ae9..d19e51e 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -1029,3 +1029,90 @@ gs_plugin_review_remove (GsPlugin *plugin,
return remove_review (plugin, review_id, error);
}
+
+typedef struct {
+ gchar *package_name;
+ gint rating;
+} PopularEntry;
+
+static gint
+popular_sqlite_cb (void *data,
+ gint argc,
+ gchar **argv,
+ gchar **col_name)
+{
+ GList **list = data;
+ PopularEntry *entry;
+
+ entry = g_slice_new (PopularEntry);
+ entry->package_name = g_strdup (argv[0]);
+ entry->rating = get_rating (g_ascii_strtoll (argv[1], NULL, 10), g_ascii_strtoll (argv[2], NULL, 10),
g_ascii_strtoll (argv[3], NULL, 10), g_ascii_strtoll (argv[4], NULL, 10), g_ascii_strtoll (argv[5], NULL,
10));
+ *list = g_list_prepend (*list, entry);
+
+ return 0;
+}
+
+static gint
+compare_popular_entry (gconstpointer a, gconstpointer b)
+{
+ PopularEntry *ea = a, *eb = b;
+ return eb->rating - ea->rating;
+}
+
+static void
+free_popular_entry (gpointer data)
+{
+ PopularEntry *entry = data;
+ g_free (entry->package_name);
+ g_slice_free (PopularEntry, entry);
+}
+
+gboolean
+gs_plugin_add_popular (GsPlugin *plugin,
+ GList **list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gint result;
+ GList *entries = NULL, *link;
+ char *error_msg = NULL;
+
+ /* Load database once */
+ if (g_once_init_enter (&plugin->priv->db_loaded)) {
+ gboolean ret = load_database (plugin, error);
+ g_once_init_leave (&plugin->priv->db_loaded, TRUE);
+ if (!ret)
+ return FALSE;
+ }
+
+ result = sqlite3_exec (plugin->priv->db,
+ "SELECT package_name, one_star_count, two_star_count, three_star_count,
four_star_count, five_star_count FROM review_stats",
+ popular_sqlite_cb,
+ &entries,
+ &error_msg);
+ if (result != SQLITE_OK) {
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_FAILED,
+ "SQL error: %s", error_msg);
+ sqlite3_free (error_msg);
+ return FALSE;
+ }
+
+ entries = g_list_sort (entries, compare_popular_entry);
+ for (link = entries; link; link = link->next) {
+ PopularEntry *entry = link->data;
+ g_autoptr(GsApp) app = NULL;
+
+ /* Need four stars to show */
+ if (entry->rating < 80)
+ break;
+
+ app = gs_app_new (entry->package_name);
+ gs_app_add_source (app, entry->package_name);
+ gs_plugin_add_app (list, app);
+ }
+ g_list_free_full (entries, free_popular_entry);
+
+ return TRUE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]