Skip to content

Commit

Permalink
fix: rating average function
Browse files Browse the repository at this point in the history
Signed-off-by: Oleh Astappiev <[email protected]>
  • Loading branch information
astappiev committed Feb 22, 2024
1 parent 748fb1c commit 337ef18
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/l3s/learnweb/resource/ResourceRating.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ResourceRating implements Serializable {
private final String type;
private final HashMap<Integer, Integer> userRates = new HashMap<>();

private transient float average = -1.0f;
private transient float average = Float.NaN;

public ResourceRating(String type) {
this.type = type;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<h:panelGroup id="relevance" layout="block">
<p:rating id="star" value="#{resourceDetailBean.ratingValues['star']}" cancel="false" immediate="true"
readonly="${not empty resourceDetailBean.ratingValues['star'] or not res.canAnnotateResource(userBean.user)}">
<p:ajax event="rate" listener="#{resourceDetailBean.handleRate}" update=":relevance"/>
<p:ajax event="rate" listener="#{resourceDetailBean.handleRate}" update="@parent"/>
</p:rating>

<h:outputText value="#{res.getRatingAvg('star')}">
Expand Down

0 comments on commit 337ef18

Please sign in to comment.