#18 - Find percent

This commit is contained in:
Anton Romanov 2021-04-05 12:19:51 +04:00
parent c4edf5b639
commit eb59d3684d

View File

@ -3,10 +3,7 @@ package ru.ulstu.extractor.controller;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; 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 ru.ulstu.extractor.repository.BranchRepository;
import ru.ulstu.extractor.repository.CommitRepository; import ru.ulstu.extractor.repository.CommitRepository;
import ru.ulstu.extractor.repository.RepositoryRepository;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -34,7 +31,21 @@ public class StatisticController {
.map(stat -> new String[]{stat.getAuthor(), stat.getCountCommit().toString()}) .map(stat -> new String[]{stat.getAuthor(), stat.getCountCommit().toString()})
.collect(Collectors.toList()); .collect(Collectors.toList());
String[][] commitAuthorData = listArr.toArray(String[][]::new); String[][] commitAuthorData = listArr.toArray(String[][]::new);
model.addAttribute("commitAuthorData", commitAuthorData); model.addAttribute("commitAuthorData", findPercent(commitAuthorData));
return "statistic"; 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;
}
} }