#18 - Create column table

This commit is contained in:
Anton Romanov 2021-04-05 15:06:27 +04:00
parent 41efe3b3f4
commit 6c89e67ac7
4 changed files with 131 additions and 12 deletions

View File

@ -34,6 +34,10 @@ public class StatisticController {
.map(stat -> new Object[]{stat.getAuthor(), stat.getCountCommit()}) .map(stat -> new Object[]{stat.getAuthor(), stat.getCountCommit()})
.collect(Collectors.toList()); .collect(Collectors.toList());
model.addAttribute("commitAuthorData", authorCommits); model.addAttribute("commitAuthorData", authorCommits);
List<Object[]> urlCommits = commitRepository.getCommitUrlStatistic().stream()
.map(stat -> new Object[]{stat.getUrl(), stat.getCountCommit()})
.collect(Collectors.toList());
model.addAttribute("commitUrlData", urlCommits);
return "statistic"; return "statistic";
} }
} }

View File

@ -0,0 +1,20 @@
package ru.ulstu.extractor.model;
public class CommitUrlStatistic {
private String url;
private Long countCommit;
public CommitUrlStatistic(String url, Long countCommit) {
this.url = url;
this.countCommit = countCommit;
}
public String getUrl() {
return url;
}
public Long getCountCommit() {
return countCommit;
}
}

View File

@ -7,6 +7,7 @@ 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.CommitAuthorStatistic;
import ru.ulstu.extractor.model.CommitUrlStatistic;
import ru.ulstu.extractor.model.Repository; import ru.ulstu.extractor.model.Repository;
import java.util.List; import java.util.List;
@ -14,6 +15,10 @@ 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") @Query("SELECT new ru.ulstu.extractor.model.CommitAuthorStatistic(c.author.name, COUNT(c)) FROM Commit c GROUP by c.author.name")
List<CommitAuthorStatistic> getCommitAuthorStatistic(); List<CommitAuthorStatistic> getCommitAuthorStatistic();
@Query("SELECT new ru.ulstu.extractor.model.CommitUrlStatistic(c.branch.repository.url, COUNT(c)) FROM Commit c GROUP by c.branch.repository.url")
List<CommitUrlStatistic> getCommitUrlStatistic();
} }

View File

@ -34,32 +34,122 @@
chart.draw(data, options); chart.draw(data, options);
} }
</script> </script>
<script> <script th:inline="javascript">
google.load("visualization", "1", {packages: ["corechart"]}); google.load("visualization", "1", {packages: ["corechart"]});
google.setOnLoadCallback(drawChart); google.setOnLoadCallback(drawChart);
function drawChart() { function drawChart() {
var data = google.visualization.arrayToDataTable([ var onlyCommitUrlData = [[${commitUrlData}]];
['Год', 'Россия', 'США'], var commitUrlData = [
['1860', 1.3, 70], ['Url', 'Коммиты']
['1885', 2000, 3120], ].concat(onlyCommitUrlData);
['1901', 12170, 9920] var data = google.visualization.arrayToDataTable(commitUrlData);
]);
var options = { var options = {
title: 'Добыча нефти', title: 'Количество коммитов',
hAxis: {title: 'Год'}, hAxis: {title: 'Url'},
vAxis: {title: 'Тыс. тонн', vAxis: {
width:600, title: 'Кол-во',
height:300} width: 600,
height: 300
}
}; };
var chart = new google.visualization.ColumnChart(document.getElementById('oil')); var chart = new google.visualization.ColumnChart(document.getElementById('oil'));
chart.draw(data, options); chart.draw(data, options);
} }
</script> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script language="JavaScript">
$(document).ready(function () {
var chart = {
type: 'scatter',
zoomType: 'xy'
};
var title = {
text: 'Height Versus Weight of Individuals'
};
var xAxis = {
title: {
enabled: true,
text: 'Height (cm)'
},
startOnTick: true,
endOnTick: true,
showLastLabel: true
};
var yAxis = {
title: {
text: 'Weight (kg)'
}
};
var plotOptions = {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x} cm, {point.y} kg'
}
}
};
var series = [
{
name: 'Male',
color: 'rgba(119, 152, 191, .5)',
data: [[174.0, 65.6], [175.3, 71.8], [193.5, 80.7], [186.5, 72.6],
[172.7, 75.3], [182.2, 87.1], [164.1, 55.2], [163.0, 57.0],
[167.4, 67.7], [181.1, 66.0], [177.0, 68.2], [174.5, 63.9],
[177.5, 72.0], [170.5, 56.8], [182.4, 74.5], [197.1, 90.9],
[180.1, 93.0], [175.5, 80.9], [180.6, 72.7], [184.4, 68.0],
[175.5, 70.9], [180.6, 72.5], [177.0, 72.5], [177.1, 83.4],
[184.9, 86.4], [177.3, 73.2], [167.4, 53.9], [178.1, 72.0],
[168.9, 55.5], [157.2, 58.4], [180.3, 83.2], [170.2, 72.7],
[177.8, 64.1], [172.7, 72.3], [165.1, 65.0], [186.7, 86.4],
[165.1, 65.0], [174.0, 88.6], [175.3, 84.1], [185.4, 66.8],
[177.8, 75.5], [180.3, 93.2], [180.3, 82.7], [177.8, 58.0],
[163.8, 72.2], [188.0, 83.6], [198.1, 85.5], [175.3, 90.9],
[166.4, 85.9], [190.5, 89.1], [166.4, 75.0], [177.8, 77.7],
[179.7, 86.4], [172.7, 90.9], [190.5, 73.6], [185.4, 76.4],
[168.9, 69.1], [167.6, 84.5], [175.3, 64.5], [170.2, 69.1],
[171.4, 72.7], [172.7, 84.1], [172.7, 76.8], [177.8, 63.6],
[177.8, 80.9], [182.9, 80.9], [170.2, 85.5], [167.6, 68.6],
[172.7, 95.9], [190.5, 84.1], [179.1, 87.3], [175.3, 71.8],
[170.2, 65.9], [193.0, 95.9], [171.4, 91.4], [177.8, 81.8],
[177.8, 96.8], [167.6, 69.1], [167.6, 82.7], [180.3, 75.5]
]
}
];
var json = {};
json.chart = chart;
json.title = title;
json.xAxis = xAxis;
json.yAxis = yAxis;
json.series = series;
json.plotOptions = plotOptions;
$('#container').highcharts(json);
});
</script>
<div class="row"> <div class="row">
<div id="air" class="col-sm-12 col-lg-6" style="width: 200px"></div> <div id="air" class="col-sm-12 col-lg-6" style="width: 200px"></div>
<div id="oil" class="col-sm-12 col-lg-6" style="width: 200px"></div> <div id="oil" class="col-sm-12 col-lg-6" style="width: 200px"></div>
<div id="container" style="width: 550px; height: 400px; margin: 0 auto"></div>
</div> </div>
</div> </div>
</html> </html>