diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java index ce4593d..0f470f5 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java @@ -1,17 +1,18 @@ package ru.ulstu.extractor.ts.creator; +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.Comparator; import java.util.List; -import java.util.Map; import static ru.ulstu.extractor.ts.util.TimeSeriesDateMapper.mapTimeSeriesToInterval; public abstract class AbstractTimeSeriesCreator { - public abstract String getTimeSeriesName(); + public abstract TimeSeriesType getTimeSeriesType(); /** * Извлечь список точек временных рядов @@ -20,7 +21,7 @@ public abstract class AbstractTimeSeriesCreator { * @param branchName * @return */ - public abstract Map> getTimeSeriesValues(Integer repositoryId, String branchName); + public abstract List getTimeSeries(Integer repositoryId, String branchName); public abstract TimeSeriesService getTimeSeriesService(); @@ -31,18 +32,18 @@ public abstract class AbstractTimeSeriesCreator { * @param branchName */ public void addTimeSeries(Integer repositoryId, String branchName) { - // извлеченные точки временных рядов - Map> timeSeriesValues = getTimeSeriesValues(repositoryId, branchName); + // извлеченные временных рядов + List timeSeries = getTimeSeries(repositoryId, branchName); // сгруппированные по временным интервалам точки временных рядов - timeSeriesValues.replaceAll((k, v) -> mapTimeSeriesToInterval(getTimeSeriesService().getTimeSeriesInterval(), v)); - getTimeSeriesService().save(sortTimeSeriesValues(timeSeriesValues)); + timeSeries.forEach(ts -> ts.setValues(mapTimeSeriesToInterval(getTimeSeriesService().getTimeSeriesInterval(), ts.getValues()))); + getTimeSeriesService().save(sortTimeSeries(timeSeries)); } - private Map> sortTimeSeriesValues(Map> timeSeriesValues) { - for (Map.Entry> entry : timeSeriesValues.entrySet()) { - entry.getValue().sort(Comparator.comparing(TimeSeriesValue::getDate)); + private List sortTimeSeries(List timeSeries) { + for (TimeSeries ts : timeSeries) { + ts.getValues().sort(Comparator.comparing(TimeSeriesValue::getDate)); } - return timeSeriesValues; + return timeSeries; } } 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 63e4b3b..ae71399 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class AuthorTS extends AbstractTimeSeriesCreator { @@ -17,13 +17,13 @@ public class AuthorTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество Авторов"; + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.AUTHORS; } @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList<>(); } @Override diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommentTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommentTS.java deleted file mode 100644 index bb1ebef..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommentTS.java +++ /dev/null @@ -1,33 +0,0 @@ -package ru.ulstu.extractor.ts.creator; - -import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; -import ru.ulstu.extractor.ts.service.TimeSeriesService; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Component -public class AuthorsCommentTS extends AbstractTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - - public AuthorsCommentTS(TimeSeriesService timeSeriesService) { - this.timeSeriesService = timeSeriesService; - } - - @Override - public String getTimeSeriesName() { - return "Количество коммитов авторов"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); - } - - @Override - public TimeSeriesService getTimeSeriesService() { - return timeSeriesService; - } -} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java new file mode 100644 index 0000000..4be4592 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java @@ -0,0 +1,33 @@ +package ru.ulstu.extractor.ts.creator; + +import org.springframework.stereotype.Component; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; +import ru.ulstu.extractor.ts.service.TimeSeriesService; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class AuthorsCommitTS extends AbstractTimeSeriesCreator { + private final TimeSeriesService timeSeriesService; + + public AuthorsCommitTS(TimeSeriesService timeSeriesService) { + this.timeSeriesService = timeSeriesService; + } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.AUTHOR_COMMITS; + } + + @Override + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList(); + } + + @Override + public TimeSeriesService getTimeSeriesService() { + return timeSeriesService; + } +} 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 5112c0b..1fa3ebb 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class AuthorsCompletedIssueTS extends AbstractTimeSeriesCreator { @@ -17,17 +17,17 @@ public class AuthorsCompletedIssueTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество выполненных issues авторов"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList<>(); } @Override public TimeSeriesService getTimeSeriesService() { return timeSeriesService; } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.AUTHOR_COMPLETED_ISSUES; + } } 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 209ee59..4ba5df2 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class AuthorsIssueTS extends AbstractTimeSeriesCreator { @@ -17,17 +17,17 @@ public class AuthorsIssueTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество issues авторов"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList(); } @Override public TimeSeriesService getTimeSeriesService() { return timeSeriesService; } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.AUTHOR_ISSUES; + } } 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 95c237d..aa6592e 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class BranchTS extends AbstractTimeSeriesCreator { @@ -17,13 +17,13 @@ public class BranchTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество веток"; + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.BRANCHES; } @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList<>(); } @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 c6bb4a1..2e7e8ea 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class ClassTS extends AbstractTimeSeriesCreator { @@ -17,17 +17,17 @@ public class ClassTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество классов"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList(); } @Override public TimeSeriesService getTimeSeriesService() { return timeSeriesService; } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.CLASSES; + } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java index cbd444f..c686a90 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java @@ -3,12 +3,13 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; 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.HashMap; +import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; @Component @@ -26,26 +27,28 @@ public class CommitsTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество коммитов во времени"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { + public List getTimeSeries(Integer repositoryId, String branchName) { //TODO: добавить постраничное чтение - Map> result = new HashMap<>(); - result.put(String.format("%s %s %s", gitRepositoryService.findById(repositoryId).getName(), - branchName, - getTimeSeriesName()), - commitService.findByRepositoryIdAndName(repositoryId, branchName) - .stream() - .map(c -> new TimeSeriesValue(c.getDate(), 1.0)) - .collect(Collectors.toList())); - return result; + 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(), 1.0)) + .collect(Collectors.toList()))); } @Override public TimeSeriesService getTimeSeriesService() { return timeSeriesService; } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.COMMITS; + } } 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 dd511fb..e534627 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class DependenceTS extends AbstractTimeSeriesCreator { @@ -17,17 +17,17 @@ public class DependenceTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество зависимостей"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList(); } @Override public TimeSeriesService getTimeSeriesService() { return timeSeriesService; } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.DEPENDENCIES; + } } 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 183a12e..c635556 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class EntityTS extends AbstractTimeSeriesCreator { @@ -17,17 +17,17 @@ public class EntityTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество сущностей"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList(); } @Override public TimeSeriesService getTimeSeriesService() { return timeSeriesService; } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.ENTITIES; + } } 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 cb2279b..5797212 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class FileTS extends AbstractTimeSeriesCreator { @@ -17,17 +17,17 @@ public class FileTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество файлов"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList(); } @Override public TimeSeriesService getTimeSeriesService() { return timeSeriesService; } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.FILES; + } } 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 55d4341..8821f8c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class InterfaceTS extends AbstractTimeSeriesCreator { @@ -17,17 +17,17 @@ public class InterfaceTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество интерфейсов"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList(); } @Override public TimeSeriesService getTimeSeriesService() { return timeSeriesService; } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.INTERFACES; + } } 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 23a40d5..eef0e20 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class IssuesTS extends AbstractTimeSeriesCreator { @@ -17,17 +17,17 @@ public class IssuesTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество issues созданных во времени"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList<>(); } @Override public TimeSeriesService getTimeSeriesService() { return timeSeriesService; } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.ISSUES; + } } 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 0a7c05f..f375b66 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class ProcessTS extends AbstractTimeSeriesCreator { @@ -17,17 +17,17 @@ public class ProcessTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество процессов"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList<>(); } @Override public TimeSeriesService getTimeSeriesService() { return timeSeriesService; } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.PROCESSES; + } } 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 ddab245..557e9be 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java @@ -1,12 +1,12 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; @Component public class StarTS extends AbstractTimeSeriesCreator { @@ -17,17 +17,17 @@ public class StarTS extends AbstractTimeSeriesCreator { } @Override - public String getTimeSeriesName() { - return "Количество звезд"; - } - - @Override - public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { - return new HashMap<>(); + public List getTimeSeries(Integer repositoryId, String branchName) { + return new ArrayList<>(); } @Override public TimeSeriesService getTimeSeriesService() { return timeSeriesService; } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.STARS; + } } 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 8be74b1..b6d6931 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java @@ -6,6 +6,8 @@ import ru.ulstu.extractor.core.BaseEntity; import javax.persistence.CascadeType; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; @@ -20,6 +22,9 @@ public class TimeSeries extends BaseEntity { @Fetch(FetchMode.SUBSELECT) private List values = new ArrayList<>(); + @Enumerated(EnumType.STRING) + private TimeSeriesType timeSeriesType; + public TimeSeries() { } @@ -32,6 +37,12 @@ public class TimeSeries extends BaseEntity { this.values = values; } + public TimeSeries(String name, TimeSeriesType timeSeriesType, List values) { + this.name = name; + this.values = values; + this.timeSeriesType = timeSeriesType; + } + public String getName() { return name; } @@ -48,4 +59,11 @@ public class TimeSeries extends BaseEntity { this.values = values; } + public TimeSeriesType getTimeSeriesType() { + return timeSeriesType; + } + + public void setTimeSeriesType(TimeSeriesType timeSeriesType) { + this.timeSeriesType = timeSeriesType; + } } diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java new file mode 100644 index 0000000..636061e --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java @@ -0,0 +1,28 @@ +package ru.ulstu.extractor.ts.model; + +public enum TimeSeriesType { + COMMITS("Временной ряд коммитов"), + AUTHOR_COMMITS("Временной ряд коммитов авторов"), + AUTHOR_ISSUES("Временной ряд задач авторов"), + AUTHOR_COMPLETED_ISSUES("Временной ряд завершенных задач авторов"), + AUTHORS("Временной ряд авторов"), + BRANCHES("Временной ряд веток"), + CLASSES("Временной ряд кклассов"), + DEPENDENCIES("Временной ряд зависимостей"), + ENTITIES("Временной ряд сущностей"), + FILES("Временной файлов"), + INTERFACES("Временной ряд интерфейсов"), + ISSUES("Временной ряд задач"), + PROCESSES("Временной ряд процессов"), + STARS("Временной ряд звезд"); + + private final String description; + + TimeSeriesType(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } +} diff --git a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java index f587ea2..c7da83c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import ru.ulstu.extractor.http.HttpService; import ru.ulstu.extractor.http.JsonTimeSeries; 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.repository.TimeSeriesRepository; import ru.ulstu.extractor.ts.repository.TimeSeriesValueRepository; @@ -19,11 +20,8 @@ import ru.ulstu.extractor.ts.util.TimeSeriesDateMapper; import javax.transaction.Transactional; import java.util.ArrayList; -import java.util.Date; import java.util.List; -import java.util.Map; import java.util.Optional; -import java.util.stream.Collectors; @Service public class TimeSeriesService { @@ -42,27 +40,13 @@ public class TimeSeriesService { this.httpService = httpService; } - /** - * Сохранить список временных рядов - * - * @param timeSeriesValues - * @return - */ @Transactional - public List save(Map> timeSeriesValues) { - List results = new ArrayList<>(); - for (Map.Entry> entry : timeSeriesValues.entrySet()) { - results.add(save(entry.getKey(), entry.getValue())); - } - return results; - } - - @Transactional - public TimeSeries save(String timeSeriesName, List timeSeriesValues) { + public TimeSeries save(String timeSeriesName, TimeSeriesType timeSeriesType, List timeSeriesValues) { LOG.debug("Start save {} time series with {} time series values ", timeSeriesName, timeSeriesValues.size()); final TimeSeries timeSeries = findOrCreate(timeSeriesName); List timeSeriesValuesToRemove = timeSeries.getValues(); timeSeries.setValues(timeSeriesValues); + timeSeries.setTimeSeriesType(timeSeriesType); LOG.debug("Save time series {} ", timeSeries.getName()); TimeSeries savedTimeSeries = timeSeriesRepository.save(timeSeries); LOG.debug("Clear {} time series values ", timeSeriesValuesToRemove.size()); @@ -80,23 +64,19 @@ public class TimeSeriesService { return timeSeriesRepository.save(new TimeSeries(timeSeriesName)); } - public List save(List timeSeriesValues) { - return timeSeriesValues.stream() - .map(timeSeriesValue -> { - timeSeriesValue.setValue((timeSeriesValue.getValue())); - timeSeriesValue.setDate((timeSeriesValue.getDate())); - return timeSeriesValueRepository.save(timeSeriesValue); - }).collect(Collectors.toList()); - } - - public void addTimeSeriesValue(String timeSeriesName, Date date, Double value) { - LOG.debug("Start add time series values to {} time series values ", timeSeriesName); - TimeSeries timeSeries = findOrCreate(timeSeriesName); - timeSeriesValueRepository.save(new TimeSeriesValue(timeSeries, date, value)); - } - - public List findAll() { - return timeSeriesValueRepository.findAll(); + /** + * Сохранить список временных рядов + * + * @param timeSeries список ВР + * @return сохраненный список ВР + */ + @Transactional + public List save(List timeSeries) { + List results = new ArrayList<>(); + for (TimeSeries ts : timeSeries) { + results.add(save(ts.getName(), ts.getTimeSeriesType(), ts.getValues())); + } + return results; } public TimeSeriesDateMapper.TimeSeriesInterval getTimeSeriesInterval() { diff --git a/src/main/resources/db/changelog-20221012_170000-schema.xml b/src/main/resources/db/changelog-20221012_170000-schema.xml index 76ad715..61b2f4f 100644 --- a/src/main/resources/db/changelog-20221012_170000-schema.xml +++ b/src/main/resources/db/changelog-20221012_170000-schema.xml @@ -44,4 +44,9 @@ referencedTableName="time_series" referencedColumnNames="id"/> + + + + + \ No newline at end of file