From 49e906c1903cd3e1a1ed34f866e26b8d1bd56aaf Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 29 Apr 2021 16:19:27 +0400 Subject: [PATCH] #27 -- fix statistic --- .../controller/StatisticController.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java index 5bd3c6f..7fb2629 100644 --- a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java @@ -27,19 +27,20 @@ public class StatisticController { @GetMapping(STATISTIC) public String indexBranch(Model model) { + List urlCommits = getUrlCommits(); + List timeCommits = getTimeCommits(); model.addAttribute("commitAuthorData", authorCommits()); - model.addAttribute("commitUrlData", urlCommits()); - model.addAttribute("commitTimeData", timeCommits()); - String[] date = new String[timeCommits().size()]; - for (int i = 0; i < timeCommits().size(); i++) { - date[i] = timeCommits().get(i)[0].toString(); - } - model.addAttribute("dates", date); - String[] url = new String[urlCommits().size()]; - for (int i = 0; i < urlCommits().size(); i++) { - url[i] = urlCommits().get(i)[0].toString().substring(urlCommits().get(i)[0].toString().lastIndexOf("/") + 1); - } - model.addAttribute("urls", url); + model.addAttribute("commitUrlData", urlCommits); + model.addAttribute("commitTimeData", timeCommits); + List dates = timeCommits.stream() + .map(tc -> tc[0].toString()) + .collect(Collectors.toList()); + model.addAttribute("dates", dates); + + List urls = urlCommits.stream() + .map(tc -> tc[0].toString().substring(tc[0].toString().lastIndexOf("/") + 1)) + .collect(Collectors.toList()); + model.addAttribute("urls", urls); model.addAttribute("commitEntityData", entityCommits()); model.addAttribute("commitTimeEntityData", allTimeEntityCommits()); return STATISTIC; @@ -52,14 +53,14 @@ public class StatisticController { return authorCommits; } - public List urlCommits() { + public List getUrlCommits() { List urlCommits = commitRepository.getCommitUrlStatistic().stream() .map(stat -> new Object[]{stat.getUrl(), stat.getCountCommit()}) .collect(Collectors.toList()); return urlCommits; } - public List timeCommits() { + public List getTimeCommits() { List timeCommits = commitRepository.getCommitTimeStatistic().stream() .map(stat -> new Object[]{stat.getDate(), stat.getCountCommit()}) .collect(Collectors.toList());