#76-create authorTS
This commit is contained in:
parent
5e9afaaddd
commit
3b7812a075
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -269,7 +269,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());
|
||||
@ -281,6 +281,9 @@ public class GitRepositoryService {
|
||||
List<FileChange> changes = new ArrayList<>();
|
||||
String[] strings = output.split("\n");
|
||||
FileChange fileChange = new FileChange();
|
||||
boolean isAdded = false;
|
||||
boolean isRemoved = false;
|
||||
boolean isFileChanged = false;
|
||||
int stringsLength = strings.length - 1;
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
while (i < stringsLength) {
|
||||
@ -290,6 +293,8 @@ public class GitRepositoryService {
|
||||
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())));
|
||||
fileChange.setAdded(isAdded);
|
||||
fileChange.setRemoved(isRemoved);
|
||||
try {
|
||||
fileChange.setContainsBusinessLogic(futureBL.get());
|
||||
fileChange.setContainsEntity(futureEntity.get());
|
||||
@ -312,6 +317,7 @@ public class GitRepositoryService {
|
||||
lineChange.setLineFrom(lineChange.getLineFrom() + "\n" + strings[i]);
|
||||
i++;
|
||||
}
|
||||
isRemoved = true;
|
||||
}
|
||||
}
|
||||
lineChange.setRemoved(true);
|
||||
@ -328,6 +334,7 @@ public class GitRepositoryService {
|
||||
lineChange.setLineTo(lineChange.getLineTo() + "\n" + strings[i]);
|
||||
i++;
|
||||
}
|
||||
isAdded = true;
|
||||
}
|
||||
}
|
||||
lineChange.setAdded(true);
|
||||
@ -340,6 +347,13 @@ public class GitRepositoryService {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((isAdded) && (isRemoved)) {
|
||||
isAdded = false;
|
||||
isRemoved = false;
|
||||
isFileChanged = true;
|
||||
}
|
||||
fileChange.setAdded(isAdded);
|
||||
fileChange.setRemoved(isRemoved);
|
||||
return changes;
|
||||
}
|
||||
|
||||
|
@ -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,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,6 +1,10 @@
|
||||
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.service.TimeSeriesService;
|
||||
@ -11,14 +15,29 @@ 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>();
|
||||
// findSum(repositoryId,branchName);
|
||||
return new ArrayList<>();
|
||||
// return Collections.singletonList(
|
||||
// new TimeSeries(
|
||||
// String.format("",
|
||||
// gitRepositoryService.findById(repositoryId).getName(),
|
||||
// branchName,
|
||||
// getTimeSeriesType().getDescription()),
|
||||
// getTimeSeriesType(),
|
||||
// )
|
||||
// )
|
||||
// )
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,4 +49,20 @@ public class FileTS extends AbstractTimeSeriesCreator {
|
||||
public TimeSeriesType getTimeSeriesType() {
|
||||
return TimeSeriesType.FILES;
|
||||
}
|
||||
|
||||
public void findSum(Integer repositoryId, String branchName) {
|
||||
List<Commit> commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName));
|
||||
int value = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
System.out.println(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,11 @@ public class TimeSeries extends BaseEntity {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public TimeSeries(String name, TimeSeriesType timeSeriesType) {
|
||||
this.name = name;
|
||||
this.timeSeriesType = timeSeriesType;
|
||||
}
|
||||
|
||||
public TimeSeries(String name, List<TimeSeriesValue> values) {
|
||||
this.name = name;
|
||||
this.values = values;
|
||||
|
Loading…
Reference in New Issue
Block a user