#18- Add CommitAuthorStatistic
This commit is contained in:
parent
fc2f0c209a
commit
c4edf5b639
@ -5,16 +5,18 @@ import org.springframework.ui.Model;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import ru.ulstu.extractor.repository.BranchRepository;
|
import ru.ulstu.extractor.repository.BranchRepository;
|
||||||
|
import ru.ulstu.extractor.repository.CommitRepository;
|
||||||
import ru.ulstu.extractor.repository.RepositoryRepository;
|
import ru.ulstu.extractor.repository.RepositoryRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class StatisticController {
|
public class StatisticController {
|
||||||
private final RepositoryRepository repositoryRepository;
|
private final CommitRepository commitRepository;
|
||||||
private final BranchRepository branchRepository;
|
|
||||||
|
|
||||||
public StatisticController(RepositoryRepository repositoryRepository, BranchRepository branchRepository) {
|
public StatisticController(CommitRepository commitRepository) {
|
||||||
this.repositoryRepository = repositoryRepository;
|
this.commitRepository = commitRepository;
|
||||||
this.branchRepository = branchRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/statistic")
|
@GetMapping("/statistic")
|
||||||
@ -28,8 +30,11 @@ public class StatisticController {
|
|||||||
|
|
||||||
model.addAttribute("continents", continents);
|
model.addAttribute("continents", continents);
|
||||||
model.addAttribute("array", new int[]{1, 2, 3});
|
model.addAttribute("array", new int[]{1, 2, 3});
|
||||||
String[][] data = new String[][] {{"Газ", "Объём"}, {"Dsdfsdf", "10"}};
|
List<String[]> listArr = commitRepository.getCommitAuthorStatistic().stream()
|
||||||
model.addAttribute("data", data);
|
.map(stat -> new String[]{stat.getAuthor(), stat.getCountCommit().toString()})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
String[][] commitAuthorData = listArr.toArray(String[][]::new);
|
||||||
|
model.addAttribute("commitAuthorData", commitAuthorData);
|
||||||
return "statistic";
|
return "statistic";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package ru.ulstu.extractor.model;
|
||||||
|
|
||||||
|
public class CommitAuthorStatistic {
|
||||||
|
private String author;
|
||||||
|
private Long countCommit;
|
||||||
|
|
||||||
|
public CommitAuthorStatistic(String author, Long countCommit) {
|
||||||
|
this.author = author;
|
||||||
|
this.countCommit = countCommit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthor() {
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCountCommit() {
|
||||||
|
return countCommit;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,9 +6,14 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.ulstu.extractor.model.Commit;
|
import ru.ulstu.extractor.model.Commit;
|
||||||
|
import ru.ulstu.extractor.model.CommitAuthorStatistic;
|
||||||
import ru.ulstu.extractor.model.Repository;
|
import ru.ulstu.extractor.model.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface CommitRepository extends JpaRepository<Commit, Integer> {
|
public interface CommitRepository extends JpaRepository<Commit, Integer> {
|
||||||
@Query("SELECT c FROM Commit c, Repository r, Branch b WHERE c.branch = b AND r = b.repository AND r = :repository AND b.name = :branchName")
|
@Query("SELECT c FROM Commit c, Repository r, Branch b WHERE c.branch = b AND r = b.repository AND r = :repository AND b.name = :branchName")
|
||||||
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName);
|
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName);
|
||||||
|
@Query("SELECT new ru.ulstu.extractor.model.CommitAuthorStatistic(c.author.name, COUNT(c)) FROM Commit c GROUP by c.author.name")
|
||||||
|
List<CommitAuthorStatistic> getCommitAuthorStatistic();
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,11 @@
|
|||||||
google.setOnLoadCallback(drawChart);
|
google.setOnLoadCallback(drawChart);
|
||||||
|
|
||||||
function drawChart() {
|
function drawChart() {
|
||||||
|
var arr = [[${commitAuthorData}]];
|
||||||
var arr = [[${data}]];
|
var newArray = [
|
||||||
var data = google.visualization.arrayToDataTable(arr);
|
['Author','Commit']
|
||||||
|
].concat(arr);
|
||||||
|
var data = google.visualization.arrayToDataTable(newArray);
|
||||||
var options = {
|
var options = {
|
||||||
title: 'Состав воздуха',
|
title: 'Состав воздуха',
|
||||||
is3D: true,
|
is3D: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user