From 337ef18661f8f2025505f3a77fb9ef81d3c6581f Mon Sep 17 00:00:00 2001 From: Oleh Astappiev Date: Thu, 22 Feb 2024 16:22:20 +0100 Subject: [PATCH] fix: rating average function Signed-off-by: Oleh Astappiev --- src/main/java/de/l3s/learnweb/resource/ResourceRating.java | 4 ++-- .../templates/blocks/resourceview/resource_view_details.xhtml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/l3s/learnweb/resource/ResourceRating.java b/src/main/java/de/l3s/learnweb/resource/ResourceRating.java index 66c4f8d63..b12d209df 100644 --- a/src/main/java/de/l3s/learnweb/resource/ResourceRating.java +++ b/src/main/java/de/l3s/learnweb/resource/ResourceRating.java @@ -11,7 +11,7 @@ public class ResourceRating implements Serializable { private final String type; private final HashMap userRates = new HashMap<>(); - private transient float average = -1.0f; + private transient float average = Float.NaN; public ResourceRating(String type) { this.type = type; @@ -42,7 +42,7 @@ public int total() { } public float average() { - if (average < 0) { + if (Float.isNaN(average) && !userRates.isEmpty()) { int sum = 0; for (Integer rating : userRates.values()) { sum += rating; diff --git a/src/main/webapp/WEB-INF/templates/blocks/resourceview/resource_view_details.xhtml b/src/main/webapp/WEB-INF/templates/blocks/resourceview/resource_view_details.xhtml index 3048d1a88..bcae92ea0 100644 --- a/src/main/webapp/WEB-INF/templates/blocks/resourceview/resource_view_details.xhtml +++ b/src/main/webapp/WEB-INF/templates/blocks/resourceview/resource_view_details.xhtml @@ -106,7 +106,7 @@ - +