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/Main.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/main/java/com/encora/Main.java') diff --git a/src/main/java/com/encora/Main.java b/src/main/java/com/encora/Main.java index ea3a2a4..368fa29 100644 --- a/src/main/java/com/encora/Main.java +++ b/src/main/java/com/encora/Main.java @@ -6,6 +6,8 @@ import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.*; @SpringBootApplication @@ -233,4 +235,27 @@ public class Main { final int pageSize = 10; return (int) Math.ceil((double) toDosRepository.filteredToDos.size() / pageSize); } + + + // Return the average time on completing to dos. + @CrossOrigin(origins=allowed_origin) + @GetMapping("/todos/average/{priority}") + @ResponseStatus(value=HttpStatus.OK) + public String getAverageTime(@PathVariable("priority") String priority) { + String result = ""; + Double milliseconds = toDosRepository.getAverageCompletingTime(priority); + + if (milliseconds > 86400000) { + // More than a day. + Integer days = (int) (milliseconds / 86400000); + result += String.valueOf(days) + " days, "; + } + + // Convert the milliseconds into an hour, minute, second and + // millisecond format. + DateFormat simple = new SimpleDateFormat("HH:mm:ss:SSS"); + simple.setTimeZone(TimeZone.getTimeZone("GMT")); + + return result + simple.format(milliseconds); + } } -- cgit v1.2.3