WIP: страницы для правил #62
@ -1,30 +1,39 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.ulstu.extractor.author.model.Author;
|
||||
import ru.ulstu.extractor.author.service.AuthorService;
|
||||
import ru.ulstu.extractor.branch.service.BranchService;
|
||||
import ru.ulstu.extractor.commit.model.Commit;
|
||||
import ru.ulstu.extractor.commit.service.CommitService;
|
||||
import ru.ulstu.extractor.gitrepository.model.GitRepository;
|
||||
import ru.ulstu.extractor.gitrepository.service.GitRepositoryService;
|
||||
import ru.ulstu.extractor.ts.model.TimeSeries;
|
||||
import ru.ulstu.extractor.ts.model.TimeSeriesType;
|
||||
import ru.ulstu.extractor.ts.model.TimeSeriesValue;
|
||||
import ru.ulstu.extractor.ts.service.TimeSeriesService;
|
||||
import ru.ulstu.extractor.ts.util.Dummy;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class AuthorsCommitTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
private final CommitService commitService;
|
||||
private final AuthorService authorService;
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
private final BranchService branchService;
|
||||
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public AuthorsCommitTS(TimeSeriesService timeSeriesService,
|
||||
BranchService branchService,
|
||||
GitRepositoryService gitRepositoryService) {
|
||||
CommitService commitService,
|
||||
AuthorService authorService,
|
||||
GitRepositoryService gitRepositoryService,
|
||||
BranchService branchService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.branchService = branchService;
|
||||
this.commitService = commitService;
|
||||
this.authorService = authorService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
this.branchService = branchService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,17 +43,29 @@ public class AuthorsCommitTS extends AbstractTimeSeriesCreator {
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
List<TimeSeries> timeSeriesResult = new ArrayList<>();
|
||||
List<Author> authors = authorService.findAll();
|
||||
GitRepository gitRepository = gitRepositoryService.findById(repositoryId);
|
||||
//TODO: добавить постраничное чтение
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepository.getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
branchService.findByRepositoryAndName(gitRepository, branchName),
|
||||
getTimeSeriesType(),
|
||||
Dummy.getDefaultTimeSeries()));
|
||||
List<Commit> commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName));
|
||||
for (Author author : authors) {
|
||||
TimeSeries timeSeries = new TimeSeries(
|
||||
String.format("%s %s %s %s",
|
||||
gitRepository.getName(),
|
||||
branchName,
|
||||
author.getName(),
|
||||
getTimeSeriesType().getDescription()),
|
||||
branchService.findByRepositoryAndName(gitRepository, branchName),
|
||||
getTimeSeriesType());
|
||||
for (Commit commit : commits) {
|
||||
if (commit.getAuthor().equals(author)) {
|
||||
timeSeries.getValues().add(new TimeSeriesValue(commit.getDate(), 1.0));
|
||||
}
|
||||
}
|
||||
if (!timeSeries.getValues().isEmpty()) {
|
||||
timeSeriesResult.add(timeSeries);
|
||||
}
|
||||
}
|
||||
return timeSeriesResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user