From 1fd55407e0697462795d95484deabceb473a219d Mon Sep 17 00:00:00 2001 From: Felix Haller Date: Tue, 16 Feb 2021 16:32:30 +0100 Subject: [PATCH] PP-893: more statistics --- .../ws/model/statistics/Statistics.java | 88 +++++++++++++------ .../ws/statistics/SplunkStatisticClient.java | 17 ++++ 2 files changed, 78 insertions(+), 27 deletions(-) diff --git a/dpppt-additionalinfo-backend/src/main/java/org/dpppt/additionalinfo/backend/ws/model/statistics/Statistics.java b/dpppt-additionalinfo-backend/src/main/java/org/dpppt/additionalinfo/backend/ws/model/statistics/Statistics.java index fe5d6f5..a786f76 100644 --- a/dpppt-additionalinfo-backend/src/main/java/org/dpppt/additionalinfo/backend/ws/model/statistics/Statistics.java +++ b/dpppt-additionalinfo-backend/src/main/java/org/dpppt/additionalinfo/backend/ws/model/statistics/Statistics.java @@ -1,44 +1,78 @@ package org.dpppt.additionalinfo.backend.ws.model.statistics; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; - import org.dpppt.additionalinfo.backend.ws.json.CustomLocalDateSerializer; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - public class Statistics { - @JsonSerialize(using = CustomLocalDateSerializer.class) - private LocalDate lastUpdated; - - private Integer totalActiveUsers; - - private List history = new ArrayList(); + @JsonSerialize(using = CustomLocalDateSerializer.class) + private LocalDate lastUpdated; + + private Integer totalActiveUsers; + + private Integer totalCovidcodesEntered; + private Double totalCovidcodesEntered0to2d; + private Integer newInfectionsSevenDayAvg; + private Double newInfectionsSevenDayAvgRelPrevWeek; + + private List history = new ArrayList(); + + public Integer getTotalActiveUsers() { + return totalActiveUsers; + } + + public void setTotalActiveUsers(Integer totalActiveUsers) { + this.totalActiveUsers = totalActiveUsers; + } + + public Integer getTotalCovidcodesEntered() { + return totalCovidcodesEntered; + } + + public void setTotalCovidcodesEntered(Integer totalCovidcodesEntered) { + this.totalCovidcodesEntered = totalCovidcodesEntered; + } + + public Double getTotalCovidcodesEntered0to2d() { + return totalCovidcodesEntered0to2d; + } + + public void setTotalCovidcodesEntered0to2d(Double totalCovidcodesEntered0to2d) { + this.totalCovidcodesEntered0to2d = totalCovidcodesEntered0to2d; + } + + public Integer getNewInfectionsSevenDayAvg() { + return newInfectionsSevenDayAvg; + } - public Integer getTotalActiveUsers() { - return totalActiveUsers; - } + public void setNewInfectionsSevenDayAvg(Integer newInfectionsSevenDayAvg) { + this.newInfectionsSevenDayAvg = newInfectionsSevenDayAvg; + } - public void setTotalActiveUsers(Integer totalActiveUsers) { - this.totalActiveUsers = totalActiveUsers; - } + public Double getNewInfectionsSevenDayAvgRelPrevWeek() { + return newInfectionsSevenDayAvgRelPrevWeek; + } - public List getHistory() { - return history; - } + public void setNewInfectionsSevenDayAvgRelPrevWeek(Double newInfectionsSevenDayAvgRelPrevWeek) { + this.newInfectionsSevenDayAvgRelPrevWeek = newInfectionsSevenDayAvgRelPrevWeek; + } - public void setHistory(List history) { - this.history = history; - } + public List getHistory() { + return history; + } - public LocalDate getLastUpdated() { - return lastUpdated; - } + public void setHistory(List history) { + this.history = history; + } - public void setLastUpdated(LocalDate lastUpdated) { - this.lastUpdated = lastUpdated; - } + public LocalDate getLastUpdated() { + return lastUpdated; + } + public void setLastUpdated(LocalDate lastUpdated) { + this.lastUpdated = lastUpdated; + } } diff --git a/dpppt-additionalinfo-backend/src/main/java/org/dpppt/additionalinfo/backend/ws/statistics/SplunkStatisticClient.java b/dpppt-additionalinfo-backend/src/main/java/org/dpppt/additionalinfo/backend/ws/statistics/SplunkStatisticClient.java index 02181b1..5830208 100644 --- a/dpppt-additionalinfo-backend/src/main/java/org/dpppt/additionalinfo/backend/ws/statistics/SplunkStatisticClient.java +++ b/dpppt-additionalinfo-backend/src/main/java/org/dpppt/additionalinfo/backend/ws/statistics/SplunkStatisticClient.java @@ -197,6 +197,23 @@ private void loadPositiveTestCount(Statistics statistics) throws Exception { } StatisticHelper.calculateRollingAverage(statistics); + statistics.setTotalCovidcodesEntered(59532); // TODO replace mock data with splunk data + statistics.setTotalCovidcodesEntered0to2d(0.59576); // TODO replace mock data with splunk data + + Integer lastSevenDayAverage = null; + Integer prevWeekSevenDayAverage = null; + for (int i = statistics.getHistory().size() - 1; i > 0; i--) { + lastSevenDayAverage = statistics.getHistory().get(i).getNewInfectionsSevenDayAverage(); + if (lastSevenDayAverage != null) { + prevWeekSevenDayAverage = + statistics.getHistory().get(i - 7).getNewInfectionsSevenDayAverage(); + break; + } + } + statistics.setNewInfectionsSevenDayAvg(lastSevenDayAverage); + statistics.setNewInfectionsSevenDayAvgRelPrevWeek( + (lastSevenDayAverage / (double) prevWeekSevenDayAverage) - 1); + logger.info("Positive test count loaded"); }