From 3b7812a075919ab41d215f9a5dcd0356de85ed4e Mon Sep 17 00:00:00 2001 From: BarminaA Date: Sat, 5 Nov 2022 17:58:21 +0400 Subject: [PATCH 1/4] #76-create authorTS --- .../author/service/AuthorService.java | 5 +++ .../service/GitRepositoryService.java | 16 +++++++- .../ulstu/extractor/ts/creator/AuthorTS.java | 37 +++++++++++++++++- .../ulstu/extractor/ts/creator/EntityTS.java | 38 +++++++++++++++++- .../ru/ulstu/extractor/ts/creator/FileTS.java | 39 ++++++++++++++++++- .../ulstu/extractor/ts/model/TimeSeries.java | 5 +++ 6 files changed, 133 insertions(+), 7 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/author/service/AuthorService.java b/src/main/java/ru/ulstu/extractor/author/service/AuthorService.java index 659e17c..ce80869 100644 --- a/src/main/java/ru/ulstu/extractor/author/service/AuthorService.java +++ b/src/main/java/ru/ulstu/extractor/author/service/AuthorService.java @@ -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 findAll() { + return authorRepository.findAll(); + } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java index 78038ad..b08f1d9 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java @@ -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 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 futureEntity = executorService.submit(() -> structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get()))); Future 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; } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java index ae71399..b1c41fb 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java @@ -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 getTimeSeries(Integer repositoryId, String branchName) { - return new ArrayList<>(); + List timeSeriesResult = new ArrayList<>(); + List authors = authorService.findAll(); + List 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 diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java index c635556..946d9ac 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java @@ -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 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(), + 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 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; + } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java index 5797212..27e3453 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java @@ -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 getTimeSeries(Integer repositoryId, String branchName) { - return new ArrayList(); +// 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 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); + } + } } diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java index b6d6931..7a810da 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java @@ -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 values) { this.name = name; this.values = values; -- 2.34.1 From 4de0e379024e201cf3a155ed978b3fab06770786 Mon Sep 17 00:00:00 2001 From: alexandra Date: Mon, 21 Nov 2022 13:42:15 +0400 Subject: [PATCH 2/4] #78 - Add FileTS --- .../service/GitRepositoryService.java | 187 +++++++++++------- .../ru/ulstu/extractor/ts/creator/FileTS.java | 53 +++-- 2 files changed, 136 insertions(+), 104 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java index b08f1d9..fb0a3eb 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java @@ -30,6 +30,7 @@ import ru.ulstu.extractor.heuristic.model.ResourceUnit; import ru.ulstu.extractor.heuristic.service.StructuralUnitService; import ru.ulstu.extractor.model.Commit; +import javax.swing.text.html.parser.Entity; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -39,10 +40,7 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.time.Instant; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -280,80 +278,22 @@ public class GitRepositoryService { private List parseOutputDiff(String output, org.eclipse.jgit.lib.Repository repository, RevCommit commit) { List 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) { - Optional maybeFileName = getFileName(strings[i]); - if (maybeFileName.isPresent()) { - fileChange = new FileChange(); - fileChange.setFile(maybeFileName.get()); - Future futureEntity = executorService.submit(() -> structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get()))); - Future 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()); - } 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++; - } - isRemoved = true; - } - } - 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++; - } - isAdded = true; - } - } - lineChange.setAdded(true); - } - if ((lineChange.getLineTo() != null) || (lineChange.getLineFrom() != null) - || ((lineChange.getLineTo() != null) && (lineChange.getLineFrom() != null))) { - fileChange.getLineChanges().add(lineChange); - } else { - i++; - } + Map> filesContent = getFilesContent(strings); + System.out.println(filesContent); + for(Map.Entry> fileSterings: filesContent.entrySet()) { + FileChange fileChange = new FileChange(); + fileChange.setFile(fileSterings.getKey()); + Future futureEntity = executorService.submit(() -> structuralUnitService.containsEntity(getContent(repository, commit, fileSterings.getKey()))); + Future 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); } - if ((isAdded) && (isRemoved)) { - isAdded = false; - isRemoved = false; - isFileChanged = true; - } - fileChange.setAdded(isAdded); - fileChange.setRemoved(isRemoved); return changes; } @@ -382,6 +322,101 @@ public class GitRepositoryService { return Optional.empty(); } + private Map> getFilesContent(String[] commitStrings) { + int i = 0; + Map> result = new HashMap<>(); + while (i < commitStrings.length) { + Optional 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 getFileContent(String[] commitsString, int i) { + List 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 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 findAll(Pageable pageable) { return gitRepositoryRepository.findAll(pageable); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java index 27e3453..8e6a934 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java @@ -7,6 +7,7 @@ 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; @@ -26,18 +27,30 @@ public class FileTS extends AbstractTimeSeriesCreator { @Override public List getTimeSeries(Integer repositoryId, String branchName) { -// findSum(repositoryId,branchName); - return new ArrayList<>(); -// return Collections.singletonList( -// new TimeSeries( -// String.format("", -// gitRepositoryService.findById(repositoryId).getName(), -// branchName, -// getTimeSeriesType().getDescription()), -// getTimeSeriesType(), -// ) -// ) -// ) + List timeSeriesResult = new ArrayList<>(); + List 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 @@ -49,20 +62,4 @@ public class FileTS extends AbstractTimeSeriesCreator { public TimeSeriesType getTimeSeriesType() { return TimeSeriesType.FILES; } - - public void findSum(Integer repositoryId, String branchName) { - List 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); - } - } } -- 2.34.1 From 33e426e7f5c82f63830f816acbb380254171e0b5 Mon Sep 17 00:00:00 2001 From: alexandra Date: Thu, 22 Dec 2022 15:53:08 +0400 Subject: [PATCH 3/4] #78 - Add Dummy --- .../extractor/ts/creator/AuthorsCommitTS.java | 18 +++++++++++++++--- .../ts/creator/AuthorsCompletedIssueTS.java | 19 ++++++++++++++++--- .../extractor/ts/creator/AuthorsIssueTS.java | 18 +++++++++++++++--- .../ulstu/extractor/ts/creator/BranchTS.java | 18 +++++++++++++++--- .../ulstu/extractor/ts/creator/ClassTS.java | 18 +++++++++++++++--- .../extractor/ts/creator/DependenceTS.java | 18 +++++++++++++++--- .../extractor/ts/creator/InterfaceTS.java | 18 +++++++++++++++--- .../ulstu/extractor/ts/creator/IssuesTS.java | 18 +++++++++++++++--- .../ulstu/extractor/ts/creator/ProcessTS.java | 18 +++++++++++++++--- .../ru/ulstu/extractor/ts/creator/StarTS.java | 19 ++++++++++++++++--- .../ru/ulstu/extractor/ts/util/DateUtils.java | 13 +++++++++++++ .../ru/ulstu/extractor/ts/util/Dummy.java | 15 +++++++++++++++ 12 files changed, 180 insertions(+), 30 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java create mode 100644 src/main/java/ru/ulstu/extractor/ts/util/Dummy.java diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java index 4be4592..005cda2 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java @@ -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 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 diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java index 1fa3ebb..fc25833 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java @@ -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 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 diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java index 4ba5df2..f279362 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java @@ -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 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 diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java index aa6592e..b358cc7 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java @@ -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 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 diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java index 2e7e8ea..406bd43 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java @@ -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 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 diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java index e534627..d0ba6cb 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java @@ -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 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 diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java index 8821f8c..0e3d3e5 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java @@ -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 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 diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java index eef0e20..20ef996 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java @@ -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 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 diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java index f375b66..0000758 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java @@ -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 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 diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java index 557e9be..b628576 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java @@ -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 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 diff --git a/src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java b/src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java new file mode 100644 index 0000000..773e9e0 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java @@ -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(); + } +} diff --git a/src/main/java/ru/ulstu/extractor/ts/util/Dummy.java b/src/main/java/ru/ulstu/extractor/ts/util/Dummy.java new file mode 100644 index 0000000..61b0389 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/util/Dummy.java @@ -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 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)); + } +} -- 2.34.1 From df676849687ed9055ce640c3c62ebd3e4067ef0e Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 22 Dec 2022 16:00:49 +0400 Subject: [PATCH 4/4] #78 -- fix code --- .../gitrepository/service/GitRepositoryService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java index fb0a3eb..e986260 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java @@ -30,7 +30,6 @@ import ru.ulstu.extractor.heuristic.model.ResourceUnit; import ru.ulstu.extractor.heuristic.service.StructuralUnitService; import ru.ulstu.extractor.model.Commit; -import javax.swing.text.html.parser.Entity; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -40,7 +39,12 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.time.Instant; -import java.util.*; +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; import java.util.concurrent.Executors; -- 2.34.1