[gnome-software] ords: Use the Wilson algorithm to set priority when not sent
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] ords: Use the Wilson algorithm to set priority when not sent
- Date: Thu, 28 Jul 2016 08:47:57 +0000 (UTC)
commit 19d9b4949741323a1ed3164786ab7bbb38e51914
Author: Richard Hughes <richard hughsie com>
Date: Thu Jul 28 09:47:08 2016 +0100
ords: Use the Wilson algorithm to set priority when not sent
If the user is not sending the local data for privacy reasons we can't
calculate this server side.
src/plugins/gs-plugin-odrs.c | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/src/plugins/gs-plugin-odrs.c b/src/plugins/gs-plugin-odrs.c
index f231bdc..ddd066b 100644
--- a/src/plugins/gs-plugin-odrs.c
+++ b/src/plugins/gs-plugin-odrs.c
@@ -24,6 +24,7 @@
#include <gnome-software.h>
#include <json-glib/json-glib.h>
#include <string.h>
+#include <math.h>
/*
* SECTION:
@@ -239,8 +240,23 @@ gs_plugin_odrs_parse_review_object (GsPlugin *plugin, JsonObject *item)
/* assemble review */
if (json_object_has_member (item, "rating"))
as_review_set_rating (rev, (gint) json_object_get_int_member (item, "rating"));
- if (json_object_has_member (item, "score"))
+ if (json_object_has_member (item, "score")) {
as_review_set_priority (rev, (gint) json_object_get_int_member (item, "score"));
+ } else if (json_object_has_member (item, "karma_up") &&
+ json_object_has_member (item, "karma_down")) {
+ gdouble ku = (gdouble) json_object_get_int_member (item, "karma_up");
+ gdouble kd = (gdouble) json_object_get_int_member (item, "karma_down");
+ gdouble wilson = 0.f;
+
+ /* from http://www.evanmiller.org/how-not-to-sort-by-average-rating.html */
+ if (ku > 0 || kd > 0) {
+ wilson = ((ku + 1.9208) / (ku + kd) -
+ 1.96 * sqrt ((ku * kd) / (ku + kd) + 0.9604) /
+ (ku + kd)) / (1 + 3.8416 / (ku + kd));
+ wilson *= 100.f;
+ }
+ as_review_set_priority (rev, (gint) wilson);
+ }
if (json_object_has_member (item, "user_hash"))
as_review_set_reviewer_id (rev, json_object_get_string_member (item, "user_hash"));
if (json_object_has_member (item, "user_display"))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]