#18 -- fix percents
This commit is contained in:
parent
eb59d3684d
commit
fa3d285d83
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
|
||||
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
||||
*/
|
||||
|
||||
package ru.ulstu.extractor.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
@ -24,28 +29,11 @@ public class StatisticController {
|
||||
"Europe", "North America", "Sourth America"
|
||||
};
|
||||
|
||||
|
||||
model.addAttribute("continents", continents);
|
||||
model.addAttribute("array", new int[]{1, 2, 3});
|
||||
List<String[]> listArr = commitRepository.getCommitAuthorStatistic().stream()
|
||||
.map(stat -> new String[]{stat.getAuthor(), stat.getCountCommit().toString()})
|
||||
List<Object[]> authorCommits = commitRepository.getCommitAuthorStatistic().stream()
|
||||
.map(stat -> new Object[]{stat.getAuthor(), stat.getCountCommit()})
|
||||
.collect(Collectors.toList());
|
||||
String[][] commitAuthorData = listArr.toArray(String[][]::new);
|
||||
model.addAttribute("commitAuthorData", findPercent(commitAuthorData));
|
||||
model.addAttribute("commitAuthorData", authorCommits);
|
||||
return "statistic";
|
||||
}
|
||||
|
||||
public String[][] findPercent(String[][] commitAuthorData) {
|
||||
long sum = 0;
|
||||
for (int i = 0; i < commitAuthorData.length; i++) {
|
||||
sum = sum + Integer.parseInt(commitAuthorData[i][1]);
|
||||
}
|
||||
System.out.println(sum);
|
||||
long percent = 0;
|
||||
for (int i = 0; i < commitAuthorData.length; i++) {
|
||||
percent = Integer.parseInt(commitAuthorData[i][1]) * 100 / sum;
|
||||
commitAuthorData[i][1] = "";
|
||||
}
|
||||
return commitAuthorData;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
<!--
|
||||
~ Copyright (C) 2021 Anton Romanov - All Rights Reserved
|
||||
~ You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
||||
-->
|
||||
|
||||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
|
||||
<html
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
|
||||
@ -8,33 +13,20 @@
|
||||
</head>
|
||||
<div class="container" layout:fragment="content">
|
||||
<script src="https://www.google.com/jsapi"></script>
|
||||
<script type="text/javascript" >
|
||||
var items = [];
|
||||
/*[# th:each="n : ${items}"]*/
|
||||
items.push("[(${n})]");
|
||||
/*[/]*/
|
||||
console.log(items);
|
||||
</script>
|
||||
<script th:inline="javascript">
|
||||
|
||||
var username = [[${array}]];
|
||||
console.log(username);
|
||||
|
||||
</script>
|
||||
<script th:inline="javascript">
|
||||
google.load("visualization", "1", {packages: ["corechart"]});
|
||||
google.setOnLoadCallback(drawChart);
|
||||
|
||||
function drawChart() {
|
||||
var arr = [[${commitAuthorData}]];
|
||||
var newArray = [
|
||||
['Author','Commit']
|
||||
].concat(arr);
|
||||
var data = google.visualization.arrayToDataTable(newArray);
|
||||
var onlyCommitData = [[${commitAuthorData}]];
|
||||
var commitAuthorData = [
|
||||
['Автор','% коммитов']
|
||||
].concat(onlyCommitData);
|
||||
var data = google.visualization.arrayToDataTable(commitAuthorData);
|
||||
var options = {
|
||||
title: 'Состав воздуха',
|
||||
title: '% коммитов авторов',
|
||||
is3D: true,
|
||||
pieResidueSliceLabel: 'Остальное'
|
||||
pieResidueSliceLabel: 'Остальные'
|
||||
};
|
||||
var chart = new google.visualization.PieChart(document.getElementById('air'));
|
||||
chart.draw(data, options);
|
||||
|
Loading…
Reference in New Issue
Block a user