78-add-keeping-new-ts #79
@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.author.model.Author;
|
||||
import ru.ulstu.extractor.author.repository.AuthorRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@ -30,4 +31,8 @@ public class AuthorService {
|
||||
}
|
||||
return newAuthor.get();
|
||||
}
|
||||
|
||||
public List<Author> findAll() {
|
||||
return authorRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,9 @@ import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@ -269,7 +271,7 @@ public class GitRepositoryService {
|
||||
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
DiffFormatter diffFormatter = new DiffFormatter(out);
|
||||
diffFormatter.setRepository(localRepo);
|
||||
diffFormatter.format(earlierCommit.getId(), laterCommit.getId());
|
||||
diffFormatter.format(laterCommit.getId(), earlierCommit.getId());
|
||||
output = out.toString();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Error occurred during diff computation. Message: " + e.getMessage());
|
||||
@ -280,65 +282,21 @@ public class GitRepositoryService {
|
||||
private List<FileChange> parseOutputDiff(String output, org.eclipse.jgit.lib.Repository repository, RevCommit commit) {
|
||||
List<FileChange> changes = new ArrayList<>();
|
||||
String[] strings = output.split("\n");
|
||||
FileChange fileChange = new FileChange();
|
||||
int stringsLength = strings.length - 1;
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
while (i < stringsLength) {
|
||||
Optional<String> maybeFileName = getFileName(strings[i]);
|
||||
if (maybeFileName.isPresent()) {
|
||||
fileChange = new FileChange();
|
||||
fileChange.setFile(maybeFileName.get());
|
||||
Future<Boolean> futureEntity = executorService.submit(() -> structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get())));
|
||||
Future<Boolean> futureBL = executorService.submit(() -> structuralUnitService.containsBusinessLogic(getContent(repository, commit, maybeFileName.get())));
|
||||
try {
|
||||
fileChange.setContainsBusinessLogic(futureBL.get());
|
||||
fileChange.setContainsEntity(futureEntity.get());
|
||||
} catch (Exception ex) {
|
||||
LOG.warn(ex.getMessage());
|
||||
}
|
||||
/// вытащить другие изменения из коммита
|
||||
changes.add(fileChange);
|
||||
}
|
||||
LineChange lineChange = new LineChange();
|
||||
if (strings[i].startsWith("-")) {
|
||||
while ((i < stringsLength) && strings[i].startsWith("-")) {
|
||||
if (strings[i].startsWith("---")) {
|
||||
i++;
|
||||
} else {
|
||||
if (lineChange.getLineFrom() == null) {
|
||||
lineChange.setLineFrom(strings[i]);
|
||||
i++;
|
||||
} else {
|
||||
lineChange.setLineFrom(lineChange.getLineFrom() + "\n" + strings[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
lineChange.setRemoved(true);
|
||||
}
|
||||
if (strings[i].startsWith("+")) {
|
||||
while ((i < stringsLength) && strings[i].startsWith("+")) {
|
||||
if (strings[i].startsWith("+++")) {
|
||||
i++;
|
||||
} else {
|
||||
if (lineChange.getLineTo() == null) {
|
||||
lineChange.setLineTo(strings[i]);
|
||||
i++;
|
||||
} else {
|
||||
lineChange.setLineTo(lineChange.getLineTo() + "\n" + strings[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
lineChange.setAdded(true);
|
||||
}
|
||||
if ((lineChange.getLineTo() != null) || (lineChange.getLineFrom() != null)
|
||||
|| ((lineChange.getLineTo() != null) && (lineChange.getLineFrom() != null))) {
|
||||
fileChange.getLineChanges().add(lineChange);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
Map<String, List<String>> filesContent = getFilesContent(strings);
|
||||
System.out.println(filesContent);
|
||||
for(Map.Entry<String, List<String>> fileSterings: filesContent.entrySet()) {
|
||||
FileChange fileChange = new FileChange();
|
||||
fileChange.setFile(fileSterings.getKey());
|
||||
Future<Boolean> futureEntity = executorService.submit(() -> structuralUnitService.containsEntity(getContent(repository, commit, fileSterings.getKey())));
|
||||
Future<Boolean> futureBL = executorService.submit(() -> structuralUnitService.containsBusinessLogic(getContent(repository, commit, fileSterings.getKey())));
|
||||
try {
|
||||
fileChange.setContainsBusinessLogic(futureBL.get());
|
||||
fileChange.setContainsEntity(futureEntity.get());
|
||||
} catch (Exception ex) {
|
||||
LOG.warn(ex.getMessage());
|
||||
}
|
||||
fileChange = getChange(fileChange, fileSterings.getValue());
|
||||
changes.add(fileChange);
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
@ -368,6 +326,101 @@ public class GitRepositoryService {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Map<String, List<String>> getFilesContent(String[] commitStrings) {
|
||||
int i = 0;
|
||||
Map<String, List<String>> result = new HashMap<>();
|
||||
while (i < commitStrings.length) {
|
||||
Optional<String> maybeFileName = getFileName(commitStrings[i]);
|
||||
if (maybeFileName.isEmpty()) {
|
||||
i++;
|
||||
} else {
|
||||
i = skipLinesForNextFile(commitStrings, i);
|
||||
result.put(maybeFileName.get(), getFileContent(commitStrings, i));
|
||||
i += getFileContent(commitStrings, i).size() - 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<String> getFileContent(String[] commitsString, int i) {
|
||||
List<String> result = new ArrayList<>();
|
||||
while (i < commitsString.length && getFileName(commitsString[i]).isEmpty()) {
|
||||
result.add(commitsString[i]);
|
||||
i++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int skipLinesForNextFile(String[] commitStrings, int index) {
|
||||
boolean isFilePrefixSkipped = false;
|
||||
while (!isFilePrefixSkipped && (index < commitStrings.length)) {
|
||||
if ((commitStrings[index].startsWith("diff --git a/"))
|
||||
|| (commitStrings[index].startsWith("delete"))
|
||||
|| (commitStrings[index].startsWith("new"))
|
||||
|| (commitStrings[index].startsWith("index"))
|
||||
|| (commitStrings[index].startsWith("@@"))
|
||||
|| (commitStrings[index].startsWith("---"))
|
||||
|| (commitStrings[index].startsWith("+++"))) {
|
||||
index++;
|
||||
} else {
|
||||
isFilePrefixSkipped = true;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
private FileChange getChange(FileChange fileChange, List<String> fileContent){
|
||||
int addedLine = 0;
|
||||
int removedLine = 0;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
boolean isRemoved = false;
|
||||
boolean isAdded = false;
|
||||
for (String line : fileContent){
|
||||
LineChange lineChange = new LineChange();
|
||||
if (line.startsWith("-")){
|
||||
isRemoved = true;
|
||||
if (isAdded) {
|
||||
isAdded = false;
|
||||
lineChange = setAdded(lineChange, builder);
|
||||
builder.setLength(0);
|
||||
}
|
||||
builder.append(line).append("\n");
|
||||
removedLine++;
|
||||
} else if(line.startsWith("+")){
|
||||
isAdded = true;
|
||||
if (isRemoved) {
|
||||
isRemoved = false;
|
||||
lineChange = setRemoved(lineChange, builder);
|
||||
builder.setLength(0);
|
||||
}
|
||||
builder.append(line).append("\n");
|
||||
addedLine++;
|
||||
} else {
|
||||
if (isRemoved) {
|
||||
lineChange = setRemoved(lineChange, builder);
|
||||
builder.setLength(0);
|
||||
} else if (isAdded){
|
||||
lineChange = setAdded(lineChange, builder);
|
||||
builder.setLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
fileChange.setRemoved(removedLine == fileContent.size() - 1);
|
||||
fileChange.setAdded(addedLine == fileContent.size() - 1);
|
||||
return fileChange;
|
||||
}
|
||||
|
||||
private LineChange setRemoved(LineChange lineChange, StringBuilder builder){
|
||||
lineChange.setLineFrom(builder.toString());
|
||||
lineChange.setRemoved(true);
|
||||
return lineChange;
|
||||
}
|
||||
|
||||
private LineChange setAdded(LineChange lineChange, StringBuilder builder){
|
||||
lineChange.setLineTo(builder.toString());
|
||||
lineChange.setAdded(true);
|
||||
return lineChange;
|
||||
}
|
||||
public Page<GitRepository> findAll(Pageable pageable) {
|
||||
return gitRepositoryRepository.findAll(pageable);
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
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.commit.service.CommitService;
|
||||
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 java.util.ArrayList;
|
||||
@ -11,9 +16,17 @@ import java.util.List;
|
||||
@Component
|
||||
public class AuthorTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
private final CommitService commitService;
|
||||
private final AuthorService authorService;
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public AuthorTS(TimeSeriesService timeSeriesService) {
|
||||
public AuthorTS(TimeSeriesService timeSeriesService,
|
||||
CommitService commitService,
|
||||
AuthorService authorService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.commitService = commitService;
|
||||
this.authorService = authorService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -23,7 +36,27 @@ public class AuthorTS extends AbstractTimeSeriesCreator {
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<>();
|
||||
List<TimeSeries> timeSeriesResult = new ArrayList<>();
|
||||
List<Author> authors = authorService.findAll();
|
||||
List<ru.ulstu.extractor.model.Commit> commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName));
|
||||
for (Author author : authors) {
|
||||
TimeSeries timeSeries = new TimeSeries(
|
||||
String.format("%s %s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
author.getName(),
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType());
|
||||
for (ru.ulstu.extractor.model.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
|
||||
|
@ -1,19 +1,24 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
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.service.TimeSeriesService;
|
||||
import ru.ulstu.extractor.ts.util.Dummy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class AuthorsCommitTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
|
||||
public AuthorsCommitTS(TimeSeriesService timeSeriesService) {
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public AuthorsCommitTS(TimeSeriesService timeSeriesService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -23,7 +28,14 @@ public class AuthorsCommitTS extends AbstractTimeSeriesCreator {
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<TimeSeries>();
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType(),
|
||||
Dummy.getDefaultTimeSeries()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,24 +1,37 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
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.service.TimeSeriesService;
|
||||
import ru.ulstu.extractor.ts.util.Dummy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class AuthorsCompletedIssueTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
|
||||
public AuthorsCompletedIssueTS(TimeSeriesService timeSeriesService) {
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public AuthorsCompletedIssueTS(TimeSeriesService timeSeriesService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<>();
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType(),
|
||||
Dummy.getDefaultTimeSeries()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,24 +1,36 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
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.service.TimeSeriesService;
|
||||
import ru.ulstu.extractor.ts.util.Dummy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class AuthorsIssueTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
|
||||
public AuthorsIssueTS(TimeSeriesService timeSeriesService) {
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public AuthorsIssueTS(TimeSeriesService timeSeriesService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<TimeSeries>();
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType(),
|
||||
Dummy.getDefaultTimeSeries()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,19 +1,24 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
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.service.TimeSeriesService;
|
||||
import ru.ulstu.extractor.ts.util.Dummy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class BranchTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
|
||||
public BranchTS(TimeSeriesService timeSeriesService) {
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public BranchTS(TimeSeriesService timeSeriesService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -23,7 +28,14 @@ public class BranchTS extends AbstractTimeSeriesCreator {
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<>();
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType(),
|
||||
Dummy.getDefaultTimeSeries()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,24 +1,36 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
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.service.TimeSeriesService;
|
||||
import ru.ulstu.extractor.ts.util.Dummy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ClassTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
|
||||
public ClassTS(TimeSeriesService timeSeriesService) {
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public ClassTS(TimeSeriesService timeSeriesService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<TimeSeries>();
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType(),
|
||||
Dummy.getDefaultTimeSeries()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,24 +1,36 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
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.service.TimeSeriesService;
|
||||
import ru.ulstu.extractor.ts.util.Dummy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class DependenceTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
|
||||
public DependenceTS(TimeSeriesService timeSeriesService) {
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public DependenceTS(TimeSeriesService timeSeriesService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<TimeSeries>();
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType(),
|
||||
Dummy.getDefaultTimeSeries()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,24 +1,45 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.ulstu.extractor.commit.service.CommitService;
|
||||
import ru.ulstu.extractor.gitrepository.model.FileChange;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class EntityTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
private final CommitService commitService;
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public EntityTS(TimeSeriesService timeSeriesService) {
|
||||
|
||||
public EntityTS(TimeSeriesService timeSeriesService, CommitService commitService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.commitService = commitService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<TimeSeries>();
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType(),
|
||||
commitService.findByRepositoryIdAndName(repositoryId, branchName)
|
||||
.stream()
|
||||
.map(c -> new TimeSeriesValue(c.getDate(), findEntity(repositoryId, branchName)))
|
||||
.collect(Collectors.toList())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,4 +51,17 @@ public class EntityTS extends AbstractTimeSeriesCreator {
|
||||
public TimeSeriesType getTimeSeriesType() {
|
||||
return TimeSeriesType.ENTITIES;
|
||||
}
|
||||
|
||||
public Double findEntity(Integer repositoryId, String branchName) {
|
||||
List<ru.ulstu.extractor.model.Commit> commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName));
|
||||
double value = 0;
|
||||
for (ru.ulstu.extractor.model.Commit commit : commits) {
|
||||
for (FileChange fileChange : commit.getFileChanges()) {
|
||||
if ((fileChange.getContainsEntity() != null) && (fileChange.getContainsEntity())) {
|
||||
value = value + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.ulstu.extractor.commit.service.CommitService;
|
||||
import ru.ulstu.extractor.gitrepository.model.FileChange;
|
||||
import ru.ulstu.extractor.gitrepository.service.GitRepositoryService;
|
||||
import ru.ulstu.extractor.model.Commit;
|
||||
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 java.util.ArrayList;
|
||||
@ -11,14 +16,41 @@ import java.util.List;
|
||||
@Component
|
||||
public class FileTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
private final CommitService commitService;
|
||||
|
||||
public FileTS(TimeSeriesService timeSeriesService) {
|
||||
public FileTS(TimeSeriesService timeSeriesService, GitRepositoryService gitRepositoryService, CommitService commitService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
this.commitService = commitService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<TimeSeries>();
|
||||
List<TimeSeries> timeSeriesResult = new ArrayList<>();
|
||||
List<Commit> commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName));
|
||||
double value = 0;
|
||||
TimeSeries timeSeries = new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType());
|
||||
for (Commit commit : commits) {
|
||||
for (FileChange fileChange : commit.getFileChanges()) {
|
||||
if ((fileChange.getAdded() != null) && (fileChange.getAdded())) {
|
||||
value += 1;
|
||||
}
|
||||
if ((fileChange.getRemoved() != null) && (fileChange.getRemoved())) {
|
||||
value -= 1;
|
||||
}
|
||||
}
|
||||
timeSeries.getValues().add(new TimeSeriesValue(commit.getDate(), value));
|
||||
}
|
||||
if (!timeSeries.getValues().isEmpty()) {
|
||||
timeSeriesResult.add(timeSeries);
|
||||
}
|
||||
return timeSeriesResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,24 +1,36 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
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.service.TimeSeriesService;
|
||||
import ru.ulstu.extractor.ts.util.Dummy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class InterfaceTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
|
||||
public InterfaceTS(TimeSeriesService timeSeriesService) {
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public InterfaceTS(TimeSeriesService timeSeriesService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<TimeSeries>();
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType(),
|
||||
Dummy.getDefaultTimeSeries()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,24 +1,36 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
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.service.TimeSeriesService;
|
||||
import ru.ulstu.extractor.ts.util.Dummy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class IssuesTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
|
||||
public IssuesTS(TimeSeriesService timeSeriesService) {
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public IssuesTS(TimeSeriesService timeSeriesService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<>();
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType(),
|
||||
Dummy.getDefaultTimeSeries()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,24 +1,36 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
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.service.TimeSeriesService;
|
||||
import ru.ulstu.extractor.ts.util.Dummy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ProcessTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
|
||||
public ProcessTS(TimeSeriesService timeSeriesService) {
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public ProcessTS(TimeSeriesService timeSeriesService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<>();
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType(),
|
||||
Dummy.getDefaultTimeSeries()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,24 +1,37 @@
|
||||
package ru.ulstu.extractor.ts.creator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
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.service.TimeSeriesService;
|
||||
import ru.ulstu.extractor.ts.util.Dummy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class StarTS extends AbstractTimeSeriesCreator {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
|
||||
public StarTS(TimeSeriesService timeSeriesService) {
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public StarTS(TimeSeriesService timeSeriesService, GitRepositoryService gitRepositoryService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||
return new ArrayList<>();
|
||||
return Collections.singletonList(
|
||||
new TimeSeries(
|
||||
String.format("%s %s %s",
|
||||
gitRepositoryService.findById(repositoryId).getName(),
|
||||
branchName,
|
||||
getTimeSeriesType().getDescription()),
|
||||
getTimeSeriesType(),
|
||||
Dummy.getDefaultTimeSeries()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
13
src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java
Normal file
13
src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java
Normal file
@ -0,0 +1,13 @@
|
||||
package ru.ulstu.extractor.ts.util;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
public class DateUtils {
|
||||
public static Date addMonths(int amount) {
|
||||
Calendar c = GregorianCalendar.getInstance();
|
||||
c.add(Calendar.DAY_OF_MONTH, amount);
|
||||
return c.getTime();
|
||||
}
|
||||
}
|
15
src/main/java/ru/ulstu/extractor/ts/util/Dummy.java
Normal file
15
src/main/java/ru/ulstu/extractor/ts/util/Dummy.java
Normal file
@ -0,0 +1,15 @@
|
||||
package ru.ulstu.extractor.ts.util;
|
||||
|
||||
import ru.ulstu.extractor.ts.model.TimeSeriesValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Dummy {
|
||||
public static List<TimeSeriesValue> getDefaultTimeSeries (){
|
||||
return List.of(new TimeSeriesValue(DateUtils.addMonths(-5), 1.0),
|
||||
new TimeSeriesValue(DateUtils.addMonths(-4), 2.0),
|
||||
new TimeSeriesValue(DateUtils.addMonths(-3), 3.0),
|
||||
new TimeSeriesValue(DateUtils.addMonths(-2), 4.0),
|
||||
new TimeSeriesValue(DateUtils.addMonths(-1), 5.0));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user