#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.RequestParam;
|
||||
import ru.ulstu.extractor.repository.BranchRepository;
|
||||
import ru.ulstu.extractor.repository.CommitRepository;
|
||||
import ru.ulstu.extractor.repository.RepositoryRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Controller
|
||||
public class StatisticController {
|
||||
private final RepositoryRepository repositoryRepository;
|
||||
private final BranchRepository branchRepository;
|
||||
private final CommitRepository commitRepository;
|
||||
|
||||
public StatisticController(RepositoryRepository repositoryRepository, BranchRepository branchRepository) {
|
||||
this.repositoryRepository = repositoryRepository;
|
||||
this.branchRepository = branchRepository;
|
||||
public StatisticController(CommitRepository commitRepository) {
|
||||
this.commitRepository = commitRepository;
|
||||
}
|
||||
|
||||
@GetMapping("/statistic")
|
||||
@ -28,8 +30,11 @@ public class StatisticController {
|
||||
|
||||
model.addAttribute("continents", continents);
|
||||
model.addAttribute("array", new int[]{1, 2, 3});
|
||||
String[][] data = new String[][] {{"Газ", "Объём"}, {"Dsdfsdf", "10"}};
|
||||
model.addAttribute("data", data);
|
||||
List<String[]> listArr = commitRepository.getCommitAuthorStatistic().stream()
|
||||
.map(stat -> new String[]{stat.getAuthor(), stat.getCountCommit().toString()})
|
||||
.collect(Collectors.toList());
|
||||
String[][] commitAuthorData = listArr.toArray(String[][]::new);
|
||||
model.addAttribute("commitAuthorData", commitAuthorData);
|
||||
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.repository.query.Param;
|
||||
import ru.ulstu.extractor.model.Commit;
|
||||
import ru.ulstu.extractor.model.CommitAuthorStatistic;
|
||||
import ru.ulstu.extractor.model.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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")
|
||||
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);
|
||||
|
||||
function drawChart() {
|
||||
|
||||
var arr = [[${data}]];
|
||||
var data = google.visualization.arrayToDataTable(arr);
|
||||
var arr = [[${commitAuthorData}]];
|
||||
var newArray = [
|
||||
['Author','Commit']
|
||||
].concat(arr);
|
||||
var data = google.visualization.arrayToDataTable(newArray);
|
||||
var options = {
|
||||
title: 'Состав воздуха',
|
||||
is3D: true,
|
||||
|
Loading…
Reference in New Issue
Block a user