[gnome-software/gnome-42: 2/3] gs-review-histogram: Use rating percentage from the app




commit d90725a3e7db8c43c688d8f9641e05cdfe8c5186
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jun 20 11:08:08 2022 +0200

    gs-review-histogram: Use rating percentage from the app
    
    Use the GsApp rating percentage instead of calculating the rating
    from the reviews, to make sure the value matches with what the GsApp
    has set. It also matches the algorithm for the rating value now.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1800

 src/gs-details-page.c     | 1 +
 src/gs-review-histogram.c | 5 ++---
 src/gs-review-histogram.h | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index dd1591087..ff5a42f23 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -1322,6 +1322,7 @@ gs_details_page_refresh_reviews (GsDetailsPage *self)
                review_ratings = gs_app_get_review_ratings (self->app);
                if (review_ratings != NULL) {
                        gs_review_histogram_set_ratings (GS_REVIEW_HISTOGRAM (self->histogram),
+                                                        gs_app_get_rating (self->app),
                                                         review_ratings);
                }
                if (review_ratings != NULL) {
diff --git a/src/gs-review-histogram.c b/src/gs-review-histogram.c
index cbd27b5a2..0b7403478 100644
--- a/src/gs-review-histogram.c
+++ b/src/gs-review-histogram.c
@@ -35,6 +35,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (GsReviewHistogram, gs_review_histogram, GTK_TYPE_WID
 
 void
 gs_review_histogram_set_ratings (GsReviewHistogram *histogram,
+                                gint rating_percent,
                                 GArray *review_ratings)
 {
        GsReviewHistogramPrivate *priv = gs_review_histogram_get_instance_private (histogram);
@@ -42,7 +43,6 @@ gs_review_histogram_set_ratings (GsReviewHistogram *histogram,
        gdouble fraction[6] = { 0.0f };
        guint32 max = 0;
        guint32 total = 0;
-       guint32 star_count = 0;
 
        g_return_if_fail (GS_IS_REVIEW_HISTOGRAM (histogram));
 
@@ -56,7 +56,6 @@ gs_review_histogram_set_ratings (GsReviewHistogram *histogram,
        for (guint i = 1; i < review_ratings->len; i++) {
                guint32 c = g_array_index (review_ratings, guint32, i);
                max = MAX (c, max);
-               star_count += i * c;
        }
        for (guint i = 1; i < review_ratings->len; i++) {
                guint32 c = g_array_index (review_ratings, guint32, i);
@@ -77,7 +76,7 @@ gs_review_histogram_set_ratings (GsReviewHistogram *histogram,
 
        /* Round explicitly, to avoid rounding inside the printf() call and to use
           the same value also for the stars fraction. */
-       fraction[0] = total > 0 ? round (((gdouble) star_count / (gdouble) total) * 10.0) / 10.0 : 0.0;
+       fraction[0] = total > 0 ? round (((gdouble) rating_percent ) * 50.0 / 100.0) / 10.0 : 0.0;
        text = g_strdup_printf ("%.01f", fraction[0]);
        gtk_label_set_text (GTK_LABEL (priv->label_value), text);
 
diff --git a/src/gs-review-histogram.h b/src/gs-review-histogram.h
index bd0fbf8bf..0e9dafcdd 100644
--- a/src/gs-review-histogram.h
+++ b/src/gs-review-histogram.h
@@ -24,6 +24,7 @@ struct _GsReviewHistogramClass
 GtkWidget      *gs_review_histogram_new                        (void);
 
 void            gs_review_histogram_set_ratings                (GsReviewHistogram *histogram,
+                                                                gint rating_percent,
                                                                 GArray *review_ratings);
 
 G_END_DECLS


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