From 4072c7c3890a6629ab6a96830481716898972028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Oliva?= Date: Mon, 29 May 2023 22:52:44 -0600 Subject: Getting average of time to complete tasks. Not as good as expected. But I don't have time anymore. :'( It appears as if the milliseconds are not converted into seconds and minutes properly. Will have to see this in depth. --- src/main/java/com/encora/ToDosRepository.java | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/main/java/com/encora/ToDosRepository.java') diff --git a/src/main/java/com/encora/ToDosRepository.java b/src/main/java/com/encora/ToDosRepository.java index c4bdcba..9333cd9 100644 --- a/src/main/java/com/encora/ToDosRepository.java +++ b/src/main/java/com/encora/ToDosRepository.java @@ -201,6 +201,39 @@ public class ToDosRepository implements JpaRepository { return this.filteredToDos; } + public Double getAverageCompletingTime(String priority) { + List recordedTimes = new ArrayList<>(); + + if (priority.equalsIgnoreCase("all")) { + for (ToDos todo : this.todos) { + if (!todo.isDone()) { + continue; + } + recordedTimes.add( + (double) (todo.getDoneDate().getTime() - todo.getCreationDate().getTime()) + ); + } + } else { + for (ToDos todo : this.todos) { + if (!todo.isDone() || !Objects.equals(String.valueOf(todo.getPriority()), priority)) { + continue; + } + recordedTimes.add( + (double) (todo.getDoneDate().getTime() - todo.getCreationDate().getTime()) + ); + } + } + + if (recordedTimes.size() == 0) { + return (double) 0; + } + Double valuesSum = (double) 0; + for (Double d : recordedTimes) { + valuesSum += d; + } + return valuesSum / (double) recordedTimes.size(); + } + /* * N O T Y E T D E F I N E D . */ -- cgit v1.2.3