#18 - Find percent
This commit is contained in:
parent
c4edf5b639
commit
eb59d3684d
@ -3,10 +3,7 @@ package ru.ulstu.extractor.controller;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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;
|
||||
@ -34,7 +31,21 @@ public class StatisticController {
|
||||
.map(stat -> new String[]{stat.getAuthor(), stat.getCountCommit().toString()})
|
||||
.collect(Collectors.toList());
|
||||
String[][] commitAuthorData = listArr.toArray(String[][]::new);
|
||||
model.addAttribute("commitAuthorData", commitAuthorData);
|
||||
model.addAttribute("commitAuthorData", findPercent(commitAuthorData));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user