From 01ecc096368a901ef0f635d0d55955bd2bbd56c1 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 7 Apr 2021 15:02:35 +0400 Subject: [PATCH] #18 - Create new graphic --- build.gradle | 1 + .../controller/StatisticController.java | 7 ++++- .../repository/CommitRepository.java | 2 +- src/main/resources/templates/statistic.html | 26 +++++++++---------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index c356675..d5ab502 100644 --- a/build.gradle +++ b/build.gradle @@ -64,6 +64,7 @@ dependencies { compile group: 'org.webjars', name: 'bootstrap', version: '4.6.0' compile group: 'org.webjars', name: 'bootstrap-select', version: '1.13.8' compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0' + compile group: 'org.webjars', name: 'highcharts', version: '7.0.0' testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' } diff --git a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java index a364330..9f672d1 100644 --- a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java @@ -39,9 +39,14 @@ public class StatisticController { .collect(Collectors.toList()); model.addAttribute("commitUrlData", urlCommits); List timeCommits = commitRepository.getCommitTimeStatistic().stream() - .map(stat -> new Object[]{stat.getCountCommit(), stat.getDate()}) + .map(stat -> new Object[]{stat.getDate(), stat.getCountCommit()}) .collect(Collectors.toList()); 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("datas", date); return "statistic"; } } diff --git a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java index 5dbe4ab..6531125 100644 --- a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java +++ b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java @@ -23,7 +23,7 @@ public interface CommitRepository extends JpaRepository { @Query("SELECT new ru.ulstu.extractor.model.CommitUrlStatistic(c.branch.repository.url, COUNT(c)) FROM Commit c GROUP by c.branch.repository.url") List getCommitUrlStatistic(); - @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(cast(c.date as date), COUNT(c)) FROM Commit c GROUP by cast(c.date as date)") + @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(cast(c.date as date), COUNT(c)) FROM Commit c GROUP by cast(c.date as date) ORDER by cast(c.date as date)") List getCommitTimeStatistic(); } diff --git a/src/main/resources/templates/statistic.html b/src/main/resources/templates/statistic.html index afd1b73..d50a04b 100644 --- a/src/main/resources/templates/statistic.html +++ b/src/main/resources/templates/statistic.html @@ -18,16 +18,16 @@ google.setOnLoadCallback(drawChart); function drawChart() { - var onlyCommitData = [[${commitAuthorData}]]; - var commitAuthorData = [ - ['Автор','% коммитов'] - ].concat(onlyCommitData); + var onlyCommitData = [[${commitAuthorData}]]; + var commitAuthorData = [ + ['Автор', '% коммитов'] + ].concat(onlyCommitData); var data = google.visualization.arrayToDataTable(commitAuthorData); var options = { title: '% коммитов авторов', is3D: true, - width:600, - height:300, + width: 600, + height: 300, pieResidueSliceLabel: 'Остальные' }; var chart = new google.visualization.PieChart(document.getElementById('air')); @@ -58,9 +58,7 @@ } - - +