From b711d70eac833c8700f8e99edbf6775d506acdad Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 7 Oct 2022 12:43:13 +0400 Subject: [PATCH 001/110] fix time series name --- .../extractor/gitrepository/GitRepositoryService.java | 8 ++++++-- .../extractor/gitrepository/model/GitRepository.java | 7 +++++++ src/main/java/ru/ulstu/extractor/ts/CommitsTS.java | 10 ++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryService.java b/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryService.java index 311ddff..934f920 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryService.java @@ -56,8 +56,8 @@ public class GitRepositoryService { private static final String BRANCH_PREFIX = "refs/remotes/origin/"; @Value("${extractor.custom-projects-dir}") private String customProjectsDir; - private final ExecutorService executorService = Executors.newFixedThreadPool(4); - private final ExecutorService executorServiceCommits = Executors.newFixedThreadPool(4); + private final ExecutorService executorService = Executors.newFixedThreadPool(8); + private final ExecutorService executorServiceCommits = Executors.newFixedThreadPool(8); private final StructuralUnitService structuralUnitService; private final GitRepositoryRepository gitRepositoryRepository; @@ -370,4 +370,8 @@ public class GitRepositoryService { public Page findAll(Pageable pageable) { return gitRepositoryRepository.findAll(pageable); } + + public GitRepository findById(Integer id) { + return gitRepositoryRepository.getOne(id); + } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java index edabd3e..3d5c605 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java @@ -22,4 +22,11 @@ public class GitRepository extends BaseEntity { public void setUrl(String url) { this.url = url; } + + public String getName() { + int lastDelimiterIndex = url.lastIndexOf("/"); + return (lastDelimiterIndex > 0 && lastDelimiterIndex < url.length()) + ? url.substring(lastDelimiterIndex + 1) + : url; + } } diff --git a/src/main/java/ru/ulstu/extractor/ts/CommitsTS.java b/src/main/java/ru/ulstu/extractor/ts/CommitsTS.java index 3067117..2196c20 100644 --- a/src/main/java/ru/ulstu/extractor/ts/CommitsTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/CommitsTS.java @@ -2,6 +2,7 @@ package ru.ulstu.extractor.ts; import org.springframework.stereotype.Component; import ru.ulstu.extractor.commit.service.CommitService; +import ru.ulstu.extractor.gitrepository.GitRepositoryService; import ru.ulstu.extractor.model.TimeSeriesValue; import ru.ulstu.extractor.service.TimeSeriesService; @@ -14,11 +15,14 @@ import java.util.stream.Collectors; public class CommitsTS extends AbstractTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final CommitService commitService; + private final GitRepositoryService gitRepositoryService; public CommitsTS(TimeSeriesService timeSeriesService, - CommitService commitService) { + CommitService commitService, + GitRepositoryService gitRepositoryService) { this.timeSeriesService = timeSeriesService; this.commitService = commitService; + this.gitRepositoryService = gitRepositoryService; } @Override @@ -30,7 +34,9 @@ public class CommitsTS extends AbstractTimeSeriesCreator { public Map> getTimeSeriesValues(Integer repositoryId, String branchName) { //TODO: добавить постраничное чтение Map> result = new HashMap<>(); - result.put(String.format("%s %s %s", getTimeSeriesName(), repositoryId, branchName), + 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)) -- 2.34.1 From ea6e77b9f9423e90bce41a2be9c2c0db35f66e16 Mon Sep 17 00:00:00 2001 From: BarminaA Date: Fri, 7 Oct 2022 13:40:41 +0400 Subject: [PATCH 002/110] #61-add pages for rules --- src/main/resources/templates/default.html | 6 +++ src/main/resources/templates/listRules.html | 30 ++++++++++++ .../resources/templates/recommendations.html | 27 ++++++++++ src/main/resources/templates/rule.html | 49 +++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 src/main/resources/templates/listRules.html create mode 100644 src/main/resources/templates/recommendations.html create mode 100644 src/main/resources/templates/rule.html diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 254f42c..1b59df9 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -37,6 +37,12 @@ + + diff --git a/src/main/resources/templates/listRules.html b/src/main/resources/templates/listRules.html new file mode 100644 index 0000000..a4694e7 --- /dev/null +++ b/src/main/resources/templates/listRules.html @@ -0,0 +1,30 @@ + + + + Простая обработка формы на Spring MVC + + +
+ + + + + + + + + + + + + + + +
Правила
Если задач много, а коммитов мало, то увеличить колличество авторов
Если авторов много, задач мало, оценнить эффективность авторов
+ +
+ diff --git a/src/main/resources/templates/recommendations.html b/src/main/resources/templates/recommendations.html new file mode 100644 index 0000000..4415f18 --- /dev/null +++ b/src/main/resources/templates/recommendations.html @@ -0,0 +1,27 @@ + + + + Простая обработка формы на Spring MVC + + +
+ + + + + + + + + + + + + + + +
Рекомендации
Увеличить колличество авторов
Оценнить эффективность авторов
+
+ diff --git a/src/main/resources/templates/rule.html b/src/main/resources/templates/rule.html new file mode 100644 index 0000000..00be0ad --- /dev/null +++ b/src/main/resources/templates/rule.html @@ -0,0 +1,49 @@ + + + + Простая обработка формы на Spring MVC + + +
+ +
+
+
+ Если +
+
+ +
+
+ времянной ряд +
+
+ +
+
+
+
+ то: +
+
+ +
+
+ +
+
+
+
+ -- 2.34.1 From fd001da317f3fe712d8d06d44f73ba540573aa99 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 8 Oct 2022 12:24:36 +0400 Subject: [PATCH 003/110] #59 -- sort time series values --- .../ulstu/extractor/ts/AbstractTimeSeriesCreator.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/extractor/ts/AbstractTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/AbstractTimeSeriesCreator.java index 4fde2c8..07b516b 100644 --- a/src/main/java/ru/ulstu/extractor/ts/AbstractTimeSeriesCreator.java +++ b/src/main/java/ru/ulstu/extractor/ts/AbstractTimeSeriesCreator.java @@ -3,6 +3,7 @@ package ru.ulstu.extractor.ts; import ru.ulstu.extractor.model.TimeSeriesValue; import ru.ulstu.extractor.service.TimeSeriesService; +import java.util.Comparator; import java.util.List; import java.util.Map; @@ -35,6 +36,13 @@ public abstract class AbstractTimeSeriesCreator { // сгруппированные по временным интервалам точки временных рядов timeSeriesValues.replaceAll((k, v) -> mapTimeSeriesToInterval(getTimeSeriesService().getTimeSeriesInterval(), v)); - getTimeSeriesService().save(timeSeriesValues); + getTimeSeriesService().save(sortTimeSeriesValues(timeSeriesValues)); + } + + private Map> sortTimeSeriesValues(Map> timeSeriesValues) { + for (Map.Entry> entry : timeSeriesValues.entrySet()) { + entry.getValue().sort(Comparator.comparing(TimeSeriesValue::getDate)); + } + return timeSeriesValues; } } -- 2.34.1 From c85c7e7917c7b68f21625558dd04c6c731658d3b Mon Sep 17 00:00:00 2001 From: BarminaA Date: Sun, 9 Oct 2022 08:01:10 +0400 Subject: [PATCH 004/110] #64-add model for rule --- .../java/ru/ulstu/extractor/model/Rule.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/main/java/ru/ulstu/extractor/model/Rule.java diff --git a/src/main/java/ru/ulstu/extractor/model/Rule.java b/src/main/java/ru/ulstu/extractor/model/Rule.java new file mode 100644 index 0000000..2c249e7 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/model/Rule.java @@ -0,0 +1,67 @@ +package ru.ulstu.extractor.model; + +import javax.persistence.Entity; + +@Entity +public class Rule extends BaseEntity { + private String measure1; + + private String timeSeries1; + + private String measure2; + + private String timeSeries2; + + private String action; + + public Rule() { + } + + public Rule(String measure1, String timeSeries1, String measure2, String timeSeries2, String action) { + this.measure1 = measure1; + this.timeSeries1 = timeSeries1; + this.measure2 = measure2; + this.timeSeries2 = timeSeries2; + this.action = action; + } + + public String getMeasure1() { + return measure1; + } + + public String getTimeSeries1() { + return timeSeries1; + } + + public String getMeasure2() { + return measure2; + } + + public String getTimeSeries2() { + return timeSeries2; + } + + public void setMeasure1(String measure1) { + this.measure1 = measure1; + } + + public void setTimeSeries1(String timeSeries1) { + this.timeSeries1 = timeSeries1; + } + + public void setMeasure2(String measure2) { + this.measure2 = measure2; + } + + public void setTimeSeries2(String timeSeries2) { + this.timeSeries2 = timeSeries2; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } +} -- 2.34.1 From 1621e151d91abfbbf1a85d74bf7e4dd83c1e3c8d Mon Sep 17 00:00:00 2001 From: BarminaA Date: Thu, 13 Oct 2022 15:18:34 +0400 Subject: [PATCH 005/110] #64-add model and changelog --- .../extractor/model/AntecedentValue.java | 23 +++++++ .../java/ru/ulstu/extractor/model/Rule.java | 68 ++++++++++--------- .../db/changelog-20221012_170000-schema.xml | 47 +++++++++++++ src/main/resources/db/changelog-master.xml | 1 + 4 files changed, 108 insertions(+), 31 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/model/AntecedentValue.java create mode 100644 src/main/resources/db/changelog-20221012_170000-schema.xml diff --git a/src/main/java/ru/ulstu/extractor/model/AntecedentValue.java b/src/main/java/ru/ulstu/extractor/model/AntecedentValue.java new file mode 100644 index 0000000..1ed3473 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/model/AntecedentValue.java @@ -0,0 +1,23 @@ +package ru.ulstu.extractor.model; + +import javax.persistence.Entity; + +@Entity +public class AntecedentValue extends BaseEntity { + private String antecedentValue; + + public AntecedentValue() { + } + + public AntecedentValue(String antecedentValue) { + this.antecedentValue = antecedentValue; + } + + public String getAntecedentValue() { + return antecedentValue; + } + + public void setAntecedentValue(String antecedentValue) { + this.antecedentValue = antecedentValue; + } +} diff --git a/src/main/java/ru/ulstu/extractor/model/Rule.java b/src/main/java/ru/ulstu/extractor/model/Rule.java index 2c249e7..699e621 100644 --- a/src/main/java/ru/ulstu/extractor/model/Rule.java +++ b/src/main/java/ru/ulstu/extractor/model/Rule.java @@ -1,67 +1,73 @@ package ru.ulstu.extractor.model; import javax.persistence.Entity; +import javax.persistence.ManyToOne; @Entity public class Rule extends BaseEntity { - private String measure1; + @ManyToOne + private AntecedentValue firstAntecedentValue; - private String timeSeries1; + @ManyToOne + private TimeSeries firstAntecedent; - private String measure2; + @ManyToOne + private AntecedentValue secondAntecedentValue; - private String timeSeries2; + @ManyToOne + private TimeSeries secondAntecedent; - private String action; + private String consequent; public Rule() { } - public Rule(String measure1, String timeSeries1, String measure2, String timeSeries2, String action) { - this.measure1 = measure1; - this.timeSeries1 = timeSeries1; - this.measure2 = measure2; - this.timeSeries2 = timeSeries2; - this.action = action; + public Rule(Integer id, Integer version, AntecedentValue firstAntecedentValue, TimeSeries firstAntecedent, AntecedentValue secondAntecedentValue, TimeSeries secondAntecedent, String consequent) { + super(id, version); + this.firstAntecedentValue = firstAntecedentValue; + this.firstAntecedent = firstAntecedent; + this.secondAntecedentValue = secondAntecedentValue; + this.secondAntecedent = secondAntecedent; + this.consequent = consequent; } - public String getMeasure1() { - return measure1; + public AntecedentValue getFirstValue() { + return firstAntecedentValue; } - public String getTimeSeries1() { - return timeSeries1; + public void setFirstValue(AntecedentValue firstAntecedentValue) { + this.firstAntecedentValue = firstAntecedentValue; } - public String getMeasure2() { - return measure2; + public TimeSeries getFirstAntecedent() { + return firstAntecedent; } - public String getTimeSeries2() { - return timeSeries2; + public void setFirstAntecedent(TimeSeries firstAntecedent) { + this.firstAntecedent = firstAntecedent; } - public void setMeasure1(String measure1) { - this.measure1 = measure1; + public AntecedentValue getSecondValue() { + return secondAntecedentValue; } - public void setTimeSeries1(String timeSeries1) { - this.timeSeries1 = timeSeries1; + public void setSecondValue(AntecedentValue secondAntecedentValue) { + this.secondAntecedentValue = secondAntecedentValue; } - public void setMeasure2(String measure2) { - this.measure2 = measure2; + public TimeSeries getSecondAntecedent() { + return secondAntecedent; } - public void setTimeSeries2(String timeSeries2) { - this.timeSeries2 = timeSeries2; + public void setSecondAntecedent(TimeSeries secondAntecedent) { + this.secondAntecedent = secondAntecedent; } - public String getAction() { - return action; + public String getConsequent() { + return consequent; } - public void setAction(String action) { - this.action = action; + public void setConsequent(String consequent) { + this.consequent = consequent; } } diff --git a/src/main/resources/db/changelog-20221012_170000-schema.xml b/src/main/resources/db/changelog-20221012_170000-schema.xml new file mode 100644 index 0000000..76ad715 --- /dev/null +++ b/src/main/resources/db/changelog-20221012_170000-schema.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index e2afa54..dfde9f7 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -14,4 +14,5 @@ + -- 2.34.1 From 2e18e34647e0c76e415a5c381dd6e4b207991de9 Mon Sep 17 00:00:00 2001 From: BarminaA Date: Fri, 14 Oct 2022 11:27:27 +0400 Subject: [PATCH 006/110] #66-view list rules --- .../ru/ulstu/extractor/controller/Route.java | 1 + .../extractor/controller/RuleController.java | 25 +++++++++++++++++++ .../java/ru/ulstu/extractor/model/Rule.java | 8 +++--- .../extractor/repository/RuleRepository.java | 7 ++++++ .../ulstu/extractor/service/RuleService.java | 20 +++++++++++++++ src/main/resources/templates/listRules.html | 19 ++++++++------ 6 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/controller/RuleController.java create mode 100644 src/main/java/ru/ulstu/extractor/repository/RuleRepository.java create mode 100644 src/main/java/ru/ulstu/extractor/service/RuleService.java diff --git a/src/main/java/ru/ulstu/extractor/controller/Route.java b/src/main/java/ru/ulstu/extractor/controller/Route.java index 37cc08f..0d3f39e 100644 --- a/src/main/java/ru/ulstu/extractor/controller/Route.java +++ b/src/main/java/ru/ulstu/extractor/controller/Route.java @@ -16,6 +16,7 @@ public class Route { public static final String INDEXING_NEW_REPOSITORY = "indexNewRepository"; public static final String FILTER_COMMITS = "filterCommits"; public static final String STATISTIC = "statistic"; + public static final String LIST_RULE = "listRules"; public static String getLIST_INDEXED_REPOSITORIES() { return LIST_INDEXED_REPOSITORIES; diff --git a/src/main/java/ru/ulstu/extractor/controller/RuleController.java b/src/main/java/ru/ulstu/extractor/controller/RuleController.java new file mode 100644 index 0000000..f9c4eab --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/controller/RuleController.java @@ -0,0 +1,25 @@ +package ru.ulstu.extractor.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import ru.ulstu.extractor.service.RuleService; +import springfox.documentation.annotations.ApiIgnore; + +import static ru.ulstu.extractor.controller.Route.LIST_RULE; + +@Controller +@ApiIgnore +public class RuleController { + private RuleService ruleService; + + public RuleController(RuleService ruleService) { + this.ruleService = ruleService; + } + + @GetMapping(LIST_RULE) + public String getList(Model model) { + model.addAttribute("rules", ruleService.getList()); + return LIST_RULE; + } +} diff --git a/src/main/java/ru/ulstu/extractor/model/Rule.java b/src/main/java/ru/ulstu/extractor/model/Rule.java index 699e621..0075b92 100644 --- a/src/main/java/ru/ulstu/extractor/model/Rule.java +++ b/src/main/java/ru/ulstu/extractor/model/Rule.java @@ -31,11 +31,11 @@ public class Rule extends BaseEntity { this.consequent = consequent; } - public AntecedentValue getFirstValue() { + public AntecedentValue getFirstAntecedentValue() { return firstAntecedentValue; } - public void setFirstValue(AntecedentValue firstAntecedentValue) { + public void setFirstAntecedentValue(AntecedentValue firstAntecedentValue) { this.firstAntecedentValue = firstAntecedentValue; } @@ -47,11 +47,11 @@ public class Rule extends BaseEntity { this.firstAntecedent = firstAntecedent; } - public AntecedentValue getSecondValue() { + public AntecedentValue getSecondAntecedentValue() { return secondAntecedentValue; } - public void setSecondValue(AntecedentValue secondAntecedentValue) { + public void setSecondAntecedentValue(AntecedentValue secondAntecedentValue) { this.secondAntecedentValue = secondAntecedentValue; } diff --git a/src/main/java/ru/ulstu/extractor/repository/RuleRepository.java b/src/main/java/ru/ulstu/extractor/repository/RuleRepository.java new file mode 100644 index 0000000..e931488 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/repository/RuleRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.extractor.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.extractor.model.Rule; + +public interface RuleRepository extends JpaRepository { +} diff --git a/src/main/java/ru/ulstu/extractor/service/RuleService.java b/src/main/java/ru/ulstu/extractor/service/RuleService.java new file mode 100644 index 0000000..7b9f4e1 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/service/RuleService.java @@ -0,0 +1,20 @@ +package ru.ulstu.extractor.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.model.Rule; +import ru.ulstu.extractor.repository.RuleRepository; + +import java.util.List; + +@Service +public class RuleService { + private final RuleRepository ruleRepository; + + public RuleService(RuleRepository ruleRepository) { + this.ruleRepository = ruleRepository; + } + + public List getList() { + return ruleRepository.findAll(); + } +} diff --git a/src/main/resources/templates/listRules.html b/src/main/resources/templates/listRules.html index a4694e7..c10aa15 100644 --- a/src/main/resources/templates/listRules.html +++ b/src/main/resources/templates/listRules.html @@ -1,6 +1,6 @@ Простая обработка формы на Spring MVC @@ -10,16 +10,19 @@ - - + - - - - - + + + + + + + + +
ПравилаПравила
Если задач много, а коммитов мало, то увеличить колличество авторов
Если авторов много, задач мало, оценнить эффективность авторов
Еслиито
-- 2.34.1 From 7dbe89169e9b9d71481cfc8ec0d67274eaf9ac3a Mon Sep 17 00:00:00 2001 From: BarminaA Date: Sat, 15 Oct 2022 14:26:53 +0400 Subject: [PATCH 007/110] #68-save rule in db --- .../ru/ulstu/extractor/controller/Route.java | 1 + .../extractor/controller/RuleController.java | 30 +++++++- .../java/ru/ulstu/extractor/model/Rule.java | 20 ++++- .../extractor/model/mvc/AddRuleForm.java | 63 +++++++++++++++ .../repository/AntecedentValueRepository.java | 8 ++ .../service/AntecedentValueService.java | 25 ++++++ .../ulstu/extractor/service/RuleService.java | 17 ++++- .../extractor/service/TimeSeriesService.java | 15 ++-- src/main/resources/templates/addRule.html | 76 +++++++++++++++++++ src/main/resources/templates/listRules.html | 2 +- src/main/resources/templates/rule.html | 49 ------------ 11 files changed, 247 insertions(+), 59 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/model/mvc/AddRuleForm.java create mode 100644 src/main/java/ru/ulstu/extractor/repository/AntecedentValueRepository.java create mode 100644 src/main/java/ru/ulstu/extractor/service/AntecedentValueService.java create mode 100644 src/main/resources/templates/addRule.html delete mode 100644 src/main/resources/templates/rule.html diff --git a/src/main/java/ru/ulstu/extractor/controller/Route.java b/src/main/java/ru/ulstu/extractor/controller/Route.java index 0d3f39e..77e1efe 100644 --- a/src/main/java/ru/ulstu/extractor/controller/Route.java +++ b/src/main/java/ru/ulstu/extractor/controller/Route.java @@ -17,6 +17,7 @@ public class Route { public static final String FILTER_COMMITS = "filterCommits"; public static final String STATISTIC = "statistic"; public static final String LIST_RULE = "listRules"; + public static final String ADD_RULE = "addRule"; public static String getLIST_INDEXED_REPOSITORIES() { return LIST_INDEXED_REPOSITORIES; diff --git a/src/main/java/ru/ulstu/extractor/controller/RuleController.java b/src/main/java/ru/ulstu/extractor/controller/RuleController.java index f9c4eab..038005b 100644 --- a/src/main/java/ru/ulstu/extractor/controller/RuleController.java +++ b/src/main/java/ru/ulstu/extractor/controller/RuleController.java @@ -3,18 +3,30 @@ package ru.ulstu.extractor.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import ru.ulstu.extractor.model.mvc.AddRuleForm; +import ru.ulstu.extractor.service.AntecedentValueService; import ru.ulstu.extractor.service.RuleService; +import ru.ulstu.extractor.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; +import static ru.ulstu.extractor.controller.Route.ADD_RULE; import static ru.ulstu.extractor.controller.Route.LIST_RULE; @Controller @ApiIgnore public class RuleController { - private RuleService ruleService; + private final RuleService ruleService; + private final AntecedentValueService antecedentValueService; + private final TimeSeriesService timeSeriesService; - public RuleController(RuleService ruleService) { + public RuleController(RuleService ruleService, AntecedentValueService antecedentValueService, TimeSeriesService timeSeriesService) { this.ruleService = ruleService; + this.antecedentValueService = antecedentValueService; + this.timeSeriesService = timeSeriesService; } @GetMapping(LIST_RULE) @@ -22,4 +34,18 @@ public class RuleController { model.addAttribute("rules", ruleService.getList()); return LIST_RULE; } + + @GetMapping(ADD_RULE) + public String getAntecedent(Model model) { + model.addAttribute("antecedentValues", antecedentValueService.getList()); + model.addAttribute("antecedents", timeSeriesService.getAllTimeSeries()); + model.addAttribute("addRuleForm", new AddRuleForm()); + return ADD_RULE; + } + + @RequestMapping(value = ADD_RULE, method = RequestMethod.POST) + public String addRule(@ModelAttribute AddRuleForm ruleForm, Model model, RedirectAttributes redirectAttributes) { + ruleService.saveRule(ruleForm); + return "redirect:/" + LIST_RULE; + } } diff --git a/src/main/java/ru/ulstu/extractor/model/Rule.java b/src/main/java/ru/ulstu/extractor/model/Rule.java index 0075b92..baf8565 100644 --- a/src/main/java/ru/ulstu/extractor/model/Rule.java +++ b/src/main/java/ru/ulstu/extractor/model/Rule.java @@ -22,7 +22,25 @@ public class Rule extends BaseEntity { public Rule() { } - public Rule(Integer id, Integer version, AntecedentValue firstAntecedentValue, TimeSeries firstAntecedent, AntecedentValue secondAntecedentValue, TimeSeries secondAntecedent, String consequent) { + public Rule(AntecedentValue firstAntecedentValue, + TimeSeries firstAntecedent, + AntecedentValue secondAntecedentValue, + TimeSeries secondAntecedent, + String consequent) { + this.firstAntecedentValue = firstAntecedentValue; + this.firstAntecedent = firstAntecedent; + this.secondAntecedentValue = secondAntecedentValue; + this.secondAntecedent = secondAntecedent; + this.consequent = consequent; + } + + public Rule(Integer id, + Integer version, + AntecedentValue firstAntecedentValue, + TimeSeries firstAntecedent, + AntecedentValue secondAntecedentValue, + TimeSeries secondAntecedent, + String consequent) { super(id, version); this.firstAntecedentValue = firstAntecedentValue; this.firstAntecedent = firstAntecedent; diff --git a/src/main/java/ru/ulstu/extractor/model/mvc/AddRuleForm.java b/src/main/java/ru/ulstu/extractor/model/mvc/AddRuleForm.java new file mode 100644 index 0000000..cf164d8 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/model/mvc/AddRuleForm.java @@ -0,0 +1,63 @@ +package ru.ulstu.extractor.model.mvc; + +public class AddRuleForm { + private Integer firstAntecedentValueId; + private Integer firstAntecedentId; + private Integer secondAntecedentValueId; + private Integer secondAntecedentId; + private String consequent; + + public AddRuleForm() { + } + + public Integer getFirstAntecedentValueId() { + return firstAntecedentValueId; + } + + public void setFirstAntecedentValueId(Integer firstAntecedentValueId) { + this.firstAntecedentValueId = firstAntecedentValueId; + } + + public Integer getFirstAntecedentId() { + return firstAntecedentId; + } + + public void setFirstAntecedentId(Integer firstAntecedentId) { + this.firstAntecedentId = firstAntecedentId; + } + + public Integer getSecondAntecedentValueId() { + return secondAntecedentValueId; + } + + public void setSecondAntecedentValueId(Integer secondAntecedentValueId) { + this.secondAntecedentValueId = secondAntecedentValueId; + } + + public Integer getSecondAntecedentId() { + return secondAntecedentId; + } + + public void setSecondAntecedentId(Integer secondAntecedentId) { + this.secondAntecedentId = secondAntecedentId; + } + + public String getConsequent() { + return consequent; + } + + public void setConsequent(String consequent) { + this.consequent = consequent; + } + + @Override + public String toString() { + return "AddRuleForm{" + + "firstAntecedentValueId=" + firstAntecedentValueId + + ", firstAntecedentId=" + firstAntecedentId + + ", secondAntecedentValueId=" + secondAntecedentValueId + + ", secondAntecedentId=" + secondAntecedentId + + ", consequent='" + consequent + '\'' + + '}'; + } +} diff --git a/src/main/java/ru/ulstu/extractor/repository/AntecedentValueRepository.java b/src/main/java/ru/ulstu/extractor/repository/AntecedentValueRepository.java new file mode 100644 index 0000000..86ea561 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/repository/AntecedentValueRepository.java @@ -0,0 +1,8 @@ +package ru.ulstu.extractor.repository; + + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.extractor.model.AntecedentValue; + +public interface AntecedentValueRepository extends JpaRepository { +} diff --git a/src/main/java/ru/ulstu/extractor/service/AntecedentValueService.java b/src/main/java/ru/ulstu/extractor/service/AntecedentValueService.java new file mode 100644 index 0000000..e2c48e6 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/service/AntecedentValueService.java @@ -0,0 +1,25 @@ +package ru.ulstu.extractor.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.model.AntecedentValue; +import ru.ulstu.extractor.repository.AntecedentValueRepository; + +import java.util.List; + +@Service +public class AntecedentValueService { + private final AntecedentValueRepository antecedentValueRepository; + + public AntecedentValueService(AntecedentValueRepository antecedentValueRepository) { + this.antecedentValueRepository = antecedentValueRepository; + } + + public List getList() { + return antecedentValueRepository.findAll(); + } + + public AntecedentValue getById(Integer antecedentValueId) { + return antecedentValueRepository.findById(antecedentValueId) + .orElseThrow(() -> new RuntimeException("Antecedent value not found by id " + antecedentValueId)); + } +} diff --git a/src/main/java/ru/ulstu/extractor/service/RuleService.java b/src/main/java/ru/ulstu/extractor/service/RuleService.java index 7b9f4e1..5c8acd7 100644 --- a/src/main/java/ru/ulstu/extractor/service/RuleService.java +++ b/src/main/java/ru/ulstu/extractor/service/RuleService.java @@ -2,6 +2,7 @@ package ru.ulstu.extractor.service; import org.springframework.stereotype.Service; import ru.ulstu.extractor.model.Rule; +import ru.ulstu.extractor.model.mvc.AddRuleForm; import ru.ulstu.extractor.repository.RuleRepository; import java.util.List; @@ -9,12 +10,26 @@ import java.util.List; @Service public class RuleService { private final RuleRepository ruleRepository; + private final TimeSeriesService timeSeriesService; + private final AntecedentValueService antecedentValueService; - public RuleService(RuleRepository ruleRepository) { + public RuleService(RuleRepository ruleRepository, + TimeSeriesService timeSeriesService, + AntecedentValueService antecedentValueService) { this.ruleRepository = ruleRepository; + this.timeSeriesService = timeSeriesService; + this.antecedentValueService = antecedentValueService; } public List getList() { return ruleRepository.findAll(); } + + public void saveRule(AddRuleForm addRuleForm) { + ruleRepository.save(new Rule(antecedentValueService.getById(addRuleForm.getFirstAntecedentValueId()), + timeSeriesService.getById(addRuleForm.getFirstAntecedentId()), + antecedentValueService.getById(addRuleForm.getSecondAntecedentValueId()), + timeSeriesService.getById(addRuleForm.getSecondAntecedentId()), + addRuleForm.getConsequent())); + } } diff --git a/src/main/java/ru/ulstu/extractor/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/service/TimeSeriesService.java index 706b52f..f978433 100644 --- a/src/main/java/ru/ulstu/extractor/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/service/TimeSeriesService.java @@ -18,11 +18,7 @@ import ru.ulstu.extractor.repository.TimeSeriesValueRepository; import ru.ulstu.extractor.ts.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.*; import java.util.stream.Collectors; @Service @@ -113,4 +109,13 @@ public class TimeSeriesService { } }).start(); } + + public List getAllTimeSeries() { + return timeSeriesRepository.findAll(); + } + + public TimeSeries getById(Integer tsId) { + return timeSeriesRepository.findById(tsId) + .orElseThrow(() -> new RuntimeException("Time series not found by id " + tsId)); + } } diff --git a/src/main/resources/templates/addRule.html b/src/main/resources/templates/addRule.html new file mode 100644 index 0000000..8c709d0 --- /dev/null +++ b/src/main/resources/templates/addRule.html @@ -0,0 +1,76 @@ + + + + Простая обработка формы на Spring MVC + + +
+
+
+
+ Если +
+
+ +
+
+ временной ряд +
+
+ +
+
+ и +
+
+ +
+
+ временной ряд +
+
+ +
+
+ то: +
+
+ +
+
+ +
+
+
+
+ diff --git a/src/main/resources/templates/listRules.html b/src/main/resources/templates/listRules.html index c10aa15..93e139a 100644 --- a/src/main/resources/templates/listRules.html +++ b/src/main/resources/templates/listRules.html @@ -27,7 +27,7 @@ diff --git a/src/main/resources/templates/rule.html b/src/main/resources/templates/rule.html deleted file mode 100644 index 00be0ad..0000000 --- a/src/main/resources/templates/rule.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - Простая обработка формы на Spring MVC - - -
- -
-
-
- Если -
-
- -
-
- времянной ряд -
-
- -
-
-
-
- то: -
-
- -
-
- -
-
-
-
- -- 2.34.1 From 76f1a6075403476d5166113da31ad28018eb6924 Mon Sep 17 00:00:00 2001 From: BarminaA Date: Sat, 15 Oct 2022 20:43:33 +0400 Subject: [PATCH 008/110] #70-add button --- src/main/resources/templates/recommendations.html | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/templates/recommendations.html b/src/main/resources/templates/recommendations.html index 4415f18..036dc66 100644 --- a/src/main/resources/templates/recommendations.html +++ b/src/main/resources/templates/recommendations.html @@ -23,5 +23,6 @@ + -- 2.34.1 From 957c1bbc8c257b7238ec67e059c8050ba9a77b73 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 15 Oct 2022 22:36:08 +0400 Subject: [PATCH 009/110] #72 -- classes refactor --- .../extractor/{ => author}/model/Author.java | 4 +++- .../repository/AuthorRepository.java | 4 ++-- .../{ => author}/service/AuthorService.java | 6 +++--- .../branch/controller/BranchController.java | 6 +++--- .../ulstu/extractor/branch/model/Branch.java | 2 +- .../branch/service/BranchService.java | 2 +- .../ulstu/extractor/commit/model/Commit.java | 3 +++ .../commit/service/CommitService.java | 2 +- .../extractor/config/MvcConfiguration.java | 2 +- .../extractor/{model => core}/BaseEntity.java | 2 +- .../{model => core}/OffsetablePageRequest.java | 2 +- .../extractor/{controller => core}/Route.java | 2 +- .../controler}/GitFilteringController.java | 10 +++++----- .../controler}/GitIndexingController.java | 14 +++++++------- .../controler}/RepoController.java | 8 ++++---- .../controler}/RepositoryController.java | 8 ++++---- .../controler}/StatisticController.java | 8 ++++---- .../{ => gitrepository}/model/FileChange.java | 3 ++- .../model}/FilterForm.java | 2 +- .../gitrepository/model/GitRepository.java | 2 +- .../{ => gitrepository}/model/LineChange.java | 4 +++- .../mvc => gitrepository/model}/RepoForm.java | 2 +- .../GitRepositoryRepository.java | 2 +- .../service/FilteringService.java | 6 +++--- .../{ => service}/GitRepositoryService.java | 9 +++++---- .../service/IndexService.java | 7 +++---- .../controller/StructuralUnitController.java | 2 +- .../ulstu/extractor/http/JsonTimeSeries.java | 2 +- .../extractor/http/JsonTimeSeriesValue.java | 2 +- .../{ => rule}/controller/RuleController.java | 14 +++++++------- .../{model/mvc => rule/model}/AddRuleForm.java | 2 +- .../{ => rule}/model/AntecedentValue.java | 4 +++- .../ulstu/extractor/{ => rule}/model/Rule.java | 5 ++++- .../repository/AntecedentValueRepository.java | 4 ++-- .../{ => rule}/repository/RuleRepository.java | 4 ++-- .../service/AntecedentValueService.java | 6 +++--- .../{ => rule}/service/RuleService.java | 9 +++++---- .../AbstractTimeSeriesCreator.java | 8 ++++---- .../extractor/ts/{ => creator}/AuthorTS.java | 6 +++--- .../ts/{ => creator}/AuthorsCommentTS.java | 6 +++--- .../{ => creator}/AuthorsCompletedIssueTS.java | 6 +++--- .../ts/{ => creator}/AuthorsIssueTS.java | 6 +++--- .../extractor/ts/{ => creator}/BranchTS.java | 6 +++--- .../extractor/ts/{ => creator}/ClassTS.java | 6 +++--- .../extractor/ts/{ => creator}/CommitsTS.java | 8 ++++---- .../ts/{ => creator}/DependenceTS.java | 6 +++--- .../extractor/ts/{ => creator}/EntityTS.java | 6 +++--- .../extractor/ts/{ => creator}/FileTS.java | 6 +++--- .../ts/{ => creator}/InterfaceTS.java | 6 +++--- .../extractor/ts/{ => creator}/IssuesTS.java | 6 +++--- .../extractor/ts/{ => creator}/ProcessTS.java | 6 +++--- .../extractor/ts/{ => creator}/StarTS.java | 6 +++--- .../extractor/{ => ts}/model/TimeSeries.java | 3 ++- .../{ => ts}/model/TimeSeriesValue.java | 4 +++- .../repository/TimeSeriesRepository.java | 4 ++-- .../repository/TimeSeriesValueRepository.java | 4 ++-- .../{ => ts}/service/TimeSeriesService.java | 18 +++++++++++------- .../ts/{ => util}/TimeSeriesDateMapper.java | 6 +++--- .../java/ru/ulstu/TimeSeriesMapperTest.java | 6 +++--- 59 files changed, 168 insertions(+), 147 deletions(-) rename src/main/java/ru/ulstu/extractor/{ => author}/model/Author.java (79%) rename src/main/java/ru/ulstu/extractor/{ => author}/repository/AuthorRepository.java (93%) rename src/main/java/ru/ulstu/extractor/{ => author}/service/AuthorService.java (85%) rename src/main/java/ru/ulstu/extractor/{model => core}/BaseEntity.java (98%) rename src/main/java/ru/ulstu/extractor/{model => core}/OffsetablePageRequest.java (98%) rename src/main/java/ru/ulstu/extractor/{controller => core}/Route.java (97%) rename src/main/java/ru/ulstu/extractor/{controller => gitrepository/controler}/GitFilteringController.java (91%) rename src/main/java/ru/ulstu/extractor/{controller => gitrepository/controler}/GitIndexingController.java (87%) rename src/main/java/ru/ulstu/extractor/{controller => gitrepository/controler}/RepoController.java (89%) rename src/main/java/ru/ulstu/extractor/{controller => gitrepository/controler}/RepositoryController.java (82%) rename src/main/java/ru/ulstu/extractor/{controller => gitrepository/controler}/StatisticController.java (96%) rename src/main/java/ru/ulstu/extractor/{ => gitrepository}/model/FileChange.java (96%) rename src/main/java/ru/ulstu/extractor/{model/mvc => gitrepository/model}/FilterForm.java (97%) rename src/main/java/ru/ulstu/extractor/{ => gitrepository}/model/LineChange.java (93%) rename src/main/java/ru/ulstu/extractor/{model/mvc => gitrepository/model}/RepoForm.java (91%) rename src/main/java/ru/ulstu/extractor/gitrepository/{ => repository}/GitRepositoryRepository.java (82%) rename src/main/java/ru/ulstu/extractor/{ => gitrepository}/service/FilteringService.java (92%) rename src/main/java/ru/ulstu/extractor/gitrepository/{ => service}/GitRepositoryService.java (98%) rename src/main/java/ru/ulstu/extractor/{ => gitrepository}/service/IndexService.java (93%) rename src/main/java/ru/ulstu/extractor/{ => rule}/controller/RuleController.java (82%) rename src/main/java/ru/ulstu/extractor/{model/mvc => rule/model}/AddRuleForm.java (97%) rename src/main/java/ru/ulstu/extractor/{ => rule}/model/AntecedentValue.java (85%) rename src/main/java/ru/ulstu/extractor/{ => rule}/model/Rule.java (95%) rename src/main/java/ru/ulstu/extractor/{ => rule}/repository/AntecedentValueRepository.java (62%) rename src/main/java/ru/ulstu/extractor/{ => rule}/repository/RuleRepository.java (61%) rename src/main/java/ru/ulstu/extractor/{ => rule}/service/AntecedentValueService.java (81%) rename src/main/java/ru/ulstu/extractor/{ => rule}/service/RuleService.java (82%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/AbstractTimeSeriesCreator.java (87%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/AuthorTS.java (83%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/AuthorsCommentTS.java (84%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/AuthorsCompletedIssueTS.java (84%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/AuthorsIssueTS.java (84%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/BranchTS.java (83%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/ClassTS.java (83%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/CommitsTS.java (88%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/DependenceTS.java (83%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/EntityTS.java (83%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/FileTS.java (83%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/InterfaceTS.java (83%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/IssuesTS.java (84%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/ProcessTS.java (83%) rename src/main/java/ru/ulstu/extractor/ts/{ => creator}/StarTS.java (83%) rename src/main/java/ru/ulstu/extractor/{ => ts}/model/TimeSeries.java (93%) rename src/main/java/ru/ulstu/extractor/{ => ts}/model/TimeSeriesValue.java (89%) rename src/main/java/ru/ulstu/extractor/{ => ts}/repository/TimeSeriesRepository.java (71%) rename src/main/java/ru/ulstu/extractor/{ => ts}/repository/TimeSeriesValueRepository.java (80%) rename src/main/java/ru/ulstu/extractor/{ => ts}/service/TimeSeriesService.java (91%) rename src/main/java/ru/ulstu/extractor/ts/{ => util}/TimeSeriesDateMapper.java (94%) diff --git a/src/main/java/ru/ulstu/extractor/model/Author.java b/src/main/java/ru/ulstu/extractor/author/model/Author.java similarity index 79% rename from src/main/java/ru/ulstu/extractor/model/Author.java rename to src/main/java/ru/ulstu/extractor/author/model/Author.java index 2462d5b..efd5ba1 100644 --- a/src/main/java/ru/ulstu/extractor/model/Author.java +++ b/src/main/java/ru/ulstu/extractor/author/model/Author.java @@ -1,4 +1,6 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.author.model; + +import ru.ulstu.extractor.core.BaseEntity; import javax.persistence.Entity; diff --git a/src/main/java/ru/ulstu/extractor/repository/AuthorRepository.java b/src/main/java/ru/ulstu/extractor/author/repository/AuthorRepository.java similarity index 93% rename from src/main/java/ru/ulstu/extractor/repository/AuthorRepository.java rename to src/main/java/ru/ulstu/extractor/author/repository/AuthorRepository.java index 0ae8a20..e20f19d 100644 --- a/src/main/java/ru/ulstu/extractor/repository/AuthorRepository.java +++ b/src/main/java/ru/ulstu/extractor/author/repository/AuthorRepository.java @@ -3,13 +3,13 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.repository; +package ru.ulstu.extractor.author.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import ru.ulstu.extractor.author.model.Author; import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.model.Author; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/service/AuthorService.java b/src/main/java/ru/ulstu/extractor/author/service/AuthorService.java similarity index 85% rename from src/main/java/ru/ulstu/extractor/service/AuthorService.java rename to src/main/java/ru/ulstu/extractor/author/service/AuthorService.java index c04cfd1..659e17c 100644 --- a/src/main/java/ru/ulstu/extractor/service/AuthorService.java +++ b/src/main/java/ru/ulstu/extractor/author/service/AuthorService.java @@ -3,13 +3,13 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.service; +package ru.ulstu.extractor.author.service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import ru.ulstu.extractor.model.Author; -import ru.ulstu.extractor.repository.AuthorRepository; +import ru.ulstu.extractor.author.model.Author; +import ru.ulstu.extractor.author.repository.AuthorRepository; import java.util.Optional; diff --git a/src/main/java/ru/ulstu/extractor/branch/controller/BranchController.java b/src/main/java/ru/ulstu/extractor/branch/controller/BranchController.java index 22432bd..8b79a93 100644 --- a/src/main/java/ru/ulstu/extractor/branch/controller/BranchController.java +++ b/src/main/java/ru/ulstu/extractor/branch/controller/BranchController.java @@ -10,11 +10,11 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.extractor.branch.repository.BranchRepository; -import ru.ulstu.extractor.gitrepository.GitRepositoryRepository; +import ru.ulstu.extractor.gitrepository.repository.GitRepositoryRepository; import springfox.documentation.annotations.ApiIgnore; -import static ru.ulstu.extractor.controller.Route.DELETE_BRANCH; -import static ru.ulstu.extractor.controller.Route.LIST_REPOSITORY_BRANCHES; +import static ru.ulstu.extractor.core.Route.DELETE_BRANCH; +import static ru.ulstu.extractor.core.Route.LIST_REPOSITORY_BRANCHES; @Controller @ApiIgnore diff --git a/src/main/java/ru/ulstu/extractor/branch/model/Branch.java b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java index 6837771..12a9f01 100644 --- a/src/main/java/ru/ulstu/extractor/branch/model/Branch.java +++ b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java @@ -7,8 +7,8 @@ package ru.ulstu.extractor.branch.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import ru.ulstu.extractor.core.BaseEntity; import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.model.BaseEntity; import ru.ulstu.extractor.model.Commit; import javax.persistence.CascadeType; diff --git a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java index 3d6fd28..ebb51aa 100644 --- a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java +++ b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java @@ -12,8 +12,8 @@ import org.springframework.transaction.annotation.Transactional; import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.repository.BranchRepository; import ru.ulstu.extractor.commit.service.CommitService; +import ru.ulstu.extractor.core.BaseEntity; import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.model.BaseEntity; import ru.ulstu.extractor.model.Commit; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/commit/model/Commit.java b/src/main/java/ru/ulstu/extractor/commit/model/Commit.java index 699ff94..9f8f109 100644 --- a/src/main/java/ru/ulstu/extractor/commit/model/Commit.java +++ b/src/main/java/ru/ulstu/extractor/commit/model/Commit.java @@ -7,7 +7,10 @@ package ru.ulstu.extractor.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import ru.ulstu.extractor.author.model.Author; import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.core.BaseEntity; +import ru.ulstu.extractor.gitrepository.model.FileChange; import javax.persistence.CascadeType; import javax.persistence.Entity; diff --git a/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java b/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java index fd1c449..050437a 100644 --- a/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java +++ b/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java @@ -7,9 +7,9 @@ package ru.ulstu.extractor.commit.service; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; +import ru.ulstu.extractor.author.service.AuthorService; import ru.ulstu.extractor.commit.repository.CommitRepository; import ru.ulstu.extractor.model.Commit; -import ru.ulstu.extractor.service.AuthorService; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java b/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java index 035f359..d4f9a9c 100644 --- a/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java +++ b/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java @@ -10,7 +10,7 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import static ru.ulstu.extractor.controller.Route.LIST_INDEXED_REPOSITORIES; +import static ru.ulstu.extractor.core.Route.LIST_INDEXED_REPOSITORIES; @Configuration public class MvcConfiguration implements WebMvcConfigurer { diff --git a/src/main/java/ru/ulstu/extractor/model/BaseEntity.java b/src/main/java/ru/ulstu/extractor/core/BaseEntity.java similarity index 98% rename from src/main/java/ru/ulstu/extractor/model/BaseEntity.java rename to src/main/java/ru/ulstu/extractor/core/BaseEntity.java index 0859807..43690f1 100644 --- a/src/main/java/ru/ulstu/extractor/model/BaseEntity.java +++ b/src/main/java/ru/ulstu/extractor/core/BaseEntity.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.core; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/src/main/java/ru/ulstu/extractor/model/OffsetablePageRequest.java b/src/main/java/ru/ulstu/extractor/core/OffsetablePageRequest.java similarity index 98% rename from src/main/java/ru/ulstu/extractor/model/OffsetablePageRequest.java rename to src/main/java/ru/ulstu/extractor/core/OffsetablePageRequest.java index e96673b..f48e7cc 100644 --- a/src/main/java/ru/ulstu/extractor/model/OffsetablePageRequest.java +++ b/src/main/java/ru/ulstu/extractor/core/OffsetablePageRequest.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.core; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; diff --git a/src/main/java/ru/ulstu/extractor/controller/Route.java b/src/main/java/ru/ulstu/extractor/core/Route.java similarity index 97% rename from src/main/java/ru/ulstu/extractor/controller/Route.java rename to src/main/java/ru/ulstu/extractor/core/Route.java index 77e1efe..9627848 100644 --- a/src/main/java/ru/ulstu/extractor/controller/Route.java +++ b/src/main/java/ru/ulstu/extractor/core/Route.java @@ -3,7 +3,7 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.controller; +package ru.ulstu.extractor.core; import org.springframework.stereotype.Component; diff --git a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitFilteringController.java similarity index 91% rename from src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java rename to src/main/java/ru/ulstu/extractor/gitrepository/controler/GitFilteringController.java index 5c036a8..25f9ee7 100644 --- a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitFilteringController.java @@ -3,7 +3,7 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.controller; +package ru.ulstu.extractor.gitrepository.controler; import org.springframework.data.domain.Page; import org.springframework.stereotype.Controller; @@ -11,10 +11,10 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import ru.ulstu.extractor.core.OffsetablePageRequest; +import ru.ulstu.extractor.gitrepository.model.FilterForm; +import ru.ulstu.extractor.gitrepository.service.FilteringService; import ru.ulstu.extractor.model.Commit; -import ru.ulstu.extractor.model.OffsetablePageRequest; -import ru.ulstu.extractor.model.mvc.FilterForm; -import ru.ulstu.extractor.service.FilteringService; import springfox.documentation.annotations.ApiIgnore; import java.util.List; @@ -22,7 +22,7 @@ import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.IntStream; -import static ru.ulstu.extractor.controller.Route.FILTER_COMMITS; +import static ru.ulstu.extractor.core.Route.FILTER_COMMITS; @Controller @ApiIgnore diff --git a/src/main/java/ru/ulstu/extractor/controller/GitIndexingController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitIndexingController.java similarity index 87% rename from src/main/java/ru/ulstu/extractor/controller/GitIndexingController.java rename to src/main/java/ru/ulstu/extractor/gitrepository/controler/GitIndexingController.java index 7708a1f..e610db7 100644 --- a/src/main/java/ru/ulstu/extractor/controller/GitIndexingController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitIndexingController.java @@ -3,7 +3,7 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.controller; +package ru.ulstu.extractor.gitrepository.controler; import org.eclipse.jgit.api.errors.GitAPIException; import org.slf4j.Logger; @@ -16,17 +16,17 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import ru.ulstu.extractor.branch.model.Branch; -import ru.ulstu.extractor.gitrepository.GitRepositoryService; -import ru.ulstu.extractor.model.mvc.FilterForm; -import ru.ulstu.extractor.model.mvc.RepoForm; -import ru.ulstu.extractor.service.IndexService; +import ru.ulstu.extractor.gitrepository.model.FilterForm; +import ru.ulstu.extractor.gitrepository.model.RepoForm; +import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; +import ru.ulstu.extractor.gitrepository.service.IndexService; import springfox.documentation.annotations.ApiIgnore; import java.io.IOException; import java.util.List; -import static ru.ulstu.extractor.controller.Route.FILTER_COMMITS; -import static ru.ulstu.extractor.controller.Route.INDEXING_NEW_REPOSITORY; +import static ru.ulstu.extractor.core.Route.FILTER_COMMITS; +import static ru.ulstu.extractor.core.Route.INDEXING_NEW_REPOSITORY; @Controller @ApiIgnore diff --git a/src/main/java/ru/ulstu/extractor/controller/RepoController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepoController.java similarity index 89% rename from src/main/java/ru/ulstu/extractor/controller/RepoController.java rename to src/main/java/ru/ulstu/extractor/gitrepository/controler/RepoController.java index 847003d..bc14f79 100644 --- a/src/main/java/ru/ulstu/extractor/controller/RepoController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepoController.java @@ -3,7 +3,7 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.controller; +package ru.ulstu.extractor.gitrepository.controler; import org.eclipse.jgit.api.errors.GitAPIException; import org.slf4j.Logger; @@ -12,16 +12,16 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import ru.ulstu.extractor.gitrepository.GitRepositoryService; +import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; +import ru.ulstu.extractor.gitrepository.service.IndexService; import ru.ulstu.extractor.model.Commit; -import ru.ulstu.extractor.service.IndexService; import ru.ulstu.extractor.util.HttpUtils; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.List; -import static ru.ulstu.extractor.controller.RepoController.URL; +import static ru.ulstu.extractor.gitrepository.controler.RepoController.URL; @RestController @RequestMapping(URL) diff --git a/src/main/java/ru/ulstu/extractor/controller/RepositoryController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java similarity index 82% rename from src/main/java/ru/ulstu/extractor/controller/RepositoryController.java rename to src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java index ee5de82..69b643b 100644 --- a/src/main/java/ru/ulstu/extractor/controller/RepositoryController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java @@ -3,17 +3,17 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.controller; +package ru.ulstu.extractor.gitrepository.controler; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; -import ru.ulstu.extractor.gitrepository.GitRepositoryRepository; +import ru.ulstu.extractor.gitrepository.repository.GitRepositoryRepository; import springfox.documentation.annotations.ApiIgnore; -import static ru.ulstu.extractor.controller.Route.DELETE_INDEXED_REPOSITORY; -import static ru.ulstu.extractor.controller.Route.LIST_INDEXED_REPOSITORIES; +import static ru.ulstu.extractor.core.Route.DELETE_INDEXED_REPOSITORY; +import static ru.ulstu.extractor.core.Route.LIST_INDEXED_REPOSITORIES; @Controller @ApiIgnore diff --git a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java similarity index 96% rename from src/main/java/ru/ulstu/extractor/controller/StatisticController.java rename to src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java index 771a5a0..eb2024e 100644 --- a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java @@ -3,7 +3,7 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.controller; +package ru.ulstu.extractor.gitrepository.controler; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -11,15 +11,15 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.repository.CommitRepository; -import ru.ulstu.extractor.model.mvc.FilterForm; -import ru.ulstu.extractor.service.FilteringService; +import ru.ulstu.extractor.gitrepository.model.FilterForm; +import ru.ulstu.extractor.gitrepository.service.FilteringService; import springfox.documentation.annotations.ApiIgnore; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import static ru.ulstu.extractor.controller.Route.STATISTIC; +import static ru.ulstu.extractor.core.Route.STATISTIC; @Controller @ApiIgnore diff --git a/src/main/java/ru/ulstu/extractor/model/FileChange.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/FileChange.java similarity index 96% rename from src/main/java/ru/ulstu/extractor/model/FileChange.java rename to src/main/java/ru/ulstu/extractor/gitrepository/model/FileChange.java index 5f33725..65d0815 100644 --- a/src/main/java/ru/ulstu/extractor/model/FileChange.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/FileChange.java @@ -3,10 +3,11 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.gitrepository.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import ru.ulstu.extractor.core.BaseEntity; import javax.persistence.CascadeType; import javax.persistence.Entity; diff --git a/src/main/java/ru/ulstu/extractor/model/mvc/FilterForm.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/FilterForm.java similarity index 97% rename from src/main/java/ru/ulstu/extractor/model/mvc/FilterForm.java rename to src/main/java/ru/ulstu/extractor/gitrepository/model/FilterForm.java index 1db7616..d25271f 100644 --- a/src/main/java/ru/ulstu/extractor/model/mvc/FilterForm.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/FilterForm.java @@ -3,7 +3,7 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.model.mvc; +package ru.ulstu.extractor.gitrepository.model; import org.springframework.data.domain.Page; import ru.ulstu.extractor.model.Commit; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java index 3d5c605..f2b8276 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java @@ -1,6 +1,6 @@ package ru.ulstu.extractor.gitrepository.model; -import ru.ulstu.extractor.model.BaseEntity; +import ru.ulstu.extractor.core.BaseEntity; import javax.persistence.Entity; diff --git a/src/main/java/ru/ulstu/extractor/model/LineChange.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/LineChange.java similarity index 93% rename from src/main/java/ru/ulstu/extractor/model/LineChange.java rename to src/main/java/ru/ulstu/extractor/gitrepository/model/LineChange.java index 923909b..99d78b3 100644 --- a/src/main/java/ru/ulstu/extractor/model/LineChange.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/LineChange.java @@ -3,7 +3,9 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.gitrepository.model; + +import ru.ulstu.extractor.core.BaseEntity; import javax.persistence.Entity; diff --git a/src/main/java/ru/ulstu/extractor/model/mvc/RepoForm.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/RepoForm.java similarity index 91% rename from src/main/java/ru/ulstu/extractor/model/mvc/RepoForm.java rename to src/main/java/ru/ulstu/extractor/gitrepository/model/RepoForm.java index e0ca0aa..0540820 100644 --- a/src/main/java/ru/ulstu/extractor/model/mvc/RepoForm.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/RepoForm.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.model.mvc; +package ru.ulstu.extractor.gitrepository.model; public class RepoForm { private String repo; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryRepository.java b/src/main/java/ru/ulstu/extractor/gitrepository/repository/GitRepositoryRepository.java similarity index 82% rename from src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryRepository.java rename to src/main/java/ru/ulstu/extractor/gitrepository/repository/GitRepositoryRepository.java index ae9e821..40307d7 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryRepository.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/repository/GitRepositoryRepository.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.gitrepository; +package ru.ulstu.extractor.gitrepository.repository; import org.springframework.data.jpa.repository.JpaRepository; import ru.ulstu.extractor.gitrepository.model.GitRepository; diff --git a/src/main/java/ru/ulstu/extractor/service/FilteringService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/FilteringService.java similarity index 92% rename from src/main/java/ru/ulstu/extractor/service/FilteringService.java rename to src/main/java/ru/ulstu/extractor/gitrepository/service/FilteringService.java index ddeda0c..ccc29de 100644 --- a/src/main/java/ru/ulstu/extractor/service/FilteringService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/FilteringService.java @@ -3,16 +3,16 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.service; +package ru.ulstu.extractor.gitrepository.service; import com.sun.istack.NotNull; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import ru.ulstu.extractor.author.repository.AuthorRepository; import ru.ulstu.extractor.commit.repository.CommitRepository; -import ru.ulstu.extractor.gitrepository.GitRepositoryRepository; +import ru.ulstu.extractor.gitrepository.repository.GitRepositoryRepository; import ru.ulstu.extractor.model.Commit; -import ru.ulstu.extractor.repository.AuthorRepository; import java.util.List; import java.util.Map; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java similarity index 98% rename from src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryService.java rename to src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java index 934f920..78038ad 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.gitrepository; +package ru.ulstu.extractor.gitrepository.service; import org.apache.commons.io.FileUtils; import org.eclipse.jgit.api.CreateBranchCommand; @@ -18,16 +18,17 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import ru.ulstu.extractor.author.model.Author; import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.model.FileChange; import ru.ulstu.extractor.gitrepository.model.GitRepository; +import ru.ulstu.extractor.gitrepository.model.LineChange; +import ru.ulstu.extractor.gitrepository.repository.GitRepositoryRepository; import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit; import ru.ulstu.extractor.heuristic.model.EntityUnit; import ru.ulstu.extractor.heuristic.model.ResourceUnit; import ru.ulstu.extractor.heuristic.service.StructuralUnitService; -import ru.ulstu.extractor.model.Author; import ru.ulstu.extractor.model.Commit; -import ru.ulstu.extractor.model.FileChange; -import ru.ulstu.extractor.model.LineChange; import java.io.ByteArrayOutputStream; import java.io.File; diff --git a/src/main/java/ru/ulstu/extractor/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java similarity index 93% rename from src/main/java/ru/ulstu/extractor/service/IndexService.java rename to src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index d5415e2..5d2c1c2 100644 --- a/src/main/java/ru/ulstu/extractor/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -3,7 +3,7 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.service; +package ru.ulstu.extractor.gitrepository.service; import com.sun.istack.NotNull; import org.eclipse.jgit.api.errors.GitAPIException; @@ -12,11 +12,10 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.GitRepositoryRepository; -import ru.ulstu.extractor.gitrepository.GitRepositoryService; import ru.ulstu.extractor.gitrepository.model.GitRepository; +import ru.ulstu.extractor.gitrepository.repository.GitRepositoryRepository; import ru.ulstu.extractor.model.Commit; -import ru.ulstu.extractor.ts.AbstractTimeSeriesCreator; +import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import java.io.IOException; import java.util.Collections; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java b/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java index ccedc05..db95ab2 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java @@ -11,7 +11,7 @@ import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import ru.ulstu.extractor.gitrepository.GitRepositoryService; +import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit; import ru.ulstu.extractor.heuristic.model.EntityUnit; import ru.ulstu.extractor.heuristic.model.ResourceUnit; diff --git a/src/main/java/ru/ulstu/extractor/http/JsonTimeSeries.java b/src/main/java/ru/ulstu/extractor/http/JsonTimeSeries.java index 71506d1..957869c 100644 --- a/src/main/java/ru/ulstu/extractor/http/JsonTimeSeries.java +++ b/src/main/java/ru/ulstu/extractor/http/JsonTimeSeries.java @@ -1,6 +1,6 @@ package ru.ulstu.extractor.http; -import ru.ulstu.extractor.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeries; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/ru/ulstu/extractor/http/JsonTimeSeriesValue.java b/src/main/java/ru/ulstu/extractor/http/JsonTimeSeriesValue.java index f615f7d..a50681c 100644 --- a/src/main/java/ru/ulstu/extractor/http/JsonTimeSeriesValue.java +++ b/src/main/java/ru/ulstu/extractor/http/JsonTimeSeriesValue.java @@ -1,6 +1,6 @@ package ru.ulstu.extractor.http; -import ru.ulstu.extractor.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; import java.time.LocalDateTime; import java.time.ZoneId; diff --git a/src/main/java/ru/ulstu/extractor/controller/RuleController.java b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java similarity index 82% rename from src/main/java/ru/ulstu/extractor/controller/RuleController.java rename to src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java index 038005b..6369e5f 100644 --- a/src/main/java/ru/ulstu/extractor/controller/RuleController.java +++ b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.controller; +package ru.ulstu.extractor.rule.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -7,14 +7,14 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.mvc.support.RedirectAttributes; -import ru.ulstu.extractor.model.mvc.AddRuleForm; -import ru.ulstu.extractor.service.AntecedentValueService; -import ru.ulstu.extractor.service.RuleService; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.rule.model.AddRuleForm; +import ru.ulstu.extractor.rule.service.AntecedentValueService; +import ru.ulstu.extractor.rule.service.RuleService; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; -import static ru.ulstu.extractor.controller.Route.ADD_RULE; -import static ru.ulstu.extractor.controller.Route.LIST_RULE; +import static ru.ulstu.extractor.core.Route.ADD_RULE; +import static ru.ulstu.extractor.core.Route.LIST_RULE; @Controller @ApiIgnore diff --git a/src/main/java/ru/ulstu/extractor/model/mvc/AddRuleForm.java b/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java similarity index 97% rename from src/main/java/ru/ulstu/extractor/model/mvc/AddRuleForm.java rename to src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java index cf164d8..1fd344e 100644 --- a/src/main/java/ru/ulstu/extractor/model/mvc/AddRuleForm.java +++ b/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.model.mvc; +package ru.ulstu.extractor.rule.model; public class AddRuleForm { private Integer firstAntecedentValueId; diff --git a/src/main/java/ru/ulstu/extractor/model/AntecedentValue.java b/src/main/java/ru/ulstu/extractor/rule/model/AntecedentValue.java similarity index 85% rename from src/main/java/ru/ulstu/extractor/model/AntecedentValue.java rename to src/main/java/ru/ulstu/extractor/rule/model/AntecedentValue.java index 1ed3473..39b5eb6 100644 --- a/src/main/java/ru/ulstu/extractor/model/AntecedentValue.java +++ b/src/main/java/ru/ulstu/extractor/rule/model/AntecedentValue.java @@ -1,4 +1,6 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.rule.model; + +import ru.ulstu.extractor.core.BaseEntity; import javax.persistence.Entity; diff --git a/src/main/java/ru/ulstu/extractor/model/Rule.java b/src/main/java/ru/ulstu/extractor/rule/model/Rule.java similarity index 95% rename from src/main/java/ru/ulstu/extractor/model/Rule.java rename to src/main/java/ru/ulstu/extractor/rule/model/Rule.java index baf8565..e9efa92 100644 --- a/src/main/java/ru/ulstu/extractor/model/Rule.java +++ b/src/main/java/ru/ulstu/extractor/rule/model/Rule.java @@ -1,4 +1,7 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.rule.model; + +import ru.ulstu.extractor.core.BaseEntity; +import ru.ulstu.extractor.ts.model.TimeSeries; import javax.persistence.Entity; import javax.persistence.ManyToOne; diff --git a/src/main/java/ru/ulstu/extractor/repository/AntecedentValueRepository.java b/src/main/java/ru/ulstu/extractor/rule/repository/AntecedentValueRepository.java similarity index 62% rename from src/main/java/ru/ulstu/extractor/repository/AntecedentValueRepository.java rename to src/main/java/ru/ulstu/extractor/rule/repository/AntecedentValueRepository.java index 86ea561..1ea84d7 100644 --- a/src/main/java/ru/ulstu/extractor/repository/AntecedentValueRepository.java +++ b/src/main/java/ru/ulstu/extractor/rule/repository/AntecedentValueRepository.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.repository; +package ru.ulstu.extractor.rule.repository; import org.springframework.data.jpa.repository.JpaRepository; -import ru.ulstu.extractor.model.AntecedentValue; +import ru.ulstu.extractor.rule.model.AntecedentValue; public interface AntecedentValueRepository extends JpaRepository { } diff --git a/src/main/java/ru/ulstu/extractor/repository/RuleRepository.java b/src/main/java/ru/ulstu/extractor/rule/repository/RuleRepository.java similarity index 61% rename from src/main/java/ru/ulstu/extractor/repository/RuleRepository.java rename to src/main/java/ru/ulstu/extractor/rule/repository/RuleRepository.java index e931488..2504386 100644 --- a/src/main/java/ru/ulstu/extractor/repository/RuleRepository.java +++ b/src/main/java/ru/ulstu/extractor/rule/repository/RuleRepository.java @@ -1,7 +1,7 @@ -package ru.ulstu.extractor.repository; +package ru.ulstu.extractor.rule.repository; import org.springframework.data.jpa.repository.JpaRepository; -import ru.ulstu.extractor.model.Rule; +import ru.ulstu.extractor.rule.model.Rule; public interface RuleRepository extends JpaRepository { } diff --git a/src/main/java/ru/ulstu/extractor/service/AntecedentValueService.java b/src/main/java/ru/ulstu/extractor/rule/service/AntecedentValueService.java similarity index 81% rename from src/main/java/ru/ulstu/extractor/service/AntecedentValueService.java rename to src/main/java/ru/ulstu/extractor/rule/service/AntecedentValueService.java index e2c48e6..ef3c124 100644 --- a/src/main/java/ru/ulstu/extractor/service/AntecedentValueService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/AntecedentValueService.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.service; +package ru.ulstu.extractor.rule.service; import org.springframework.stereotype.Service; -import ru.ulstu.extractor.model.AntecedentValue; -import ru.ulstu.extractor.repository.AntecedentValueRepository; +import ru.ulstu.extractor.rule.model.AntecedentValue; +import ru.ulstu.extractor.rule.repository.AntecedentValueRepository; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/service/RuleService.java b/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java similarity index 82% rename from src/main/java/ru/ulstu/extractor/service/RuleService.java rename to src/main/java/ru/ulstu/extractor/rule/service/RuleService.java index 5c8acd7..46a95a6 100644 --- a/src/main/java/ru/ulstu/extractor/service/RuleService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java @@ -1,9 +1,10 @@ -package ru.ulstu.extractor.service; +package ru.ulstu.extractor.rule.service; import org.springframework.stereotype.Service; -import ru.ulstu.extractor.model.Rule; -import ru.ulstu.extractor.model.mvc.AddRuleForm; -import ru.ulstu.extractor.repository.RuleRepository; +import ru.ulstu.extractor.rule.model.AddRuleForm; +import ru.ulstu.extractor.rule.model.Rule; +import ru.ulstu.extractor.rule.repository.RuleRepository; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/AbstractTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java similarity index 87% rename from src/main/java/ru/ulstu/extractor/ts/AbstractTimeSeriesCreator.java rename to src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java index 07b516b..ce4593d 100644 --- a/src/main/java/ru/ulstu/extractor/ts/AbstractTimeSeriesCreator.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java @@ -1,13 +1,13 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +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.TimeSeriesDateMapper.mapTimeSeriesToInterval; +import static ru.ulstu.extractor.ts.util.TimeSeriesDateMapper.mapTimeSeriesToInterval; public abstract class AbstractTimeSeriesCreator { diff --git a/src/main/java/ru/ulstu/extractor/ts/AuthorTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java similarity index 83% rename from src/main/java/ru/ulstu/extractor/ts/AuthorTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java index a6d01dc..63e4b3b 100644 --- a/src/main/java/ru/ulstu/extractor/ts/AuthorTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/AuthorsCommentTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommentTS.java similarity index 84% rename from src/main/java/ru/ulstu/extractor/ts/AuthorsCommentTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommentTS.java index 62ea9a7..bb1ebef 100644 --- a/src/main/java/ru/ulstu/extractor/ts/AuthorsCommentTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommentTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/AuthorsCompletedIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java similarity index 84% rename from src/main/java/ru/ulstu/extractor/ts/AuthorsCompletedIssueTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java index 7453fdb..5112c0b 100644 --- a/src/main/java/ru/ulstu/extractor/ts/AuthorsCompletedIssueTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/AuthorsIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java similarity index 84% rename from src/main/java/ru/ulstu/extractor/ts/AuthorsIssueTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java index d7318da..209ee59 100644 --- a/src/main/java/ru/ulstu/extractor/ts/AuthorsIssueTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/BranchTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java similarity index 83% rename from src/main/java/ru/ulstu/extractor/ts/BranchTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java index 6233909..95c237d 100644 --- a/src/main/java/ru/ulstu/extractor/ts/BranchTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/ClassTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java similarity index 83% rename from src/main/java/ru/ulstu/extractor/ts/ClassTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java index 1fdf504..c6bb4a1 100644 --- a/src/main/java/ru/ulstu/extractor/ts/ClassTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/CommitsTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java similarity index 88% rename from src/main/java/ru/ulstu/extractor/ts/CommitsTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java index 2196c20..cbd444f 100644 --- a/src/main/java/ru/ulstu/extractor/ts/CommitsTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java @@ -1,10 +1,10 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; import ru.ulstu.extractor.commit.service.CommitService; -import ru.ulstu.extractor.gitrepository.GitRepositoryService; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/DependenceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java similarity index 83% rename from src/main/java/ru/ulstu/extractor/ts/DependenceTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java index 26c0e39..dd511fb 100644 --- a/src/main/java/ru/ulstu/extractor/ts/DependenceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/EntityTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java similarity index 83% rename from src/main/java/ru/ulstu/extractor/ts/EntityTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java index ff6a2d9..183a12e 100644 --- a/src/main/java/ru/ulstu/extractor/ts/EntityTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/FileTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java similarity index 83% rename from src/main/java/ru/ulstu/extractor/ts/FileTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java index e90ce57..cb2279b 100644 --- a/src/main/java/ru/ulstu/extractor/ts/FileTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/InterfaceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java similarity index 83% rename from src/main/java/ru/ulstu/extractor/ts/InterfaceTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java index 7d26f00..55d4341 100644 --- a/src/main/java/ru/ulstu/extractor/ts/InterfaceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/IssuesTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java similarity index 84% rename from src/main/java/ru/ulstu/extractor/ts/IssuesTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java index 51ecffd..23a40d5 100644 --- a/src/main/java/ru/ulstu/extractor/ts/IssuesTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/ProcessTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java similarity index 83% rename from src/main/java/ru/ulstu/extractor/ts/ProcessTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java index bc4b322..0a7c05f 100644 --- a/src/main/java/ru/ulstu/extractor/ts/ProcessTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/ts/StarTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java similarity index 83% rename from src/main/java/ru/ulstu/extractor/ts/StarTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java index 38455a3..ddab245 100644 --- a/src/main/java/ru/ulstu/extractor/ts/StarTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.TimeSeriesService; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/model/TimeSeries.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java similarity index 93% rename from src/main/java/ru/ulstu/extractor/model/TimeSeries.java rename to src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java index d04db07..8be74b1 100644 --- a/src/main/java/ru/ulstu/extractor/model/TimeSeries.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java @@ -1,7 +1,8 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.ts.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import ru.ulstu.extractor.core.BaseEntity; import javax.persistence.CascadeType; import javax.persistence.Entity; diff --git a/src/main/java/ru/ulstu/extractor/model/TimeSeriesValue.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java similarity index 89% rename from src/main/java/ru/ulstu/extractor/model/TimeSeriesValue.java rename to src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java index 06fc168..112b4c5 100644 --- a/src/main/java/ru/ulstu/extractor/model/TimeSeriesValue.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java @@ -1,4 +1,6 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.ts.model; + +import ru.ulstu.extractor.core.BaseEntity; import javax.persistence.Entity; import java.util.Date; diff --git a/src/main/java/ru/ulstu/extractor/repository/TimeSeriesRepository.java b/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesRepository.java similarity index 71% rename from src/main/java/ru/ulstu/extractor/repository/TimeSeriesRepository.java rename to src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesRepository.java index e324774..fbb123e 100644 --- a/src/main/java/ru/ulstu/extractor/repository/TimeSeriesRepository.java +++ b/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesRepository.java @@ -1,7 +1,7 @@ -package ru.ulstu.extractor.repository; +package ru.ulstu.extractor.ts.repository; import org.springframework.data.jpa.repository.JpaRepository; -import ru.ulstu.extractor.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeries; import java.util.Optional; diff --git a/src/main/java/ru/ulstu/extractor/repository/TimeSeriesValueRepository.java b/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesValueRepository.java similarity index 80% rename from src/main/java/ru/ulstu/extractor/repository/TimeSeriesValueRepository.java rename to src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesValueRepository.java index b603ed5..e334bf2 100644 --- a/src/main/java/ru/ulstu/extractor/repository/TimeSeriesValueRepository.java +++ b/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesValueRepository.java @@ -1,7 +1,7 @@ -package ru.ulstu.extractor.repository; +package ru.ulstu.extractor.ts.repository; import org.springframework.data.jpa.repository.JpaRepository; -import ru.ulstu.extractor.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; import java.util.List; diff --git a/src/main/java/ru/ulstu/extractor/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java similarity index 91% rename from src/main/java/ru/ulstu/extractor/service/TimeSeriesService.java rename to src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java index f978433..f587ea2 100644 --- a/src/main/java/ru/ulstu/extractor/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -3,7 +3,7 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.service; +package ru.ulstu.extractor.ts.service; import org.json.JSONObject; import org.slf4j.Logger; @@ -11,14 +11,18 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import ru.ulstu.extractor.http.HttpService; import ru.ulstu.extractor.http.JsonTimeSeries; -import ru.ulstu.extractor.model.TimeSeries; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.repository.TimeSeriesRepository; -import ru.ulstu.extractor.repository.TimeSeriesValueRepository; -import ru.ulstu.extractor.ts.TimeSeriesDateMapper; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.repository.TimeSeriesRepository; +import ru.ulstu.extractor.ts.repository.TimeSeriesValueRepository; +import ru.ulstu.extractor.ts.util.TimeSeriesDateMapper; import javax.transaction.Transactional; -import java.util.*; +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 diff --git a/src/main/java/ru/ulstu/extractor/ts/TimeSeriesDateMapper.java b/src/main/java/ru/ulstu/extractor/ts/util/TimeSeriesDateMapper.java similarity index 94% rename from src/main/java/ru/ulstu/extractor/ts/TimeSeriesDateMapper.java rename to src/main/java/ru/ulstu/extractor/ts/util/TimeSeriesDateMapper.java index dec6918..7a17646 100644 --- a/src/main/java/ru/ulstu/extractor/ts/TimeSeriesDateMapper.java +++ b/src/main/java/ru/ulstu/extractor/ts/util/TimeSeriesDateMapper.java @@ -1,8 +1,8 @@ -package ru.ulstu.extractor.ts; +package ru.ulstu.extractor.ts.util; import org.apache.commons.lang3.time.DateUtils; -import ru.ulstu.extractor.model.TimeSeries; -import ru.ulstu.extractor.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; import java.util.Calendar; import java.util.Date; diff --git a/src/test/java/ru/ulstu/TimeSeriesMapperTest.java b/src/test/java/ru/ulstu/TimeSeriesMapperTest.java index 91030f9..c1cae8d 100644 --- a/src/test/java/ru/ulstu/TimeSeriesMapperTest.java +++ b/src/test/java/ru/ulstu/TimeSeriesMapperTest.java @@ -2,9 +2,9 @@ package ru.ulstu; import org.junit.Assert; import org.junit.Test; -import ru.ulstu.extractor.model.TimeSeries; -import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.ts.TimeSeriesDateMapper; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.util.TimeSeriesDateMapper; import java.util.Arrays; import java.util.Calendar; -- 2.34.1 From bfec08c1f4556943f2e764b6c6401946e85fbafc Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 15 Oct 2022 23:37:22 +0400 Subject: [PATCH 010/110] #72 -- add time series type --- .../ts/creator/AbstractTimeSeriesCreator.java | 23 ++++---- .../ulstu/extractor/ts/creator/AuthorTS.java | 14 ++--- .../ts/creator/AuthorsCommentTS.java | 33 ------------ .../extractor/ts/creator/AuthorsCommitTS.java | 33 ++++++++++++ .../ts/creator/AuthorsCompletedIssueTS.java | 20 +++---- .../extractor/ts/creator/AuthorsIssueTS.java | 20 +++---- .../ulstu/extractor/ts/creator/BranchTS.java | 14 ++--- .../ulstu/extractor/ts/creator/ClassTS.java | 20 +++---- .../ulstu/extractor/ts/creator/CommitsTS.java | 37 +++++++------ .../extractor/ts/creator/DependenceTS.java | 20 +++---- .../ulstu/extractor/ts/creator/EntityTS.java | 20 +++---- .../ru/ulstu/extractor/ts/creator/FileTS.java | 20 +++---- .../extractor/ts/creator/InterfaceTS.java | 20 +++---- .../ulstu/extractor/ts/creator/IssuesTS.java | 20 +++---- .../ulstu/extractor/ts/creator/ProcessTS.java | 20 +++---- .../ru/ulstu/extractor/ts/creator/StarTS.java | 20 +++---- .../ulstu/extractor/ts/model/TimeSeries.java | 18 +++++++ .../extractor/ts/model/TimeSeriesType.java | 28 ++++++++++ .../ts/service/TimeSeriesService.java | 52 ++++++------------- .../db/changelog-20221012_170000-schema.xml | 5 ++ 20 files changed, 246 insertions(+), 211 deletions(-) delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommentTS.java create mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java create mode 100644 src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java 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 -- 2.34.1 From 49598824db667b6807f0b17bfcce37c6e80f3549 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 16 Oct 2022 01:15:26 +0400 Subject: [PATCH 011/110] #72 -- fix data model --- .../rule/controller/RuleController.java | 6 ++- .../extractor/rule/model/AddRuleForm.java | 12 ++--- .../ru/ulstu/extractor/rule/model/Rule.java | 39 ++++++---------- .../extractor/rule/service/RuleService.java | 5 ++- .../ts/service/TimeSeriesService.java | 5 +++ .../db/changelog-20221012_170000-schema.xml | 31 +++++++++++++ src/main/resources/templates/addRule.html | 45 ++++++++++--------- src/main/resources/templates/listRules.html | 4 +- 8 files changed, 88 insertions(+), 59 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java index 6369e5f..7aeeff1 100644 --- a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java @@ -23,7 +23,9 @@ public class RuleController { private final AntecedentValueService antecedentValueService; private final TimeSeriesService timeSeriesService; - public RuleController(RuleService ruleService, AntecedentValueService antecedentValueService, TimeSeriesService timeSeriesService) { + public RuleController(RuleService ruleService, + AntecedentValueService antecedentValueService, + TimeSeriesService timeSeriesService) { this.ruleService = ruleService; this.antecedentValueService = antecedentValueService; this.timeSeriesService = timeSeriesService; @@ -38,7 +40,7 @@ public class RuleController { @GetMapping(ADD_RULE) public String getAntecedent(Model model) { model.addAttribute("antecedentValues", antecedentValueService.getList()); - model.addAttribute("antecedents", timeSeriesService.getAllTimeSeries()); + model.addAttribute("antecedents", timeSeriesService.getAllTimeSeriesTypes()); model.addAttribute("addRuleForm", new AddRuleForm()); return ADD_RULE; } diff --git a/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java b/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java index 1fd344e..3b64bdd 100644 --- a/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java +++ b/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java @@ -2,9 +2,9 @@ package ru.ulstu.extractor.rule.model; public class AddRuleForm { private Integer firstAntecedentValueId; - private Integer firstAntecedentId; + private String firstAntecedentId; private Integer secondAntecedentValueId; - private Integer secondAntecedentId; + private String secondAntecedentId; private String consequent; public AddRuleForm() { @@ -18,11 +18,11 @@ public class AddRuleForm { this.firstAntecedentValueId = firstAntecedentValueId; } - public Integer getFirstAntecedentId() { + public String getFirstAntecedentId() { return firstAntecedentId; } - public void setFirstAntecedentId(Integer firstAntecedentId) { + public void setFirstAntecedentId(String firstAntecedentId) { this.firstAntecedentId = firstAntecedentId; } @@ -34,11 +34,11 @@ public class AddRuleForm { this.secondAntecedentValueId = secondAntecedentValueId; } - public Integer getSecondAntecedentId() { + public String getSecondAntecedentId() { return secondAntecedentId; } - public void setSecondAntecedentId(Integer secondAntecedentId) { + public void setSecondAntecedentId(String secondAntecedentId) { this.secondAntecedentId = secondAntecedentId; } diff --git a/src/main/java/ru/ulstu/extractor/rule/model/Rule.java b/src/main/java/ru/ulstu/extractor/rule/model/Rule.java index e9efa92..73d015c 100644 --- a/src/main/java/ru/ulstu/extractor/rule/model/Rule.java +++ b/src/main/java/ru/ulstu/extractor/rule/model/Rule.java @@ -1,9 +1,11 @@ package ru.ulstu.extractor.rule.model; import ru.ulstu.extractor.core.BaseEntity; -import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.ManyToOne; @Entity @@ -11,14 +13,14 @@ public class Rule extends BaseEntity { @ManyToOne private AntecedentValue firstAntecedentValue; - @ManyToOne - private TimeSeries firstAntecedent; + @Enumerated(EnumType.STRING) + private TimeSeriesType firstAntecedent; @ManyToOne private AntecedentValue secondAntecedentValue; - @ManyToOne - private TimeSeries secondAntecedent; + @Enumerated(EnumType.STRING) + private TimeSeriesType secondAntecedent; private String consequent; @@ -26,9 +28,9 @@ public class Rule extends BaseEntity { } public Rule(AntecedentValue firstAntecedentValue, - TimeSeries firstAntecedent, + TimeSeriesType firstAntecedent, AntecedentValue secondAntecedentValue, - TimeSeries secondAntecedent, + TimeSeriesType secondAntecedent, String consequent) { this.firstAntecedentValue = firstAntecedentValue; this.firstAntecedent = firstAntecedent; @@ -37,21 +39,6 @@ public class Rule extends BaseEntity { this.consequent = consequent; } - public Rule(Integer id, - Integer version, - AntecedentValue firstAntecedentValue, - TimeSeries firstAntecedent, - AntecedentValue secondAntecedentValue, - TimeSeries secondAntecedent, - String consequent) { - super(id, version); - this.firstAntecedentValue = firstAntecedentValue; - this.firstAntecedent = firstAntecedent; - this.secondAntecedentValue = secondAntecedentValue; - this.secondAntecedent = secondAntecedent; - this.consequent = consequent; - } - public AntecedentValue getFirstAntecedentValue() { return firstAntecedentValue; } @@ -60,11 +47,11 @@ public class Rule extends BaseEntity { this.firstAntecedentValue = firstAntecedentValue; } - public TimeSeries getFirstAntecedent() { + public TimeSeriesType getFirstAntecedent() { return firstAntecedent; } - public void setFirstAntecedent(TimeSeries firstAntecedent) { + public void setFirstAntecedent(TimeSeriesType firstAntecedent) { this.firstAntecedent = firstAntecedent; } @@ -76,11 +63,11 @@ public class Rule extends BaseEntity { this.secondAntecedentValue = secondAntecedentValue; } - public TimeSeries getSecondAntecedent() { + public TimeSeriesType getSecondAntecedent() { return secondAntecedent; } - public void setSecondAntecedent(TimeSeries secondAntecedent) { + public void setSecondAntecedent(TimeSeriesType secondAntecedent) { this.secondAntecedent = secondAntecedent; } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java b/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java index 46a95a6..63413b9 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java @@ -4,6 +4,7 @@ import org.springframework.stereotype.Service; import ru.ulstu.extractor.rule.model.AddRuleForm; import ru.ulstu.extractor.rule.model.Rule; import ru.ulstu.extractor.rule.repository.RuleRepository; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.List; @@ -28,9 +29,9 @@ public class RuleService { public void saveRule(AddRuleForm addRuleForm) { ruleRepository.save(new Rule(antecedentValueService.getById(addRuleForm.getFirstAntecedentValueId()), - timeSeriesService.getById(addRuleForm.getFirstAntecedentId()), + TimeSeriesType.valueOf(addRuleForm.getFirstAntecedentId()), antecedentValueService.getById(addRuleForm.getSecondAntecedentValueId()), - timeSeriesService.getById(addRuleForm.getSecondAntecedentId()), + TimeSeriesType.valueOf(addRuleForm.getSecondAntecedentId()), addRuleForm.getConsequent())); } } 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 c7da83c..9c79d0f 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -20,6 +20,7 @@ import ru.ulstu.extractor.ts.util.TimeSeriesDateMapper; import javax.transaction.Transactional; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -102,4 +103,8 @@ public class TimeSeriesService { return timeSeriesRepository.findById(tsId) .orElseThrow(() -> new RuntimeException("Time series not found by id " + tsId)); } + + public List getAllTimeSeriesTypes() { + return Arrays.asList(TimeSeriesType.values()); + } } diff --git a/src/main/resources/db/changelog-20221012_170000-schema.xml b/src/main/resources/db/changelog-20221012_170000-schema.xml index 61b2f4f..765df26 100644 --- a/src/main/resources/db/changelog-20221012_170000-schema.xml +++ b/src/main/resources/db/changelog-20221012_170000-schema.xml @@ -49,4 +49,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/addRule.html b/src/main/resources/templates/addRule.html index 8c709d0..191e07a 100644 --- a/src/main/resources/templates/addRule.html +++ b/src/main/resources/templates/addRule.html @@ -12,6 +12,19 @@
Если
+
+ +
+
+ имеет тенденцию +
- и + имеет тенденцию
-
- временной ряд -
-
- -
то:
-
+
-
+
+
+
+
diff --git a/src/main/resources/templates/listRules.html b/src/main/resources/templates/listRules.html index 93e139a..1f71b46 100644 --- a/src/main/resources/templates/listRules.html +++ b/src/main/resources/templates/listRules.html @@ -16,10 +16,10 @@ Если - + и - + то -- 2.34.1 From 00119b896cf8422135cc350d26fb392539f0e865 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 18 Oct 2022 00:19:07 +0400 Subject: [PATCH 012/110] #74 -- add some fuzzy rules --- build.gradle | 4 ++ .../extractor/GitExtractorApplication.java | 3 + .../rule/service/FuzzyInference.java | 70 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java diff --git a/build.gradle b/build.gradle index a94560f..e8eaefa 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,9 @@ compileJava { repositories { mavenLocal() mavenCentral() + maven { + url="https://repository.ow2.org/nexus/content/repositories/public" + } } configurations { @@ -65,6 +68,7 @@ dependencies { implementation group: 'com.ibm.icu', name: 'icu4j', version: '63.1' implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '5.9.0.202009080501-r' + implementation group: 'net.sourceforge.jFuzzyLogic', name: 'jFuzzyLogic', version: '1.2.1' implementation group: 'org.webjars', name: 'jquery', version: '3.6.0' implementation group: 'org.webjars', name: 'bootstrap', version: '4.6.0' diff --git a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java index f9a272d..85d9a30 100644 --- a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java +++ b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java @@ -3,11 +3,14 @@ package ru.ulstu.extractor; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; +import ru.ulstu.extractor.rule.service.FuzzyInference; @SpringBootApplication @EnableScheduling public class GitExtractorApplication { public static void main(String[] args) { + + new FuzzyInference().run(); SpringApplication.run(GitExtractorApplication.class, args); } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java new file mode 100644 index 0000000..54f99f4 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java @@ -0,0 +1,70 @@ +package ru.ulstu.extractor.rule.service; + +import net.sourceforge.jFuzzyLogic.defuzzifier.DefuzzifierCenterOfArea; +import net.sourceforge.jFuzzyLogic.membership.MembershipFunctionTriangular; +import net.sourceforge.jFuzzyLogic.rule.FuzzyRule; +import net.sourceforge.jFuzzyLogic.rule.FuzzyRuleExpression; +import net.sourceforge.jFuzzyLogic.rule.FuzzyRuleSet; +import net.sourceforge.jFuzzyLogic.rule.FuzzyRuleTerm; +import net.sourceforge.jFuzzyLogic.rule.LinguisticTerm; +import net.sourceforge.jFuzzyLogic.rule.Variable; +import net.sourceforge.jFuzzyLogic.ruleConnection.RuleConnectionMethodAndMin; +import net.sourceforge.jFuzzyLogic.ruleImplication.RuleImplicationMethodMin; + +import java.util.Collections; +import java.util.LinkedList; + +public class FuzzyInference { + public void run() { + FuzzyRule fuzzyRule = new FuzzyRule("rule 1"); + + Variable weather = new Variable("Погода"); + weather.getLinguisticTerms().put("солнечно", + new LinguisticTerm("солнечно", new MembershipFunctionTriangular(10, 20, 30))); + weather.getLinguisticTerms().put("мороз", + new LinguisticTerm("мороз", new MembershipFunctionTriangular(-50, 0, 10))); + weather.setDefuzzifier(new DefuzzifierCenterOfArea(weather)); + + + Variable suit = new Variable("Одежда"); + suit.getLinguisticTerms().put("легко одет", + new LinguisticTerm("легко одет", new MembershipFunctionTriangular(0, 5, 10))); + suit.getLinguisticTerms().put("тепло одет", + new LinguisticTerm("тепло одет", new MembershipFunctionTriangular(5, 10, 20))); + suit.setDefuzzifier(new DefuzzifierCenterOfArea(suit)); + + + Variable feel = new Variable("Ощущение"); + feel.getLinguisticTerms().put("Холодно", + new LinguisticTerm("Холодно", new MembershipFunctionTriangular(0, 5, 10))); + feel.getLinguisticTerms().put("Жарко", + new LinguisticTerm("Жарко", new MembershipFunctionTriangular(5, 10, 20))); + feel.setDefuzzifier(new DefuzzifierCenterOfArea(feel)); + + FuzzyRuleTerm weatherTerm1 = new FuzzyRuleTerm(weather, "солнечно", false); + //FuzzyRuleTerm weatherTerm2 = new FuzzyRuleTerm(weather, "мороз", false); + //FuzzyRuleTerm weatherTerm3 = new FuzzyRuleTerm(weather, "дождливо", false); + + //FuzzyRuleTerm suitTerm1 = new FuzzyRuleTerm(suit, "легко одет", false); + FuzzyRuleTerm suitTerm2 = new FuzzyRuleTerm(suit, "тепло одет", false); + //FuzzyRuleTerm suitTerm3 = new FuzzyRuleTerm(suit, "промокающая", false); + + //FuzzyRuleTerm feelCold = new FuzzyRuleTerm(feel, "Холодно", false); + FuzzyRuleTerm feelWarm = new FuzzyRuleTerm(feel, "Жарко", false); + //FuzzyRuleTerm feelBad = new FuzzyRuleTerm(feel, "Сыро", false); + + + FuzzyRuleExpression expression1 = new FuzzyRuleExpression(weatherTerm1, suitTerm2, new RuleConnectionMethodAndMin()); + //FuzzyRuleExpression expression2 = new FuzzyRuleExpression(weatherTerm2, suitTerm1, new RuleConnectionMethodAndMin()); + fuzzyRule.setAntecedents(expression1); + fuzzyRule.setConsequents(new LinkedList<>(Collections.singleton(feelWarm))); + + fuzzyRule.evaluate(new RuleImplicationMethodMin()); + + FuzzyRuleSet set = new FuzzyRuleSet(); + set.add(fuzzyRule); + set.evaluate(); + + System.out.println(fuzzyRule.toString()); + } +} -- 2.34.1 From 374415e154f9e3931f74936f432b83c687022de9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 18 Oct 2022 15:02:33 +0400 Subject: [PATCH 013/110] #74 -- complete fis --- .../rule/service/FuzzyInference.java | 71 +++++++++++++------ 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java index 54f99f4..0bd0ef2 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java @@ -1,6 +1,6 @@ package ru.ulstu.extractor.rule.service; -import net.sourceforge.jFuzzyLogic.defuzzifier.DefuzzifierCenterOfArea; +import net.sourceforge.jFuzzyLogic.defuzzifier.DefuzzifierCenterOfGravity; import net.sourceforge.jFuzzyLogic.membership.MembershipFunctionTriangular; import net.sourceforge.jFuzzyLogic.rule.FuzzyRule; import net.sourceforge.jFuzzyLogic.rule.FuzzyRuleExpression; @@ -12,18 +12,21 @@ import net.sourceforge.jFuzzyLogic.ruleConnection.RuleConnectionMethodAndMin; import net.sourceforge.jFuzzyLogic.ruleImplication.RuleImplicationMethodMin; import java.util.Collections; +import java.util.Comparator; import java.util.LinkedList; public class FuzzyInference { public void run() { - FuzzyRule fuzzyRule = new FuzzyRule("rule 1"); + FuzzyRule fuzzyRule1 = new FuzzyRule("rule 1"); + FuzzyRule fuzzyRule2 = new FuzzyRule("rule 2"); + FuzzyRule fuzzyRule3 = new FuzzyRule("rule 3"); Variable weather = new Variable("Погода"); weather.getLinguisticTerms().put("солнечно", - new LinguisticTerm("солнечно", new MembershipFunctionTriangular(10, 20, 30))); + new LinguisticTerm("солнечно", new MembershipFunctionTriangular(0, 20, 30))); weather.getLinguisticTerms().put("мороз", - new LinguisticTerm("мороз", new MembershipFunctionTriangular(-50, 0, 10))); - weather.setDefuzzifier(new DefuzzifierCenterOfArea(weather)); + new LinguisticTerm("мороз", new MembershipFunctionTriangular(-50, -10, 10))); + weather.setDefuzzifier(new DefuzzifierCenterOfGravity(weather)); Variable suit = new Variable("Одежда"); @@ -31,40 +34,66 @@ public class FuzzyInference { new LinguisticTerm("легко одет", new MembershipFunctionTriangular(0, 5, 10))); suit.getLinguisticTerms().put("тепло одет", new LinguisticTerm("тепло одет", new MembershipFunctionTriangular(5, 10, 20))); - suit.setDefuzzifier(new DefuzzifierCenterOfArea(suit)); - + suit.setDefuzzifier(new DefuzzifierCenterOfGravity(suit)); Variable feel = new Variable("Ощущение"); feel.getLinguisticTerms().put("Холодно", new LinguisticTerm("Холодно", new MembershipFunctionTriangular(0, 5, 10))); feel.getLinguisticTerms().put("Жарко", new LinguisticTerm("Жарко", new MembershipFunctionTriangular(5, 10, 20))); - feel.setDefuzzifier(new DefuzzifierCenterOfArea(feel)); + feel.setDefuzzifier(new DefuzzifierCenterOfGravity(feel)); FuzzyRuleTerm weatherTerm1 = new FuzzyRuleTerm(weather, "солнечно", false); - //FuzzyRuleTerm weatherTerm2 = new FuzzyRuleTerm(weather, "мороз", false); - //FuzzyRuleTerm weatherTerm3 = new FuzzyRuleTerm(weather, "дождливо", false); + FuzzyRuleTerm weatherTerm2 = new FuzzyRuleTerm(weather, "мороз", false); - //FuzzyRuleTerm suitTerm1 = new FuzzyRuleTerm(suit, "легко одет", false); + FuzzyRuleTerm suitTerm1 = new FuzzyRuleTerm(suit, "легко одет", false); FuzzyRuleTerm suitTerm2 = new FuzzyRuleTerm(suit, "тепло одет", false); - //FuzzyRuleTerm suitTerm3 = new FuzzyRuleTerm(suit, "промокающая", false); - //FuzzyRuleTerm feelCold = new FuzzyRuleTerm(feel, "Холодно", false); + FuzzyRuleTerm feelCold = new FuzzyRuleTerm(feel, "Холодно", false); FuzzyRuleTerm feelWarm = new FuzzyRuleTerm(feel, "Жарко", false); - //FuzzyRuleTerm feelBad = new FuzzyRuleTerm(feel, "Сыро", false); - FuzzyRuleExpression expression1 = new FuzzyRuleExpression(weatherTerm1, suitTerm2, new RuleConnectionMethodAndMin()); - //FuzzyRuleExpression expression2 = new FuzzyRuleExpression(weatherTerm2, suitTerm1, new RuleConnectionMethodAndMin()); - fuzzyRule.setAntecedents(expression1); - fuzzyRule.setConsequents(new LinkedList<>(Collections.singleton(feelWarm))); + fuzzyRule1.setAntecedents(expression1); + fuzzyRule1.setConsequents(new LinkedList<>(Collections.singleton(feelWarm))); - fuzzyRule.evaluate(new RuleImplicationMethodMin()); + FuzzyRuleExpression expression2 = new FuzzyRuleExpression(weatherTerm2, suitTerm1, new RuleConnectionMethodAndMin()); + fuzzyRule2.setAntecedents(expression2); + fuzzyRule2.setConsequents(new LinkedList<>(Collections.singleton(feelCold))); + + FuzzyRuleExpression expression3 = new FuzzyRuleExpression(weatherTerm1, suitTerm1, new RuleConnectionMethodAndMin()); + fuzzyRule3.setAntecedents(expression3); + fuzzyRule3.setConsequents(new LinkedList<>(Collections.singleton(feelCold))); + + fuzzyRule1.evaluate(new RuleImplicationMethodMin()); + fuzzyRule2.evaluate(new RuleImplicationMethodMin()); + //fuzzyRule3.evaluate(new RuleImplicationMethodMin()); FuzzyRuleSet set = new FuzzyRuleSet(); - set.add(fuzzyRule); + set.add(fuzzyRule1); + set.add(fuzzyRule2); + set.add(fuzzyRule3); set.evaluate(); - System.out.println(fuzzyRule.toString()); + set.setVariable("Погода", 25); + set.setVariable("Одежда", 7); + // Evaluate fuzzy set + set.evaluate(); + + // Show output variable's chart + //set.getVariable("Ощущение").chartDefuzzifier(true); + System.out.println(set.getVariable("Ощущение").getLatestDefuzzifiedValue()); + System.out.println(set); + System.out.println(set.getVariable("Ощущение")); + System.out.println( + feel.getLinguisticTerms() + .entrySet() + .stream() + .max(Comparator.comparing(e -> e.getValue() + .getMembershipFunction() + .membership(set.getVariable("Ощущение").getLatestDefuzzifiedValue()))) + .get() + .getValue().getTermName() + ); + set.getVariable("Ощущение").chartDefuzzifier(true); } } -- 2.34.1 From 616bb3385e9b70c9ff66adafb48d8b8193bd6866 Mon Sep 17 00:00:00 2001 From: BarminaA Date: Fri, 21 Oct 2022 13:07:34 +0400 Subject: [PATCH 014/110] #76-add rule delete function --- .../java/ru/ulstu/extractor/core/Route.java | 1 + .../rule/controller/RuleController.java | 36 +++++++++++++++---- .../extractor/rule/service/RuleService.java | 4 +++ src/main/resources/templates/listRules.html | 17 ++++++--- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/core/Route.java b/src/main/java/ru/ulstu/extractor/core/Route.java index 9627848..0ea2caa 100644 --- a/src/main/java/ru/ulstu/extractor/core/Route.java +++ b/src/main/java/ru/ulstu/extractor/core/Route.java @@ -18,6 +18,7 @@ public class Route { public static final String STATISTIC = "statistic"; public static final String LIST_RULE = "listRules"; public static final String ADD_RULE = "addRule"; + public static final String DELETE_RULE = "deleteRule"; public static String getLIST_INDEXED_REPOSITORIES() { return LIST_INDEXED_REPOSITORIES; diff --git a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java index 7aeeff1..c222808 100644 --- a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java @@ -2,19 +2,16 @@ package ru.ulstu.extractor.rule.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import ru.ulstu.extractor.rule.model.AddRuleForm; +import ru.ulstu.extractor.rule.repository.RuleRepository; import ru.ulstu.extractor.rule.service.AntecedentValueService; import ru.ulstu.extractor.rule.service.RuleService; import ru.ulstu.extractor.ts.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; -import static ru.ulstu.extractor.core.Route.ADD_RULE; -import static ru.ulstu.extractor.core.Route.LIST_RULE; +import static ru.ulstu.extractor.core.Route.*; @Controller @ApiIgnore @@ -22,13 +19,15 @@ public class RuleController { private final RuleService ruleService; private final AntecedentValueService antecedentValueService; private final TimeSeriesService timeSeriesService; + private final RuleRepository ruleRepository; public RuleController(RuleService ruleService, AntecedentValueService antecedentValueService, - TimeSeriesService timeSeriesService) { + TimeSeriesService timeSeriesService, RuleRepository ruleRepository) { this.ruleService = ruleService; this.antecedentValueService = antecedentValueService; this.timeSeriesService = timeSeriesService; + this.ruleRepository = ruleRepository; } @GetMapping(LIST_RULE) @@ -50,4 +49,27 @@ public class RuleController { ruleService.saveRule(ruleForm); return "redirect:/" + LIST_RULE; } + + @GetMapping(DELETE_RULE) + public String deleteRule(Model model, + @RequestParam Integer id) { + ruleRepository.deleteById(id); + model.addAttribute("rule", ruleRepository.findAll()); + return "redirect:/" + LIST_RULE; + } + +// @RequestMapping(value = FILTER_COMMITS, method = RequestMethod.GET) +// public String editRule(Model model, +// @RequestParam Optional firstAntecedentValueId, +// @RequestParam Optional firstAntecedentId, +// @RequestParam Optional secondAntecedentValueId, +// @RequestParam Optional secondAntecedentId, +// @RequestParam Optional consequent){ +// AddRuleForm addRuleForm = new AddRuleForm(); +// addRuleForm.setFirstAntecedentId(firstAntecedentValueId.); +// addRuleForm.setFirstAntecedentValueId(); +// addRuleForm.setSecondAntecedentId(); +// addRuleForm.setSecondAntecedentValueId(); +// addRuleForm.setConsequent(); +// } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java b/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java index 63413b9..71fd09a 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java @@ -34,4 +34,8 @@ public class RuleService { TimeSeriesType.valueOf(addRuleForm.getSecondAntecedentId()), addRuleForm.getConsequent())); } + + public Rule findById(Integer id) { + return ruleRepository.getOne(id); + } } diff --git a/src/main/resources/templates/listRules.html b/src/main/resources/templates/listRules.html index 1f71b46..d6f3ea1 100644 --- a/src/main/resources/templates/listRules.html +++ b/src/main/resources/templates/listRules.html @@ -10,7 +10,7 @@ - + @@ -23,11 +23,20 @@ + +
ПравилаПравила
то + + + + + + + +
- + Добавить правило
-- 2.34.1 From 301a32d610e79f84cff2fff1d55c22558d51bb0d Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Oct 2022 23:02:27 +0400 Subject: [PATCH 015/110] #74 -- partially add middle logic --- .../extractor/GitExtractorApplication.java | 3 -- ...erence.java => FuzzyInferenceService.java} | 51 ++++++++++++++++++- 2 files changed, 50 insertions(+), 4 deletions(-) rename src/main/java/ru/ulstu/extractor/rule/service/{FuzzyInference.java => FuzzyInferenceService.java} (69%) diff --git a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java index 85d9a30..f9a272d 100644 --- a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java +++ b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java @@ -3,14 +3,11 @@ package ru.ulstu.extractor; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; -import ru.ulstu.extractor.rule.service.FuzzyInference; @SpringBootApplication @EnableScheduling public class GitExtractorApplication { public static void main(String[] args) { - - new FuzzyInference().run(); SpringApplication.run(GitExtractorApplication.class, args); } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java similarity index 69% rename from src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java rename to src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java index 0bd0ef2..862166c 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java @@ -10,12 +10,61 @@ import net.sourceforge.jFuzzyLogic.rule.LinguisticTerm; import net.sourceforge.jFuzzyLogic.rule.Variable; import net.sourceforge.jFuzzyLogic.ruleConnection.RuleConnectionMethodAndMin; import net.sourceforge.jFuzzyLogic.ruleImplication.RuleImplicationMethodMin; +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.rule.model.AntecedentValue; +import ru.ulstu.extractor.rule.model.Rule; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; +import java.util.List; + +@Service +public class FuzzyInferenceService { + private final RuleService ruleService; + private final AntecedentValueService antecedentValueService; + + public FuzzyInferenceService(RuleService ruleService, + AntecedentValueService antecedentValueService) { + this.ruleService = ruleService; + this.antecedentValueService = antecedentValueService; + } + + private List getFuzzyRulesFromDb() { + List fuzzyRules = new ArrayList<>(); + //List variables = getFuzzyVariables(); + for (Rule dbRule : ruleService.getList()) { + FuzzyRule fuzzyRule = new FuzzyRule(String.format("Fuzzy rule %s", dbRule.getId())); + // fuzzyRule.setAntecedents(expression); + // fuzzyRule.setConsequents(new LinkedList<>(Collections.singleton(new FuzzyRuleTerm(dbRule.getConsequent(), false)))); + fuzzyRules.add(fuzzyRule); + } + return fuzzyRules; + } + + private List getFuzzyVariablesWithoutMembership() { + List variables = new ArrayList<>(); + List antecedentValues = antecedentValueService.getList(); + for (AntecedentValue antecedentValue : antecedentValues) { + variables.add(new Variable(antecedentValue.getAntecedentValue())); + } + return variables; + } + +// private FuzzyRuleExpression getFuzzyRulesAntecedents(TimeSeriesType timeSeriesType1, TimeSeriesType timeSeriesType2) { +// return new FuzzyRuleExpression(getFuzzyRuleTerm(), getFuzzyRuleTerm(), new RuleConnectionMethodAndMin()); +// } + + private FuzzyRuleExpression getFuzzyRuleExpression(FuzzyRuleTerm term1, FuzzyRuleTerm term2) { + return new FuzzyRuleExpression(term1, term2, new RuleConnectionMethodAndMin()); + } + + private FuzzyRuleTerm getFuzzyRuleTerm(Variable variable, String term) { + return new FuzzyRuleTerm(variable, term, false); + } + -public class FuzzyInference { public void run() { FuzzyRule fuzzyRule1 = new FuzzyRule("rule 1"); FuzzyRule fuzzyRule2 = new FuzzyRule("rule 2"); -- 2.34.1 From 281d24bde21d22debf06b47572f1569982af0cc8 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Oct 2022 23:20:48 +0400 Subject: [PATCH 016/110] #76 -- fix edit --- .../rule/controller/RuleController.java | 22 ++++++++++++----- .../extractor/rule/model/AddRuleForm.java | 8 +++++++ src/main/resources/templates/addRule.html | 12 +++++----- .../java/ru/ulstu/TimeSeriesMapperTest.java | 24 +++++++++---------- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java index c222808..abd9b8f 100644 --- a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java @@ -2,7 +2,11 @@ package ru.ulstu.extractor.rule.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import ru.ulstu.extractor.rule.model.AddRuleForm; import ru.ulstu.extractor.rule.repository.RuleRepository; @@ -11,7 +15,9 @@ import ru.ulstu.extractor.rule.service.RuleService; import ru.ulstu.extractor.ts.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; -import static ru.ulstu.extractor.core.Route.*; +import static ru.ulstu.extractor.core.Route.ADD_RULE; +import static ru.ulstu.extractor.core.Route.DELETE_RULE; +import static ru.ulstu.extractor.core.Route.LIST_RULE; @Controller @ApiIgnore @@ -37,10 +43,15 @@ public class RuleController { } @GetMapping(ADD_RULE) - public String getAntecedent(Model model) { + public String getAntecedent(Model model, @RequestParam(required = false) Integer ruleId) { model.addAttribute("antecedentValues", antecedentValueService.getList()); model.addAttribute("antecedents", timeSeriesService.getAllTimeSeriesTypes()); - model.addAttribute("addRuleForm", new AddRuleForm()); + model.addAttribute("addRuleForm", + ruleId != null + ? new AddRuleForm(ruleRepository + .findById(ruleId) + .orElseThrow(() -> new RuntimeException("Правило не найдено"))) + : new AddRuleForm()); return ADD_RULE; } @@ -51,8 +62,7 @@ public class RuleController { } @GetMapping(DELETE_RULE) - public String deleteRule(Model model, - @RequestParam Integer id) { + public String deleteRule(Model model, @RequestParam Integer id) { ruleRepository.deleteById(id); model.addAttribute("rule", ruleRepository.findAll()); return "redirect:/" + LIST_RULE; diff --git a/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java b/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java index 3b64bdd..4878b30 100644 --- a/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java +++ b/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java @@ -10,6 +10,14 @@ public class AddRuleForm { public AddRuleForm() { } + public AddRuleForm(Rule rule) { + this.firstAntecedentId = rule.getFirstAntecedent().name(); + this.secondAntecedentId = rule.getSecondAntecedent().name(); + this.firstAntecedentValueId = rule.getFirstAntecedentValue().getId(); + this.secondAntecedentValueId = rule.getSecondAntecedentValue().getId(); + this.consequent = rule.getConsequent(); + } + public Integer getFirstAntecedentValueId() { return firstAntecedentValueId; } diff --git a/src/main/resources/templates/addRule.html b/src/main/resources/templates/addRule.html index 191e07a..fd5b269 100644 --- a/src/main/resources/templates/addRule.html +++ b/src/main/resources/templates/addRule.html @@ -13,7 +13,7 @@ Если
-
diff --git a/src/test/java/ru/ulstu/FuzzyInferenceTest.java b/src/test/java/ru/ulstu/FuzzyInferenceTest.java deleted file mode 100644 index 99d69ef..0000000 --- a/src/test/java/ru/ulstu/FuzzyInferenceTest.java +++ /dev/null @@ -1,15 +0,0 @@ -package ru.ulstu; - -import org.junit.Assert; -import org.junit.Test; -import ru.ulstu.extractor.rule.service.FuzzyInferenceService; - -public class FuzzyInferenceTest { - - private final FuzzyInferenceService fuzzyInferenceService = new FuzzyInferenceService(); - - @Test - public void test() { - Assert.assertNotNull(fuzzyInferenceService); - } -} -- 2.34.1 From f9fd839a14f13fbc20e97593277ac624f4f6ceaf Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 7 Feb 2023 22:30:47 +0400 Subject: [PATCH 049/110] #81 -- Add branch indexing status --- .../ru/ulstu/extractor/branch/model/Branch.java | 15 +++++++++++++++ .../extractor/branch/model/IndexingStatus.java | 5 +++++ .../db/changelog-20221012_170000-schema.xml | 8 ++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/main/java/ru/ulstu/extractor/branch/model/IndexingStatus.java diff --git a/src/main/java/ru/ulstu/extractor/branch/model/Branch.java b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java index 046b8c4..97c03df 100644 --- a/src/main/java/ru/ulstu/extractor/branch/model/Branch.java +++ b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java @@ -13,6 +13,8 @@ import ru.ulstu.extractor.gitrepository.model.GitRepository; 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.ManyToOne; @@ -20,6 +22,8 @@ import javax.persistence.OneToMany; import java.util.ArrayList; import java.util.List; +import static ru.ulstu.extractor.branch.model.IndexingStatus.EMPTY; + @Entity public class Branch extends BaseEntity { private String name; @@ -32,6 +36,9 @@ public class Branch extends BaseEntity { @Fetch(FetchMode.SUBSELECT) private List commits = new ArrayList<>(); + @Enumerated(EnumType.STRING) + private IndexingStatus indexingStatus = EMPTY; + public Branch() { } @@ -67,4 +74,12 @@ public class Branch extends BaseEntity { public void setCommits(List commits) { this.commits = commits; } + + public IndexingStatus getIndexingStatus() { + return indexingStatus; + } + + public void setIndexingStatus(IndexingStatus indexingStatus) { + this.indexingStatus = indexingStatus; + } } diff --git a/src/main/java/ru/ulstu/extractor/branch/model/IndexingStatus.java b/src/main/java/ru/ulstu/extractor/branch/model/IndexingStatus.java new file mode 100644 index 0000000..3683817 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/branch/model/IndexingStatus.java @@ -0,0 +1,5 @@ +package ru.ulstu.extractor.branch.model; + +public enum IndexingStatus { + EMPTY, INDEXING, FINISHED +} diff --git a/src/main/resources/db/changelog-20221012_170000-schema.xml b/src/main/resources/db/changelog-20221012_170000-schema.xml index 3e4dc33..6ee4e83 100644 --- a/src/main/resources/db/changelog-20221012_170000-schema.xml +++ b/src/main/resources/db/changelog-20221012_170000-schema.xml @@ -99,4 +99,12 @@ OR branch_id is null; + + + + + + + + \ No newline at end of file -- 2.34.1 From 98ec8217484f4bf9edc2d5cbf75555c7cbf2df9c Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 7 Feb 2023 22:44:04 +0400 Subject: [PATCH 050/110] #81 -- Show indexing status --- src/main/resources/templates/listBranches.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/listBranches.html b/src/main/resources/templates/listBranches.html index b8e32f8..2ecdaae 100644 --- a/src/main/resources/templates/listBranches.html +++ b/src/main/resources/templates/listBranches.html @@ -12,20 +12,24 @@ Ветки - + + th:text="${branch.name}"> + Индексируется... + -- 2.34.1 From 11b42d7e09d7c9c318155aa6495ec704628ec761 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 7 Feb 2023 23:29:13 +0400 Subject: [PATCH 051/110] #81 -- Start indexing on failed tasks --- .../extractor/GitExtractorApplication.java | 17 +++++++++++ .../branch/repository/BranchRepository.java | 3 ++ .../branch/service/BranchService.java | 16 +++++++++++ .../gitrepository/service/IndexService.java | 28 +++++++++++++++++++ .../resources/templates/listBranches.html | 2 +- 5 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java index f9a272d..1cf7928 100644 --- a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java +++ b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java @@ -2,12 +2,29 @@ package ru.ulstu.extractor; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; +import ru.ulstu.extractor.gitrepository.service.IndexService; @SpringBootApplication @EnableScheduling +@EnableAsync public class GitExtractorApplication { + private final IndexService indexService; + + public GitExtractorApplication(IndexService indexService) { + this.indexService = indexService; + } + public static void main(String[] args) { SpringApplication.run(GitExtractorApplication.class, args); } + + @EventListener(ApplicationReadyEvent.class) + public void doSomethingAfterStartup() { + indexService.indexFailedBranchesOnStart(); + } + } diff --git a/src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java b/src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java index af14f53..5a8b1f6 100644 --- a/src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java +++ b/src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java @@ -5,6 +5,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.branch.model.IndexingStatus; import ru.ulstu.extractor.gitrepository.model.GitRepository; import java.util.List; @@ -18,4 +19,6 @@ public interface BranchRepository extends JpaRepository { List findByGitRepositoryId(Integer repositoryId); Page findByGitRepository(GitRepository gitRepository, Pageable pageable); + + List findAllByIndexingStatus(IndexingStatus indexingStatus); } diff --git a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java index ce37a85..0a11945 100644 --- a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java +++ b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java @@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.branch.model.IndexingStatus; import ru.ulstu.extractor.branch.repository.BranchRepository; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.commit.service.CommitService; @@ -32,6 +33,11 @@ public class BranchService { this.commitService = commitService; } + @Transactional + public Branch save(Branch branch) { + return branchRepository.save(branch); + } + @Transactional public Branch save(Branch branch, List commits) { LOG.debug("Start save {} branch with {} commits ", branch.getName(), commits.size()); @@ -63,4 +69,14 @@ public class BranchService { public List findAll() { return branchRepository.findAll(); } + + public List findAllByIndexingStatus(IndexingStatus indexingStatus) { + return branchRepository.findAllByIndexingStatus(indexingStatus); + } + + @Transactional + public Branch updateStatus(Branch branch, IndexingStatus indexingStatus) { + branch.setIndexingStatus(indexingStatus); + return branchRepository.save(branch); + } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index b510338..a442286 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -9,8 +9,11 @@ import com.sun.istack.NotNull; import org.eclipse.jgit.api.errors.GitAPIException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.branch.model.IndexingStatus; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.gitrepository.model.GitRepository; @@ -55,6 +58,7 @@ public class IndexService { branch = new Branch(gitRepository, branchName); } branchService.save(branch, Collections.emptyList()); + branch = branchService.updateStatus(branch, IndexingStatus.INDEXING); int commitsFrom = 0; int commitsTo = COMMITS_PAGE_SIZE; List commits = gitRepositoryService.getCommits(repositoryUrl, branchName, commitsFrom, commitsTo, true); @@ -69,6 +73,30 @@ public class IndexService { Integer repositoryId = gitRepository.getId(); final Branch branchForSave = branch; timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(repositoryId, branchForSave)); + branchService.updateStatus(branch, IndexingStatus.FINISHED); LOG.debug("Complete indexing {} branch", branchName); } + + @Transactional + @Async + public void indexFailedBranchesOnStart() { + LOG.info("Старт проверки незавершенных задач для индексирований..."); + + List failedBranches = branchService.findAllByIndexingStatus(IndexingStatus.INDEXING); + if (failedBranches.size() > 0) { + LOG.info("Найдено {} незавершенных задач для индексирования", failedBranches.size()); + failedBranches.forEach(failedBranch -> { + try { + index(failedBranch.getId()); + LOG.info("Завершено индексирование ветки {}", failedBranch.getName()); + branchService.updateStatus(failedBranch, IndexingStatus.FINISHED); + } catch (Exception ex) { + LOG.warn(ex.getMessage()); + } + }); + LOG.info("Завершено индексирование незавершенных задач"); + } else { + LOG.info("Не найдено незавершенных веток для индексирования"); + } + } } diff --git a/src/main/resources/templates/listBranches.html b/src/main/resources/templates/listBranches.html index 2ecdaae..a9cb074 100644 --- a/src/main/resources/templates/listBranches.html +++ b/src/main/resources/templates/listBranches.html @@ -30,7 +30,7 @@ Индексируется... - -- 2.34.1 From 425ff706834923b7a4ab8e430cdef85136b12cdf Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 13 Feb 2023 12:03:13 +0400 Subject: [PATCH 052/110] #81 -- Add new time series type --- .../extractor/ts/creator/AuthorsCommitTS.java | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) 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 2c6927d..86ec31d 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java @@ -1,30 +1,39 @@ package ru.ulstu.extractor.ts.creator; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.author.model.Author; +import ru.ulstu.extractor.author.service.AuthorService; import ru.ulstu.extractor.branch.service.BranchService; +import ru.ulstu.extractor.commit.model.Commit; +import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import ru.ulstu.extractor.ts.util.Dummy; -import java.util.Collections; +import java.util.ArrayList; import java.util.List; @Component public class AuthorsCommitTS extends AbstractTimeSeriesCreator { private final TimeSeriesService timeSeriesService; + private final CommitService commitService; + private final AuthorService authorService; + private final GitRepositoryService gitRepositoryService; private final BranchService branchService; - private final GitRepositoryService gitRepositoryService; - public AuthorsCommitTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { + CommitService commitService, + AuthorService authorService, + GitRepositoryService gitRepositoryService, + BranchService branchService) { this.timeSeriesService = timeSeriesService; - this.branchService = branchService; + this.commitService = commitService; + this.authorService = authorService; this.gitRepositoryService = gitRepositoryService; + this.branchService = branchService; } @Override @@ -34,17 +43,29 @@ public class AuthorsCommitTS extends AbstractTimeSeriesCreator { @Override public List getTimeSeries(Integer repositoryId, String branchName) { + List timeSeriesResult = new ArrayList<>(); + List authors = authorService.findAll(); GitRepository gitRepository = gitRepositoryService.findById(repositoryId); - //TODO: добавить постраничное чтение - return Collections.singletonList( - new TimeSeries( - String.format("%s %s %s", - gitRepository.getName(), - branchName, - getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), - getTimeSeriesType(), - Dummy.getDefaultTimeSeries())); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName)); + for (Author author : authors) { + TimeSeries timeSeries = new TimeSeries( + String.format("%s %s %s %s", + gitRepository.getName(), + branchName, + author.getName(), + getTimeSeriesType().getDescription()), + branchService.findByRepositoryAndName(gitRepository, branchName), + getTimeSeriesType()); + for (Commit commit : commits) { + if (commit.getAuthor().equals(author)) { + timeSeries.getValues().add(new TimeSeriesValue(commit.getDate(), 1.0)); + } + } + if (!timeSeries.getValues().isEmpty()) { + timeSeriesResult.add(timeSeries); + } + } + return timeSeriesResult; } @Override -- 2.34.1 From 616eaaa23a5552594223dbaf86542e2bd620745b Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 13 Feb 2023 17:54:49 +0400 Subject: [PATCH 053/110] #81 -- Add async tasks --- .../branch/model/IndexingStatus.java | 2 +- .../branch/repository/BranchRepository.java | 3 ++ .../branch/service/BranchService.java | 7 ++++ .../controler/GitIndexingController.java | 23 +++++++----- .../service/GitRepositoryService.java | 27 +++++++++----- .../gitrepository/service/IndexService.java | 37 +++++++++++-------- 6 files changed, 64 insertions(+), 35 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/branch/model/IndexingStatus.java b/src/main/java/ru/ulstu/extractor/branch/model/IndexingStatus.java index 3683817..67f2cec 100644 --- a/src/main/java/ru/ulstu/extractor/branch/model/IndexingStatus.java +++ b/src/main/java/ru/ulstu/extractor/branch/model/IndexingStatus.java @@ -1,5 +1,5 @@ package ru.ulstu.extractor.branch.model; public enum IndexingStatus { - EMPTY, INDEXING, FINISHED + EMPTY, INDEXING, ERROR, FINISHED } diff --git a/src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java b/src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java index 5a8b1f6..8ac8523 100644 --- a/src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java +++ b/src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java @@ -9,10 +9,13 @@ import ru.ulstu.extractor.branch.model.IndexingStatus; import ru.ulstu.extractor.gitrepository.model.GitRepository; import java.util.List; +import java.util.Optional; public interface BranchRepository extends JpaRepository { Branch findByGitRepositoryAndName(GitRepository gitRepository, String name); + Optional findByGitRepository_UrlAndName(String repositoryUrl, String name); + @Query("select count(c) from Commit c LEFT JOIN c.branch b LEFT JOIN GitRepository r where r.id = ?1 AND b.name = ?2") int getCommitsCount(Integer repositoryId, String name); diff --git a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java index 0a11945..cb8537e 100644 --- a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java +++ b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java @@ -62,6 +62,13 @@ public class BranchService { return branchRepository.findByGitRepositoryAndName(gitRepository, branchName); } + public Branch findByRepositoryAndNameOrCreate(GitRepository gitRepository, String branchName) { + Branch branch = branchRepository.findByGitRepositoryAndName(gitRepository, branchName); + return branch == null + ? branchRepository.save(new Branch(gitRepository, branchName)) + : branch; + } + public Optional findByBranchId(Integer branchId) { return branchRepository.findById(branchId); } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitIndexingController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitIndexingController.java index 3343754..bcd7917 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitIndexingController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitIndexingController.java @@ -17,8 +17,10 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.branch.model.IndexingStatus; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.gitrepository.model.FilterForm; +import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.gitrepository.model.RepoForm; import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.gitrepository.service.IndexService; @@ -27,8 +29,8 @@ import springfox.documentation.annotations.ApiIgnore; import java.io.IOException; import java.util.List; -import static ru.ulstu.extractor.core.Route.FILTER_COMMITS; import static ru.ulstu.extractor.core.Route.INDEXING_NEW_REPOSITORY; +import static ru.ulstu.extractor.core.Route.LIST_REPOSITORY_BRANCHES; import static ru.ulstu.extractor.core.Route.REINDEX_BRANCH; @Controller @@ -70,16 +72,18 @@ public class GitIndexingController { if (repoForm.getBranch() == null) { return INDEXING_NEW_REPOSITORY; } else { + GitRepository gitRepository = gitRepositoryService.findByUrlOrCreate(repoForm.getRepo()); + Branch branch = branchService.findByRepositoryAndNameOrCreate(gitRepository, repoForm.getBranch()); + branch = branchService.updateStatus(branch, IndexingStatus.INDEXING); try { - indexService.index(repoForm.getRepo(), repoForm.getBranch()); + indexService.index(gitRepository, branch); } catch (IOException | GitAPIException ex) { ex.printStackTrace(); model.addAttribute("error", ex.getMessage()); return INDEXING_NEW_REPOSITORY; } - redirectAttributes.addAttribute("repositoryUrl", repoForm.getRepo()); - redirectAttributes.addAttribute("branchName", repoForm.getBranch()); - return "redirect:/" + FILTER_COMMITS; + redirectAttributes.addAttribute("repositoryId", branch.getGitRepository().getId()); + return "redirect:/" + LIST_REPOSITORY_BRANCHES; } } @@ -87,6 +91,9 @@ public class GitIndexingController { public String reindexBranch(Model model, RedirectAttributes redirectAttributes, @RequestParam Integer branchId) { + + Branch branch = branchService.findByBranchId(branchId).orElseThrow(() -> new RuntimeException("Ветка не найдена по id")); + branch = branchService.updateStatus(branch, IndexingStatus.INDEXING); try { indexService.index(branchId); } catch (IOException | GitAPIException ex) { @@ -94,9 +101,7 @@ public class GitIndexingController { model.addAttribute("error", ex.getMessage()); return INDEXING_NEW_REPOSITORY; } - Branch branch = branchService.findByBranchId(branchId).orElseThrow(() -> new RuntimeException("Ветка не найдена по id")); - redirectAttributes.addAttribute("repositoryUrl", branch.getGitRepository().getUrl()); - redirectAttributes.addAttribute("branchName", branch.getName()); - return "redirect:/" + FILTER_COMMITS; + redirectAttributes.addAttribute("repositoryId", branch.getGitRepository().getId()); + return "redirect:/" + LIST_REPOSITORY_BRANCHES; } } 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 2d451e1..f6ead24 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java @@ -187,7 +187,6 @@ public class GitRepositoryService { return structuralUnitService.getResource(getProjectDirectoryFile(repositoryUrl)); } - public void remove(String repositoryUrl) throws IOException { FileUtils.deleteDirectory(getProjectDirectoryFile(repositoryUrl)); } @@ -283,7 +282,7 @@ public class GitRepositoryService { List changes = new ArrayList<>(); String[] strings = output.split("\n"); Map> filesContent = getFilesContent(strings); - for(Map.Entry> fileSterings: filesContent.entrySet()) { + 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()))); @@ -327,7 +326,7 @@ public class GitRepositoryService { private Map> getFilesContent(String[] commitStrings) { int i = 0; - Map> result = new HashMap<>(); + Map> result = new HashMap<>(); while (i < commitStrings.length) { Optional maybeFileName = getFileName(commitStrings[i]); if (maybeFileName.isEmpty()) { @@ -368,15 +367,15 @@ public class GitRepositoryService { return index; } - private FileChange getChange(FileChange fileChange, List fileContent){ + 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){ + for (String line : fileContent) { LineChange lineChange = new LineChange(); - if (line.startsWith("-")){ + if (line.startsWith("-")) { isRemoved = true; if (isAdded) { isAdded = false; @@ -385,7 +384,7 @@ public class GitRepositoryService { } builder.append(line).append("\n"); removedLine++; - } else if(line.startsWith("+")){ + } else if (line.startsWith("+")) { isAdded = true; if (isRemoved) { isRemoved = false; @@ -398,7 +397,7 @@ public class GitRepositoryService { if (isRemoved) { lineChange = setRemoved(lineChange, builder); builder.setLength(0); - } else if (isAdded){ + } else if (isAdded) { lineChange = setAdded(lineChange, builder); builder.setLength(0); } @@ -409,17 +408,18 @@ public class GitRepositoryService { return fileChange; } - private LineChange setRemoved(LineChange lineChange, StringBuilder builder){ + private LineChange setRemoved(LineChange lineChange, StringBuilder builder) { lineChange.setLineFrom(builder.toString()); lineChange.setRemoved(true); return lineChange; } - private LineChange setAdded(LineChange lineChange, StringBuilder builder){ + 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); } @@ -427,4 +427,11 @@ public class GitRepositoryService { public GitRepository findById(Integer id) { return gitRepositoryRepository.getOne(id); } + + public GitRepository findByUrlOrCreate(String gitRepositoryUrl) { + GitRepository gitRepository = gitRepositoryRepository.findByUrl(gitRepositoryUrl); + return gitRepository == null + ? gitRepositoryRepository.save(new GitRepository(gitRepositoryUrl)) + : gitRepository; + } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index a442286..7c3b4bb 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -23,6 +23,8 @@ import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import java.io.IOException; import java.util.Collections; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; @Service public class IndexService { @@ -32,6 +34,7 @@ public class IndexService { private final GitRepositoryRepository gitRepositoryRepository; private final BranchService branchService; private final List timeSeriesCreators; + private final static ExecutorService EXECUTOR = Executors.newFixedThreadPool(10); public IndexService(GitRepositoryService gitRepositoryService, GitRepositoryRepository gitRepositoryRepository, @@ -43,38 +46,43 @@ public class IndexService { this.timeSeriesCreators = timeSeriesCreators; } + @Transactional + @Async public void index(@NotNull Integer branchId) throws GitAPIException, IOException { Branch branch = branchService.findByBranchId(branchId).orElseThrow(() -> new RuntimeException("Ветка репозитория не найдена по id")); - index(branch.getGitRepository().getUrl(), branch.getName()); + index(branch.getGitRepository(), branch); } - public void index(@NotNull String repositoryUrl, @NotNull String branchName) throws GitAPIException, IOException { - GitRepository gitRepository = gitRepositoryRepository.findByUrl(repositoryUrl); - if (gitRepository == null) { - gitRepository = gitRepositoryRepository.save(new GitRepository(repositoryUrl)); - } - Branch branch = branchService.findByRepositoryAndName(gitRepository, branchName); - if (branch == null) { - branch = new Branch(gitRepository, branchName); - } + @Transactional + @Async + public void index(String gitRepositoryUrl, String branchName) throws GitAPIException, IOException { + GitRepository gitRepository = gitRepositoryService.findByUrlOrCreate(gitRepositoryUrl); + Branch branch = branchService.findByRepositoryAndNameOrCreate(gitRepository, branchName); + branch = branchService.updateStatus(branch, IndexingStatus.INDEXING); + index(gitRepository, branch); + } + + @Transactional + @Async + public void index(GitRepository gitRepository, Branch branch) throws GitAPIException, IOException { branchService.save(branch, Collections.emptyList()); branch = branchService.updateStatus(branch, IndexingStatus.INDEXING); int commitsFrom = 0; int commitsTo = COMMITS_PAGE_SIZE; - List commits = gitRepositoryService.getCommits(repositoryUrl, branchName, commitsFrom, commitsTo, true); + List commits = gitRepositoryService.getCommits(gitRepository.getUrl(), branch.getName(), commitsFrom, commitsTo, true); while (!commits.isEmpty()) { LOG.debug("{} commits loaded.", commits.size()); branchService.addCommits(branch, commits); - LOG.debug("{} commits successfully saved. {} {}", commits.size(), repositoryUrl, branchName); + LOG.debug("{} commits successfully saved. {} {}", commits.size(), gitRepository.getUrl(), branch.getName()); commitsFrom += COMMITS_PAGE_SIZE; commitsTo += COMMITS_PAGE_SIZE; - commits = gitRepositoryService.getCommits(repositoryUrl, branchName, commitsFrom, commitsTo, false); + commits = gitRepositoryService.getCommits(gitRepository.getUrl(), branch.getName(), commitsFrom, commitsTo, false); } Integer repositoryId = gitRepository.getId(); final Branch branchForSave = branch; timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(repositoryId, branchForSave)); branchService.updateStatus(branch, IndexingStatus.FINISHED); - LOG.debug("Complete indexing {} branch", branchName); + LOG.debug("Complete indexing {} branch", branch.getName()); } @Transactional @@ -89,7 +97,6 @@ public class IndexService { try { index(failedBranch.getId()); LOG.info("Завершено индексирование ветки {}", failedBranch.getName()); - branchService.updateStatus(failedBranch, IndexingStatus.FINISHED); } catch (Exception ex) { LOG.warn(ex.getMessage()); } -- 2.34.1 From 0d43bf8ccd71cb79d5ad824217c3d84c62fbdbe0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 15 Feb 2023 00:55:06 +0400 Subject: [PATCH 054/110] #89 -- Use git service api to create time series --- .../gitrepository/service/GitApi.java | 13 +++++ .../gitrepository/service/GitAtheneApi.java | 45 ++++++++++++++++ .../gitrepository/service/IndexService.java | 9 ++-- .../ru/ulstu/extractor/http/HttpService.java | 23 ++++++++ .../ts/creator/AbstractTimeSeriesCreator.java | 39 -------------- .../ulstu/extractor/ts/creator/BranchTS.java | 53 ------------------- .../ulstu/extractor/ts/creator/IssuesTS.java | 53 ------------------- .../ru/ulstu/extractor/ts/creator/StarTS.java | 53 ------------------- .../ts/creator/{ => db}/AuthorsCommitTS.java | 13 ++--- .../ts/creator/{ => db}/CommitsTS.java | 13 ++--- .../ts/creator/db/DBTimeSeriesCreator.java | 45 ++++++++++++++++ .../extractor/ts/creator/{ => db}/FileTS.java | 13 ++--- .../ts/creator/{ => scheduled}/AuthorTS.java | 12 ++--- .../AuthorsCompletedIssueTS.java | 7 ++- .../{ => scheduled}/AuthorsIssueTS.java | 4 +- .../ts/creator/scheduled/BranchTS.java | 35 ++++++++++++ .../ts/creator/{ => scheduled}/ClassTS.java | 3 +- .../creator/{ => scheduled}/DependenceTS.java | 3 +- .../ts/creator/{ => scheduled}/EntityTS.java | 3 +- .../creator/{ => scheduled}/InterfaceTS.java | 3 +- .../ts/creator/scheduled/IssuesTS.java | 35 ++++++++++++ .../ts/creator/{ => scheduled}/ProcessTS.java | 4 +- .../scheduled/ScheduledTimeSeriesCreator.java | 20 +++++++ .../ts/creator/scheduled/StarTS.java | 34 ++++++++++++ .../ulstu/extractor/ts/model/TimeSeries.java | 7 +++ .../extractor/ts/model/TimeSeriesValue.java | 5 ++ .../ts/repository/TimeSeriesRepository.java | 4 ++ .../service/ScheduledTimeSeriesService.java | 34 ++++++++++++ .../ts/service/TimeSeriesService.java | 11 +++- 29 files changed, 346 insertions(+), 250 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java create mode 100644 src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java rename src/main/java/ru/ulstu/extractor/ts/creator/{ => db}/AuthorsCommitTS.java (81%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => db}/CommitsTS.java (78%) create mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java rename src/main/java/ru/ulstu/extractor/ts/creator/{ => db}/FileTS.java (81%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/AuthorTS.java (85%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/AuthorsCompletedIssueTS.java (86%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/AuthorsIssueTS.java (94%) create mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/ClassTS.java (94%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/DependenceTS.java (94%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/EntityTS.java (96%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/InterfaceTS.java (94%) create mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/ProcessTS.java (94%) create mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java create mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java create mode 100644 src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java new file mode 100644 index 0000000..3aa4e59 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java @@ -0,0 +1,13 @@ +package ru.ulstu.extractor.gitrepository.service; + +import ru.ulstu.extractor.branch.model.Branch; + +public interface GitApi { + Integer getBranchesCount(Branch branch); + + Integer getStarsCount(Branch branch); + + Integer getOpenIssuesCount(Branch branch); + + String getFormattedUrl(String gitRepositoryUrl, String template); +} diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java new file mode 100644 index 0000000..a8853dc --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java @@ -0,0 +1,45 @@ +package ru.ulstu.extractor.gitrepository.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.http.HttpService; + +@Service +public class GitAtheneApi implements GitApi { + private final HttpService httpService; + private static final String BRANCHES_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; + private static final String STARS_COUNT_URL = "%s/api/v1/repos/%s/%s"; + private static final String OPEN_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; + + public GitAtheneApi(HttpService httpService) { + this.httpService = httpService; + } + + @Override + public Integer getBranchesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .length(); + } + + @Override + public Integer getStarsCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .getJSONObject(0) + .getInt("stars_count"); + } + + @Override + public Integer getOpenIssuesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .length(); + } + + @Override + public String getFormattedUrl(String gitRepositoryUrl, String template) { + String[] urlParts = gitRepositoryUrl.split("/"); + return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]); + } +} diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index 7c3b4bb..088aa22 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -18,7 +18,7 @@ import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.gitrepository.repository.GitRepositoryRepository; -import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; +import ru.ulstu.extractor.ts.creator.db.DBTimeSeriesCreator; import java.io.IOException; import java.util.Collections; @@ -33,13 +33,13 @@ public class IndexService { private final GitRepositoryService gitRepositoryService; private final GitRepositoryRepository gitRepositoryRepository; private final BranchService branchService; - private final List timeSeriesCreators; + private final List timeSeriesCreators; private final static ExecutorService EXECUTOR = Executors.newFixedThreadPool(10); public IndexService(GitRepositoryService gitRepositoryService, GitRepositoryRepository gitRepositoryRepository, BranchService branchService, - List timeSeriesCreators) { + List timeSeriesCreators) { this.gitRepositoryService = gitRepositoryService; this.gitRepositoryRepository = gitRepositoryRepository; this.branchService = branchService; @@ -78,9 +78,8 @@ public class IndexService { commitsTo += COMMITS_PAGE_SIZE; commits = gitRepositoryService.getCommits(gitRepository.getUrl(), branch.getName(), commitsFrom, commitsTo, false); } - Integer repositoryId = gitRepository.getId(); final Branch branchForSave = branch; - timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(repositoryId, branchForSave)); + timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(gitRepository, branchForSave)); branchService.updateStatus(branch, IndexingStatus.FINISHED); LOG.debug("Complete indexing {} branch", branch.getName()); } diff --git a/src/main/java/ru/ulstu/extractor/http/HttpService.java b/src/main/java/ru/ulstu/extractor/http/HttpService.java index 6d79315..cc1884e 100644 --- a/src/main/java/ru/ulstu/extractor/http/HttpService.java +++ b/src/main/java/ru/ulstu/extractor/http/HttpService.java @@ -1,5 +1,6 @@ package ru.ulstu.extractor.http; +import org.json.JSONArray; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,4 +39,26 @@ public class HttpService { log.debug("Service response: {}", response); return response; } + + public JSONArray get(String url) { + log.debug("Service call: {}", url); + try { + String response = client + .get() + .uri(url) + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(String.class) + .toFuture().get(); + if (response.startsWith("[")) { + return new JSONArray(response); + } else { + JSONArray jsonArray = new JSONArray(); + jsonArray.put(0, new JSONObject(response)); + return jsonArray; + } + } catch (Exception e) { + return new JSONArray("[{response:\"empty\"}]"); + } + } } 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 cad3156..c6a2f2b 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java @@ -1,49 +1,10 @@ package ru.ulstu.extractor.ts.creator; -import ru.ulstu.extractor.branch.model.Branch; -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 static ru.ulstu.extractor.ts.util.TimeSeriesDateMapper.mapTimeSeriesToInterval; - public abstract class AbstractTimeSeriesCreator { public abstract TimeSeriesType getTimeSeriesType(); - /** - * Извлечь список точек временных рядов - * - * @param repositoryId - * @param branchName - * @return - */ - public abstract List getTimeSeries(Integer repositoryId, String branchName); - public abstract TimeSeriesService getTimeSeriesService(); - - /** - * Сохранить извлеченные временные ряды - * - * @param repositoryId - * @param branch - */ - public void addTimeSeries(Integer repositoryId, Branch branch) { - // извлеченные временных рядов - List timeSeries = getTimeSeries(repositoryId, branch.getName()); - - // сгруппированные по временным интервалам точки временных рядов - timeSeries.forEach(ts -> ts.setValues(mapTimeSeriesToInterval(getTimeSeriesService().getTimeSeriesInterval(), ts.getValues()))); - getTimeSeriesService().save(sortTimeSeries(timeSeries), branch); - } - - private List sortTimeSeries(List timeSeries) { - for (TimeSeries ts : timeSeries) { - ts.getValues().sort(Comparator.comparing(TimeSeriesValue::getDate)); - } - return timeSeries; - } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java deleted file mode 100644 index a6d99f0..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.ulstu.extractor.ts.creator; - -import org.springframework.stereotype.Component; -import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.model.TimeSeries; -import ru.ulstu.extractor.ts.model.TimeSeriesType; -import ru.ulstu.extractor.ts.service.TimeSeriesService; -import ru.ulstu.extractor.ts.util.Dummy; - -import java.util.Collections; -import java.util.List; - -@Component -public class BranchTS extends AbstractTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final BranchService branchService; - - private final GitRepositoryService gitRepositoryService; - - public BranchTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { - this.timeSeriesService = timeSeriesService; - this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; - } - - @Override - public TimeSeriesType getTimeSeriesType() { - return TimeSeriesType.BRANCHES; - } - - @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); - return Collections.singletonList( - new TimeSeries( - String.format("%s %s %s", - gitRepository.getName(), - branchName, - getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), - getTimeSeriesType(), - Dummy.getDefaultTimeSeries())); - } - - @Override - public TimeSeriesService getTimeSeriesService() { - return timeSeriesService; - } -} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java deleted file mode 100644 index af43b83..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.ulstu.extractor.ts.creator; - -import org.springframework.stereotype.Component; -import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.model.TimeSeries; -import ru.ulstu.extractor.ts.model.TimeSeriesType; -import ru.ulstu.extractor.ts.service.TimeSeriesService; -import ru.ulstu.extractor.ts.util.Dummy; - -import java.util.Collections; -import java.util.List; - -@Component -public class IssuesTS extends AbstractTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final BranchService branchService; - - private final GitRepositoryService gitRepositoryService; - - public IssuesTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { - this.timeSeriesService = timeSeriesService; - this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; - } - - @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); - return Collections.singletonList( - new TimeSeries( - String.format("%s %s %s", - gitRepository.getName(), - branchName, - getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), - getTimeSeriesType(), - Dummy.getDefaultTimeSeries())); - } - - @Override - public TimeSeriesService getTimeSeriesService() { - return timeSeriesService; - } - - @Override - public TimeSeriesType getTimeSeriesType() { - return TimeSeriesType.ISSUES; - } -} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java deleted file mode 100644 index 0bbcf93..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.ulstu.extractor.ts.creator; - -import org.springframework.stereotype.Component; -import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.model.TimeSeries; -import ru.ulstu.extractor.ts.model.TimeSeriesType; -import ru.ulstu.extractor.ts.service.TimeSeriesService; -import ru.ulstu.extractor.ts.util.Dummy; - -import java.util.Collections; -import java.util.List; - -@Component -public class StarTS extends AbstractTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final BranchService branchService; - - private final GitRepositoryService gitRepositoryService; - - public StarTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { - this.timeSeriesService = timeSeriesService; - this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; - } - - @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); - return Collections.singletonList( - new TimeSeries( - String.format("%s %s %s", - gitRepository.getName(), - branchName, - getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), - getTimeSeriesType(), - Dummy.getDefaultTimeSeries())); - } - - @Override - public TimeSeriesService getTimeSeriesService() { - return timeSeriesService; - } - - @Override - public TimeSeriesType getTimeSeriesType() { - return TimeSeriesType.STARS; - } -} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java similarity index 81% rename from src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java index 86ec31d..dc95528 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; import ru.ulstu.extractor.author.model.Author; @@ -7,7 +7,6 @@ import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -17,22 +16,19 @@ import java.util.ArrayList; import java.util.List; @Component -public class AuthorsCommitTS extends AbstractTimeSeriesCreator { +public class AuthorsCommitTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final CommitService commitService; private final AuthorService authorService; - private final GitRepositoryService gitRepositoryService; private final BranchService branchService; public AuthorsCommitTS(TimeSeriesService timeSeriesService, CommitService commitService, AuthorService authorService, - GitRepositoryService gitRepositoryService, BranchService branchService) { this.timeSeriesService = timeSeriesService; this.commitService = commitService; this.authorService = authorService; - this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; } @@ -42,11 +38,10 @@ public class AuthorsCommitTS extends AbstractTimeSeriesCreator { } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { + public List getTimeSeries(GitRepository gitRepository, String branchName) { List timeSeriesResult = new ArrayList<>(); List authors = authorService.findAll(); - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName)); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); for (Author author : authors) { TimeSeries timeSeries = new TimeSeries( String.format("%s %s %s %s", diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java similarity index 78% rename from src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java index 0b7ed9d..523ff76 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java @@ -1,10 +1,9 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -15,25 +14,21 @@ import java.util.List; import java.util.stream.Collectors; @Component -public class CommitsTS extends AbstractTimeSeriesCreator { +public class CommitsTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final CommitService commitService; - private final GitRepositoryService gitRepositoryService; private final BranchService branchService; public CommitsTS(TimeSeriesService timeSeriesService, CommitService commitService, - GitRepositoryService gitRepositoryService, BranchService branchService) { this.timeSeriesService = timeSeriesService; this.commitService = commitService; - this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(GitRepository gitRepository, String branchName) { //TODO: добавить постраничное чтение return Collections.singletonList( new TimeSeries( @@ -43,7 +38,7 @@ public class CommitsTS extends AbstractTimeSeriesCreator { getTimeSeriesType().getDescription()), branchService.findByRepositoryAndName(gitRepository, branchName), getTimeSeriesType(), - commitService.findByRepositoryIdAndName(repositoryId, branchName) + commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName) .stream() .map(c -> new TimeSeriesValue(c.getDate(), 1.0)) .collect(Collectors.toList()))); diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java new file mode 100644 index 0000000..7de98b7 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java @@ -0,0 +1,45 @@ +package ru.ulstu.extractor.ts.creator.db; + +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.model.GitRepository; +import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; + +import java.util.Comparator; +import java.util.List; + +import static ru.ulstu.extractor.ts.util.TimeSeriesDateMapper.mapTimeSeriesToInterval; + +public abstract class DBTimeSeriesCreator extends AbstractTimeSeriesCreator { + /** + * Извлечь список точек временных рядов + * + * @param gitRepository + * @param branchName + * @return + */ + public abstract List getTimeSeries(GitRepository gitRepository, String branchName); + + /** + * Сохранить извлеченные временные ряды + * + * @param gitRepository + * @param branch + */ + public void addTimeSeries(GitRepository gitRepository, Branch branch) { + // извлеченные временных рядов + List timeSeries = getTimeSeries(gitRepository, branch.getName()); + + // сгруппированные по временным интервалам точки временных рядов + timeSeries.forEach(ts -> ts.setValues(mapTimeSeriesToInterval(getTimeSeriesService().getTimeSeriesInterval(), ts.getValues()))); + getTimeSeriesService().save(sortTimeSeries(timeSeries), branch); + } + + private List sortTimeSeries(List timeSeries) { + for (TimeSeries ts : timeSeries) { + ts.getValues().sort(Comparator.comparing(TimeSeriesValue::getDate)); + } + return timeSeries; + } +} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java similarity index 81% rename from src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java index 5d5f21a..dd845f6 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; @@ -6,7 +6,6 @@ import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.gitrepository.model.FileChange; import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -16,27 +15,23 @@ import java.util.ArrayList; import java.util.List; @Component -public class FileTS extends AbstractTimeSeriesCreator { +public class FileTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final GitRepositoryService gitRepositoryService; private final CommitService commitService; private final BranchService branchService; public FileTS(TimeSeriesService timeSeriesService, - GitRepositoryService gitRepositoryService, CommitService commitService, BranchService branchService) { this.timeSeriesService = timeSeriesService; - this.gitRepositoryService = gitRepositoryService; this.commitService = commitService; this.branchService = branchService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(GitRepository gitRepository, String branchName) { List timeSeriesResult = new ArrayList<>(); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName)); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); double value = 0; TimeSeries timeSeries = new TimeSeries( String.format("%s %s %s", diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java similarity index 85% rename from src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java index f2fd7cf..3caec78 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.author.model.Author; @@ -8,6 +8,7 @@ import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; +import ru.ulstu.extractor.ts.creator.db.DBTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -17,11 +18,10 @@ import java.util.ArrayList; import java.util.List; @Component -public class AuthorTS extends AbstractTimeSeriesCreator { +public class AuthorTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final CommitService commitService; private final AuthorService authorService; - private final GitRepositoryService gitRepositoryService; private final BranchService branchService; public AuthorTS(TimeSeriesService timeSeriesService, @@ -32,7 +32,6 @@ public class AuthorTS extends AbstractTimeSeriesCreator { this.timeSeriesService = timeSeriesService; this.commitService = commitService; this.authorService = authorService; - this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; } @@ -42,11 +41,10 @@ public class AuthorTS extends AbstractTimeSeriesCreator { } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { + public List getTimeSeries(GitRepository gitRepository, String branchName) { List timeSeriesResult = new ArrayList<>(); List authors = authorService.findAll(); - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName)); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); for (Author author : authors) { TimeSeries timeSeries = new TimeSeries( String.format("%s %s %s %s", diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java similarity index 86% rename from src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java index 700b6cb..9eeb72d 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; @@ -13,7 +13,7 @@ import java.util.Collections; import java.util.List; @Component -public class AuthorsCompletedIssueTS extends AbstractTimeSeriesCreator { +public class AuthorsCompletedIssueTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; @@ -28,8 +28,7 @@ public class AuthorsCompletedIssueTS extends AbstractTimeSeriesCreator { } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(GitRepository gitRepository, String branchName) { //TODO: добавить постраничное чтение return Collections.singletonList( new TimeSeries( diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java similarity index 94% rename from src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java index c4fa9ea..9407869 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; @@ -13,7 +13,7 @@ import java.util.Collections; import java.util.List; @Component -public class AuthorsIssueTS extends AbstractTimeSeriesCreator { +public class AuthorsIssueTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java new file mode 100644 index 0000000..4ef0042 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java @@ -0,0 +1,35 @@ +package ru.ulstu.extractor.ts.creator.scheduled; + +import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.service.GitApi; +import ru.ulstu.extractor.ts.model.TimeSeriesType; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; + +@Component +public class BranchTS extends ScheduledTimeSeriesCreator { + private final TimeSeriesService timeSeriesService; + private final GitApi gitApi; + + public BranchTS(TimeSeriesService timeSeriesService, + GitApi gitApi) { + this.timeSeriesService = timeSeriesService; + this.gitApi = gitApi; + } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.BRANCHES; + } + + @Override + public TimeSeriesService getTimeSeriesService() { + return timeSeriesService; + } + + @Override + public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { + return new TimeSeriesValue(gitApi.getBranchesCount(branch)); + } +} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java similarity index 94% rename from src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java index f284e90..6062fc0 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java @@ -1,9 +1,10 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; +import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java similarity index 94% rename from src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java index d89b5e8..d53c5b6 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java @@ -1,9 +1,10 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; +import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java similarity index 96% rename from src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java index b20dabd..3666d6b 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; @@ -7,6 +7,7 @@ import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.gitrepository.model.FileChange; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; +import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java similarity index 94% rename from src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java index 4c00620..efc1827 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java @@ -1,9 +1,10 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; +import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java new file mode 100644 index 0000000..69907c6 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java @@ -0,0 +1,35 @@ +package ru.ulstu.extractor.ts.creator.scheduled; + +import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.service.GitApi; +import ru.ulstu.extractor.ts.model.TimeSeriesType; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; + +@Component +public class IssuesTS extends ScheduledTimeSeriesCreator { + private final TimeSeriesService timeSeriesService; + private final GitApi gitApi; + + public IssuesTS(TimeSeriesService timeSeriesService, + GitApi gitApi) { + this.timeSeriesService = timeSeriesService; + this.gitApi = gitApi; + } + + @Override + public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { + return new TimeSeriesValue(gitApi.getOpenIssuesCount(branch)); + } + + @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/scheduled/ProcessTS.java similarity index 94% rename from src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ProcessTS.java index c172063..1dd4675 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ProcessTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; @@ -13,7 +13,7 @@ import java.util.Collections; import java.util.List; @Component -public class ProcessTS extends AbstractTimeSeriesCreator { +public class ProcessTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java new file mode 100644 index 0000000..1be6322 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java @@ -0,0 +1,20 @@ +package ru.ulstu.extractor.ts.creator.scheduled; + +import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; + +import java.util.Collections; + +public abstract class ScheduledTimeSeriesCreator extends AbstractTimeSeriesCreator { + @Transactional + public void addTimeSeriesValue(Branch branch) { + TimeSeries timeSeries = getTimeSeriesService().findByBranchAndTypeOrCreate(branch, getTimeSeriesType()); + timeSeries.getValues().add(getNewTimeSeriesValue(branch)); + getTimeSeriesService().save(Collections.singletonList(timeSeries), branch); + } + + public abstract TimeSeriesValue getNewTimeSeriesValue(Branch branch); +} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java new file mode 100644 index 0000000..6422822 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java @@ -0,0 +1,34 @@ +package ru.ulstu.extractor.ts.creator.scheduled; + +import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.service.GitApi; +import ru.ulstu.extractor.ts.model.TimeSeriesType; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.ts.service.TimeSeriesService; + +@Component +public class StarTS extends ScheduledTimeSeriesCreator { + private final TimeSeriesService timeSeriesService; + private final GitApi gitApi; + + public StarTS(TimeSeriesService timeSeriesService, GitApi gitApi) { + this.timeSeriesService = timeSeriesService; + this.gitApi = gitApi; + } + + @Override + public TimeSeriesService getTimeSeriesService() { + return timeSeriesService; + } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.STARS; + } + + @Override + public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { + return new TimeSeriesValue(gitApi.getStarsCount(branch)); + } +} 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 5e302fa..76abf70 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java @@ -33,6 +33,13 @@ public class TimeSeries extends BaseEntity { public TimeSeries() { } + public TimeSeries(Branch branch, TimeSeriesType timeSeriesType) { + this(String.format("%s %s %s", + branch.getGitRepository().getName(), + branch.getName(), + timeSeriesType.getDescription()), branch, timeSeriesType); + } + public TimeSeries(String name, Branch branch, TimeSeriesType timeSeriesType) { this(name, branch, timeSeriesType, new ArrayList<>()); } diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java index 112b4c5..9b77f2a 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java @@ -18,6 +18,11 @@ public class TimeSeriesValue extends BaseEntity { this.value = value; } + public TimeSeriesValue(Integer value) { + this.date = new Date(); + this.value = Double.valueOf(value); + } + public TimeSeriesValue(TimeSeries timeSeries, Date date, Double value) { this.date = date; this.value = value; diff --git a/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesRepository.java b/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesRepository.java index 7346519..583582c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesRepository.java +++ b/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesRepository.java @@ -1,7 +1,9 @@ package ru.ulstu.extractor.ts.repository; import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import java.util.List; import java.util.Optional; @@ -10,4 +12,6 @@ public interface TimeSeriesRepository extends JpaRepository Optional findByName(String name); List getTimeSeriesByBranchId(Integer branchId); + + Optional getTimeSeriesByBranchAndTimeSeriesType(Branch branch, TimeSeriesType timeSeriesType); } diff --git a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java new file mode 100644 index 0000000..4dc636e --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java @@ -0,0 +1,34 @@ +package ru.ulstu.extractor.ts.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.branch.service.BranchService; +import ru.ulstu.extractor.ts.creator.scheduled.ScheduledTimeSeriesCreator; + +import java.util.List; + +@Service +public class ScheduledTimeSeriesService { + private final Logger log = LoggerFactory.getLogger(ScheduledTimeSeriesService.class); + private final List scheduledTimeSeriesCreators; + private final BranchService branchService; + + public ScheduledTimeSeriesService(List scheduledTimeSeriesCreators, + BranchService branchService) { + this.scheduledTimeSeriesCreators = scheduledTimeSeriesCreators; + this.branchService = branchService; + } + + @Scheduled(cron = "0 */5 * * * *", zone = "Europe/Samara") + public void addTimeSeriesPoints() { + log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); + List branches = branchService.findAll(); + branches.forEach(branch -> { + scheduledTimeSeriesCreators.forEach(creator -> creator.addTimeSeriesValue(branch)); + }); + log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished"); + } +} 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 4cc2de9..3989f2e 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -59,7 +59,7 @@ public class TimeSeriesService { return savedTimeSeries; } - public TimeSeries findOrCreate(String timeSeriesName, Branch branch, TimeSeriesType timeSeriesType) { + private TimeSeries findOrCreate(String timeSeriesName, Branch branch, TimeSeriesType timeSeriesType) { Optional maybeTimeSeries = timeSeriesRepository.findByName(timeSeriesName); if (maybeTimeSeries.isPresent()) { LOG.debug("TimeSeries {} exists.", maybeTimeSeries.get().getName()); @@ -68,6 +68,15 @@ public class TimeSeriesService { return timeSeriesRepository.save(new TimeSeries(timeSeriesName, branch, timeSeriesType)); } + public TimeSeries findByBranchAndTypeOrCreate(Branch branch, TimeSeriesType timeSeriesType) { + Optional maybeTimeSeries = timeSeriesRepository.getTimeSeriesByBranchAndTimeSeriesType(branch, timeSeriesType); + if (maybeTimeSeries.isPresent()) { + LOG.debug("TimeSeries {} exists.", maybeTimeSeries.get().getName()); + return maybeTimeSeries.get(); + } + return timeSeriesRepository.save(new TimeSeries(branch, timeSeriesType)); + } + /** * Сохранить список временных рядов * -- 2.34.1 From aeab50cfb8ebb025d58d0f7a49e071f7bf68b885 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 15 Feb 2023 18:28:39 +0400 Subject: [PATCH 055/110] #89 -- Create a valid class hierarchy --- .../gitrepository/service/GitApi.java | 4 ++ .../gitrepository/service/GitAtheneApi.java | 16 ++++++ .../gitrepository/service/IndexService.java | 2 +- .../ts/creator/db/AuthorsCommitTS.java | 14 +++-- .../ts/creator/{scheduled => db}/ClassTS.java | 23 +++----- .../extractor/ts/creator/db/CommitsTS.java | 14 +++-- .../ts/creator/db/DBTimeSeriesCreator.java | 11 ++-- .../{scheduled => db}/DependenceTS.java | 23 +++----- .../creator/{scheduled => db}/EntityTS.java | 24 +++----- .../ulstu/extractor/ts/creator/db/FileTS.java | 14 +++-- .../{scheduled => db}/InterfaceTS.java | 23 +++----- .../creator/{scheduled => db}/ProcessTS.java | 22 +++----- .../ts/creator/scheduled/AuthorTS.java | 55 +++---------------- .../scheduled/AuthorsCompletedIssueTS.java | 53 ------------------ .../ts/creator/scheduled/AuthorsIssueTS.java | 53 ------------------ 15 files changed, 98 insertions(+), 253 deletions(-) rename src/main/java/ru/ulstu/extractor/ts/creator/{scheduled => db}/ClassTS.java (56%) rename src/main/java/ru/ulstu/extractor/ts/creator/{scheduled => db}/DependenceTS.java (56%) rename src/main/java/ru/ulstu/extractor/ts/creator/{scheduled => db}/EntityTS.java (71%) rename src/main/java/ru/ulstu/extractor/ts/creator/{scheduled => db}/InterfaceTS.java (56%) rename src/main/java/ru/ulstu/extractor/ts/creator/{scheduled => db}/ProcessTS.java (58%) delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java index 3aa4e59..1267a15 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java @@ -10,4 +10,8 @@ public interface GitApi { Integer getOpenIssuesCount(Branch branch); String getFormattedUrl(String gitRepositoryUrl, String template); + + Integer getAuthorsCompletedIssues(Branch branch); + + Integer getAuthorsCount(Branch branch); } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java index a8853dc..eb79ab5 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java @@ -10,6 +10,8 @@ public class GitAtheneApi implements GitApi { private static final String BRANCHES_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; private static final String STARS_COUNT_URL = "%s/api/v1/repos/%s/%s"; private static final String OPEN_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; + private static final String AUTHOR_COMPLETED_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; + private static final String AUTHORS_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; public GitAtheneApi(HttpService httpService) { this.httpService = httpService; @@ -42,4 +44,18 @@ public class GitAtheneApi implements GitApi { String[] urlParts = gitRepositoryUrl.split("/"); return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]); } + + @Override + public Integer getAuthorsCompletedIssues(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHOR_COMPLETED_ISSUES_URL)) + .length(); + } + + @Override + public Integer getAuthorsCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHORS_COUNT_URL)) + .length(); + } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index 088aa22..7921c21 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -79,7 +79,7 @@ public class IndexService { commits = gitRepositoryService.getCommits(gitRepository.getUrl(), branch.getName(), commitsFrom, commitsTo, false); } final Branch branchForSave = branch; - timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(gitRepository, branchForSave)); + timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(branchForSave)); branchService.updateStatus(branch, IndexingStatus.FINISHED); LOG.debug("Complete indexing {} branch", branch.getName()); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java index dc95528..dd1b7c8 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java @@ -3,10 +3,10 @@ package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; import ru.ulstu.extractor.author.model.Author; import ru.ulstu.extractor.author.service.AuthorService; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.commit.service.CommitService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -38,18 +38,20 @@ public class AuthorsCommitTS extends DBTimeSeriesCreator { } @Override - public List getTimeSeries(GitRepository gitRepository, String branchName) { + public List getTimeSeries(Branch branch) { List timeSeriesResult = new ArrayList<>(); List authors = authorService.findAll(); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(branch.getGitRepository().getId(), + branch.getName())); for (Author author : authors) { TimeSeries timeSeries = new TimeSeries( String.format("%s %s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), author.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), + branch.getName()), getTimeSeriesType()); for (Commit commit : commits) { if (commit.getAuthor().equals(author)) { diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/ClassTS.java similarity index 56% rename from src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/ClassTS.java index 6062fc0..904238c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/ClassTS.java @@ -1,10 +1,8 @@ -package ru.ulstu.extractor.ts.creator.scheduled; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -14,30 +12,25 @@ import java.util.Collections; import java.util.List; @Component -public class ClassTS extends AbstractTimeSeriesCreator { +public class ClassTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; - private final GitRepositoryService gitRepositoryService; - public ClassTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { + BranchService branchService) { this.timeSeriesService = timeSeriesService; this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(Branch branch) { return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), branch.getName()), getTimeSeriesType(), Dummy.getDefaultTimeSeries())); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java index 523ff76..a8982c1 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java @@ -1,9 +1,9 @@ package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.service.CommitService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -28,17 +28,19 @@ public class CommitsTS extends DBTimeSeriesCreator { } @Override - public List getTimeSeries(GitRepository gitRepository, String branchName) { + public List getTimeSeries(Branch branch) { //TODO: добавить постраничное чтение return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), + branch.getName()), getTimeSeriesType(), - commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName) + commitService.findByRepositoryIdAndName(branch.getGitRepository().getId(), + branch.getName()) .stream() .map(c -> new TimeSeriesValue(c.getDate(), 1.0)) .collect(Collectors.toList()))); diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java index 7de98b7..214aa32 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java @@ -1,7 +1,6 @@ package ru.ulstu.extractor.ts.creator.db; import ru.ulstu.extractor.branch.model.Branch; -import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -15,21 +14,19 @@ public abstract class DBTimeSeriesCreator extends AbstractTimeSeriesCreator { /** * Извлечь список точек временных рядов * - * @param gitRepository - * @param branchName + * @param branch * @return */ - public abstract List getTimeSeries(GitRepository gitRepository, String branchName); + public abstract List getTimeSeries(Branch branch); /** * Сохранить извлеченные временные ряды * - * @param gitRepository * @param branch */ - public void addTimeSeries(GitRepository gitRepository, Branch branch) { + public void addTimeSeries(Branch branch) { // извлеченные временных рядов - List timeSeries = getTimeSeries(gitRepository, branch.getName()); + List timeSeries = getTimeSeries(branch); // сгруппированные по временным интервалам точки временных рядов timeSeries.forEach(ts -> ts.setValues(mapTimeSeriesToInterval(getTimeSeriesService().getTimeSeriesInterval(), ts.getValues()))); diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/DependenceTS.java similarity index 56% rename from src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/DependenceTS.java index d53c5b6..385f2a0 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/DependenceTS.java @@ -1,10 +1,8 @@ -package ru.ulstu.extractor.ts.creator.scheduled; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -14,30 +12,25 @@ import java.util.Collections; import java.util.List; @Component -public class DependenceTS extends AbstractTimeSeriesCreator { +public class DependenceTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; - private final GitRepositoryService gitRepositoryService; - public DependenceTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { + BranchService branchService) { this.timeSeriesService = timeSeriesService; this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(Branch branch) { return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), branch.getName()), getTimeSeriesType(), Dummy.getDefaultTimeSeries())); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/EntityTS.java similarity index 71% rename from src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/EntityTS.java index 3666d6b..aed07b3 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/EntityTS.java @@ -1,13 +1,11 @@ -package ru.ulstu.extractor.ts.creator.scheduled; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.gitrepository.model.FileChange; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -19,36 +17,32 @@ import java.util.List; import java.util.stream.Collectors; @Component -public class EntityTS extends AbstractTimeSeriesCreator { +public class EntityTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final CommitService commitService; - private final GitRepositoryService gitRepositoryService; private final BranchService branchService; public EntityTS(TimeSeriesService timeSeriesService, CommitService commitService, - GitRepositoryService gitRepositoryService, BranchService branchService) { this.timeSeriesService = timeSeriesService; this.commitService = commitService; - this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(Branch branch) { return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), branch.getName()), getTimeSeriesType(), - commitService.findByRepositoryIdAndName(repositoryId, branchName) + commitService.findByRepositoryIdAndName(branch.getGitRepository().getId(), branch.getName()) .stream() - .map(c -> new TimeSeriesValue(c.getDate(), findEntity(repositoryId, branchName))) + .map(c -> new TimeSeriesValue(c.getDate(), findEntity(branch.getGitRepository().getId(), branch.getName()))) .collect(Collectors.toList()))); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java index dd845f6..3d4b62d 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java @@ -1,11 +1,11 @@ package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.gitrepository.model.FileChange; -import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -29,16 +29,18 @@ public class FileTS extends DBTimeSeriesCreator { } @Override - public List getTimeSeries(GitRepository gitRepository, String branchName) { + public List getTimeSeries(Branch branch) { List timeSeriesResult = new ArrayList<>(); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(branch.getGitRepository().getId(), + branch.getName())); double value = 0; TimeSeries timeSeries = new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), + branch.getName()), getTimeSeriesType()); for (Commit commit : commits) { for (FileChange fileChange : commit.getFileChanges()) { diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/InterfaceTS.java similarity index 56% rename from src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/InterfaceTS.java index efc1827..08d8cda 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/InterfaceTS.java @@ -1,10 +1,8 @@ -package ru.ulstu.extractor.ts.creator.scheduled; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -14,30 +12,25 @@ import java.util.Collections; import java.util.List; @Component -public class InterfaceTS extends AbstractTimeSeriesCreator { +public class InterfaceTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; - private final GitRepositoryService gitRepositoryService; - public InterfaceTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { + BranchService branchService) { this.timeSeriesService = timeSeriesService; this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(Branch branch) { return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), branch.getName()), getTimeSeriesType(), Dummy.getDefaultTimeSeries())); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ProcessTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/ProcessTS.java similarity index 58% rename from src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ProcessTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/ProcessTS.java index 1dd4675..c900678 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ProcessTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/ProcessTS.java @@ -1,9 +1,8 @@ -package ru.ulstu.extractor.ts.creator.scheduled; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -13,30 +12,25 @@ import java.util.Collections; import java.util.List; @Component -public class ProcessTS extends ScheduledTimeSeriesCreator { +public class ProcessTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; - private final GitRepositoryService gitRepositoryService; - public ProcessTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { + BranchService branchService) { this.timeSeriesService = timeSeriesService; this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(Branch branch) { return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), branch.getName()), getTimeSeriesType(), Dummy.getDefaultTimeSeries())); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java index 3caec78..768f16f 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java @@ -1,38 +1,20 @@ package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.author.model.Author; -import ru.ulstu.extractor.author.service.AuthorService; -import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.commit.model.Commit; -import ru.ulstu.extractor.commit.service.CommitService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.creator.db.DBTimeSeriesCreator; -import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.service.GitApi; 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.List; - @Component -public class AuthorTS extends DBTimeSeriesCreator { +public class AuthorTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final CommitService commitService; - private final AuthorService authorService; - private final BranchService branchService; + private final GitApi gitApi; - public AuthorTS(TimeSeriesService timeSeriesService, - CommitService commitService, - AuthorService authorService, - GitRepositoryService gitRepositoryService, - BranchService branchService) { + public AuthorTS(TimeSeriesService timeSeriesService, GitApi gitApi) { this.timeSeriesService = timeSeriesService; - this.commitService = commitService; - this.authorService = authorService; - this.branchService = branchService; + this.gitApi = gitApi; } @Override @@ -41,29 +23,8 @@ public class AuthorTS extends DBTimeSeriesCreator { } @Override - public List getTimeSeries(GitRepository gitRepository, String branchName) { - List timeSeriesResult = new ArrayList<>(); - List authors = authorService.findAll(); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); - for (Author author : authors) { - TimeSeries timeSeries = new TimeSeries( - String.format("%s %s %s %s", - gitRepository.getName(), - branchName, - author.getName(), - getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), - getTimeSeriesType()); - for (Commit commit : commits) { - if (commit.getAuthor().equals(author)) { - timeSeries.getValues().add(new TimeSeriesValue(commit.getDate(), 1.0)); - } - } - if (!timeSeries.getValues().isEmpty()) { - timeSeriesResult.add(timeSeries); - } - } - return timeSeriesResult; + public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { + return new TimeSeriesValue(gitApi.getAuthorsCount(branch)); } @Override diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java deleted file mode 100644 index 9eeb72d..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.ulstu.extractor.ts.creator.scheduled; - -import org.springframework.stereotype.Component; -import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.model.TimeSeries; -import ru.ulstu.extractor.ts.model.TimeSeriesType; -import ru.ulstu.extractor.ts.service.TimeSeriesService; -import ru.ulstu.extractor.ts.util.Dummy; - -import java.util.Collections; -import java.util.List; - -@Component -public class AuthorsCompletedIssueTS extends ScheduledTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final BranchService branchService; - - private final GitRepositoryService gitRepositoryService; - - public AuthorsCompletedIssueTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { - this.timeSeriesService = timeSeriesService; - this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; - } - - @Override - public List getTimeSeries(GitRepository gitRepository, String branchName) { - //TODO: добавить постраничное чтение - return Collections.singletonList( - new TimeSeries( - String.format("%s %s %s", - gitRepository.getName(), - branchName, - getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), - getTimeSeriesType(), - Dummy.getDefaultTimeSeries())); - } - - @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/scheduled/AuthorsIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java deleted file mode 100644 index 9407869..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.ulstu.extractor.ts.creator.scheduled; - -import org.springframework.stereotype.Component; -import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.model.TimeSeries; -import ru.ulstu.extractor.ts.model.TimeSeriesType; -import ru.ulstu.extractor.ts.service.TimeSeriesService; -import ru.ulstu.extractor.ts.util.Dummy; - -import java.util.Collections; -import java.util.List; - -@Component -public class AuthorsIssueTS extends ScheduledTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final BranchService branchService; - - private final GitRepositoryService gitRepositoryService; - - public AuthorsIssueTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { - this.timeSeriesService = timeSeriesService; - this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; - } - - @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); - return Collections.singletonList( - new TimeSeries( - String.format("%s %s %s", - gitRepository.getName(), - branchName, - getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), - getTimeSeriesType(), - Dummy.getDefaultTimeSeries())); - } - - @Override - public TimeSeriesService getTimeSeriesService() { - return timeSeriesService; - } - - @Override - public TimeSeriesType getTimeSeriesType() { - return TimeSeriesType.AUTHOR_ISSUES; - } -} -- 2.34.1 From 3de664abb1e1829d70c630a277383e4258899f33 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 16 Feb 2023 00:39:13 +0400 Subject: [PATCH 056/110] #89 -- Divide git api services --- .../gitrepository/service/GithubApi.java | 61 +++++++++++++++++++ .../gitrepository/service/GitlabApi.java | 61 +++++++++++++++++++ .../ru/ulstu/extractor/http/HttpService.java | 2 +- .../ts/creator/scheduled/AuthorTS.java | 12 ++-- .../ts/creator/scheduled/BranchTS.java | 11 ++-- .../ts/creator/scheduled/IssuesTS.java | 11 ++-- .../scheduled/ScheduledTimeSeriesCreator.java | 15 +++++ .../ts/creator/scheduled/StarTS.java | 12 ++-- .../ru/ulstu/extractor/util/StringUtils.java | 6 ++ 9 files changed, 170 insertions(+), 21 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java create mode 100644 src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java new file mode 100644 index 0000000..11145ca --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java @@ -0,0 +1,61 @@ +package ru.ulstu.extractor.gitrepository.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.http.HttpService; + +@Service +public class GithubApi implements GitApi { + private final HttpService httpService; + private static final String BRANCHES_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; + private static final String STARS_COUNT_URL = "%s/api/v1/repos/%s/%s"; + private static final String OPEN_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; + private static final String AUTHOR_COMPLETED_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; + private static final String AUTHORS_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; + + public GithubApi(HttpService httpService) { + this.httpService = httpService; + } + + @Override + public Integer getBranchesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .length(); + } + + @Override + public Integer getStarsCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .getJSONObject(0) + .getInt("stars_count"); + } + + @Override + public Integer getOpenIssuesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .length(); + } + + @Override + public String getFormattedUrl(String gitRepositoryUrl, String template) { + String[] urlParts = gitRepositoryUrl.split("/"); + return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]); + } + + @Override + public Integer getAuthorsCompletedIssues(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHOR_COMPLETED_ISSUES_URL)) + .length(); + } + + @Override + public Integer getAuthorsCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHORS_COUNT_URL)) + .length(); + } +} diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java new file mode 100644 index 0000000..975e0f8 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java @@ -0,0 +1,61 @@ +package ru.ulstu.extractor.gitrepository.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.http.HttpService; + +@Service +public class GitlabApi implements GitApi { + private final HttpService httpService; + private static final String BRANCHES_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; + private static final String STARS_COUNT_URL = "%s/api/v1/repos/%s/%s"; + private static final String OPEN_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; + private static final String AUTHOR_COMPLETED_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; + private static final String AUTHORS_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; + + public GitlabApi(HttpService httpService) { + this.httpService = httpService; + } + + @Override + public Integer getBranchesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .length(); + } + + @Override + public Integer getStarsCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .getJSONObject(0) + .getInt("stars_count"); + } + + @Override + public Integer getOpenIssuesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .length(); + } + + @Override + public String getFormattedUrl(String gitRepositoryUrl, String template) { + String[] urlParts = gitRepositoryUrl.split("/"); + return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]); + } + + @Override + public Integer getAuthorsCompletedIssues(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHOR_COMPLETED_ISSUES_URL)) + .length(); + } + + @Override + public Integer getAuthorsCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHORS_COUNT_URL)) + .length(); + } +} diff --git a/src/main/java/ru/ulstu/extractor/http/HttpService.java b/src/main/java/ru/ulstu/extractor/http/HttpService.java index cc1884e..2c24f1f 100644 --- a/src/main/java/ru/ulstu/extractor/http/HttpService.java +++ b/src/main/java/ru/ulstu/extractor/http/HttpService.java @@ -58,7 +58,7 @@ public class HttpService { return jsonArray; } } catch (Exception e) { - return new JSONArray("[{response:\"empty\"}]"); + throw new RuntimeException(e); } } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java index 768f16f..a07007c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java @@ -1,8 +1,8 @@ package ru.ulstu.extractor.ts.creator.scheduled; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.model.Branch; -import ru.ulstu.extractor.gitrepository.service.GitApi; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -10,11 +10,12 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; @Component public class AuthorTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final GitApi gitApi; + private final ApplicationContext applicationContext; - public AuthorTS(TimeSeriesService timeSeriesService, GitApi gitApi) { + public AuthorTS(TimeSeriesService timeSeriesService, + ApplicationContext applicationContext) { this.timeSeriesService = timeSeriesService; - this.gitApi = gitApi; + this.applicationContext = applicationContext; } @Override @@ -24,7 +25,8 @@ public class AuthorTS extends ScheduledTimeSeriesCreator { @Override public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(gitApi.getAuthorsCount(branch)); + return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) + .getAuthorsCount(branch)); } @Override diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java index 4ef0042..81289db 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java @@ -1,8 +1,8 @@ package ru.ulstu.extractor.ts.creator.scheduled; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.model.Branch; -import ru.ulstu.extractor.gitrepository.service.GitApi; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -10,12 +10,12 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; @Component public class BranchTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final GitApi gitApi; + private final ApplicationContext applicationContext; public BranchTS(TimeSeriesService timeSeriesService, - GitApi gitApi) { + ApplicationContext applicationContext) { this.timeSeriesService = timeSeriesService; - this.gitApi = gitApi; + this.applicationContext = applicationContext; } @Override @@ -30,6 +30,7 @@ public class BranchTS extends ScheduledTimeSeriesCreator { @Override public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(gitApi.getBranchesCount(branch)); + return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) + .getBranchesCount(branch)); } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java index 69907c6..8d26648 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java @@ -1,8 +1,8 @@ package ru.ulstu.extractor.ts.creator.scheduled; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.model.Branch; -import ru.ulstu.extractor.gitrepository.service.GitApi; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -10,17 +10,18 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; @Component public class IssuesTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final GitApi gitApi; + private final ApplicationContext applicationContext; public IssuesTS(TimeSeriesService timeSeriesService, - GitApi gitApi) { + ApplicationContext applicationContext) { this.timeSeriesService = timeSeriesService; - this.gitApi = gitApi; + this.applicationContext = applicationContext; } @Override public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(gitApi.getOpenIssuesCount(branch)); + return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) + .getOpenIssuesCount(branch)); } @Override diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java index 1be6322..0bb3786 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java @@ -2,13 +2,24 @@ package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.service.GitApi; +import ru.ulstu.extractor.gitrepository.service.GitAtheneApi; +import ru.ulstu.extractor.gitrepository.service.GithubApi; +import ru.ulstu.extractor.gitrepository.service.GitlabApi; import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.util.StringUtils; import java.util.Collections; +import java.util.Map; public abstract class ScheduledTimeSeriesCreator extends AbstractTimeSeriesCreator { + private final Map> gitApiServiceHolder = Map.of( + "git.athene.tech", GitAtheneApi.class, + "github.com", GithubApi.class, + "gitlab.com", GitlabApi.class); + @Transactional public void addTimeSeriesValue(Branch branch) { TimeSeries timeSeries = getTimeSeriesService().findByBranchAndTypeOrCreate(branch, getTimeSeriesType()); @@ -17,4 +28,8 @@ public abstract class ScheduledTimeSeriesCreator extends AbstractTimeSeriesCreat } public abstract TimeSeriesValue getNewTimeSeriesValue(Branch branch); + + public Class getGitApiServiceClass(Branch branch) { + return gitApiServiceHolder.get(StringUtils.getServerDomain(branch.getGitRepository().getUrl())); + } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java index 6422822..27becfa 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java @@ -1,8 +1,8 @@ package ru.ulstu.extractor.ts.creator.scheduled; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.model.Branch; -import ru.ulstu.extractor.gitrepository.service.GitApi; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -10,11 +10,12 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; @Component public class StarTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final GitApi gitApi; + private final ApplicationContext applicationContext; - public StarTS(TimeSeriesService timeSeriesService, GitApi gitApi) { + public StarTS(TimeSeriesService timeSeriesService, + ApplicationContext applicationContext) { this.timeSeriesService = timeSeriesService; - this.gitApi = gitApi; + this.applicationContext = applicationContext; } @Override @@ -29,6 +30,7 @@ public class StarTS extends ScheduledTimeSeriesCreator { @Override public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(gitApi.getStarsCount(branch)); + return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) + .getStarsCount(branch)); } } diff --git a/src/main/java/ru/ulstu/extractor/util/StringUtils.java b/src/main/java/ru/ulstu/extractor/util/StringUtils.java index ec448bc..9d137e5 100644 --- a/src/main/java/ru/ulstu/extractor/util/StringUtils.java +++ b/src/main/java/ru/ulstu/extractor/util/StringUtils.java @@ -9,6 +9,7 @@ import java.nio.file.FileSystems; public class StringUtils { public final static String EMPTY_STRING = ""; + public final static String SERVER_DOMAIN_PATTERN = "%s"; private final static String PATH_SEPARATOR = FileSystems.getDefault().getSeparator(); public static String addPathSeparator(String path) { @@ -25,4 +26,9 @@ public class StringUtils { public static boolean fileInSubdirectory(String filePath, String projectPath, String subDirectory) { return filePath.startsWith(projectPath + PATH_SEPARATOR + subDirectory); } + + public static String getServerDomain(String url) { + String[] urlParts = url.split("/"); + return urlParts[2]; + } } -- 2.34.1 From 78016741cf3938fce731f217f6eecee2ab40bb51 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 19 Feb 2023 23:59:30 +0400 Subject: [PATCH 057/110] #89 -- Fix scheduled time series --- .../gitrepository/model/GitRepository.java | 8 +++- .../gitrepository/service/GitApi.java | 4 +- .../gitrepository/service/GitAtheneApi.java | 22 +++------ .../gitrepository/service/GithubApi.java | 32 +++++-------- .../gitrepository/service/GitlabApi.java | 46 +++++++++++-------- .../ru/ulstu/extractor/http/HttpService.java | 2 + .../ts/creator/scheduled/AuthorTS.java | 36 --------------- 7 files changed, 56 insertions(+), 94 deletions(-) delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java index f2b8276..da94301 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java @@ -26,7 +26,11 @@ public class GitRepository extends BaseEntity { public String getName() { int lastDelimiterIndex = url.lastIndexOf("/"); return (lastDelimiterIndex > 0 && lastDelimiterIndex < url.length()) - ? url.substring(lastDelimiterIndex + 1) - : url; + ? removeDotGit(url.substring(lastDelimiterIndex + 1)) + : removeDotGit(url); + } + + private String removeDotGit(String prevName) { + return prevName.substring(0, prevName.lastIndexOf(".git")); } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java index 1267a15..4be8736 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java @@ -9,9 +9,7 @@ public interface GitApi { Integer getOpenIssuesCount(Branch branch); - String getFormattedUrl(String gitRepositoryUrl, String template); + String getFormattedUrl(Branch branch, String template); Integer getAuthorsCompletedIssues(Branch branch); - - Integer getAuthorsCount(Branch branch); } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java index eb79ab5..d6644e1 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java @@ -10,8 +10,7 @@ public class GitAtheneApi implements GitApi { private static final String BRANCHES_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; private static final String STARS_COUNT_URL = "%s/api/v1/repos/%s/%s"; private static final String OPEN_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; - private static final String AUTHOR_COMPLETED_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; - private static final String AUTHORS_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; + private static final String COMPLETED_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=closed"; public GitAtheneApi(HttpService httpService) { this.httpService = httpService; @@ -20,14 +19,14 @@ public class GitAtheneApi implements GitApi { @Override public Integer getBranchesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .get(getFormattedUrl(branch, BRANCHES_COUNT_URL)) .length(); } @Override public Integer getStarsCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .get(getFormattedUrl(branch, STARS_COUNT_URL)) .getJSONObject(0) .getInt("stars_count"); } @@ -35,27 +34,20 @@ public class GitAtheneApi implements GitApi { @Override public Integer getOpenIssuesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .get(getFormattedUrl(branch, OPEN_ISSUES_URL)) .length(); } @Override - public String getFormattedUrl(String gitRepositoryUrl, String template) { - String[] urlParts = gitRepositoryUrl.split("/"); + public String getFormattedUrl(Branch branch, String template) { + String[] urlParts = branch.getGitRepository().getUrl().split("/"); return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]); } @Override public Integer getAuthorsCompletedIssues(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHOR_COMPLETED_ISSUES_URL)) - .length(); - } - - @Override - public Integer getAuthorsCount(Branch branch) { - return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHORS_COUNT_URL)) + .get(getFormattedUrl(branch, COMPLETED_ISSUES_URL)) .length(); } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java index 11145ca..e744bb7 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java @@ -7,11 +7,10 @@ import ru.ulstu.extractor.http.HttpService; @Service public class GithubApi implements GitApi { private final HttpService httpService; - private static final String BRANCHES_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; - private static final String STARS_COUNT_URL = "%s/api/v1/repos/%s/%s"; - private static final String OPEN_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; - private static final String AUTHOR_COMPLETED_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; - private static final String AUTHORS_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; + private static final String BRANCHES_COUNT_URL = "https://api.github.com/repos/%s/%s/branches"; + private static final String STARS_COUNT_URL = "https://api.github.com/repos/%s/%s"; + private static final String OPEN_ISSUES_URL = "https://api.github.com/repos/%s/%s/issues?state=open"; + private static final String AUTHOR_COMPLETED_ISSUES_URL = "https://api.github.com/repos/%s/%s/issues?state=open"; public GithubApi(HttpService httpService) { this.httpService = httpService; @@ -20,42 +19,35 @@ public class GithubApi implements GitApi { @Override public Integer getBranchesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .get(getFormattedUrl(branch, BRANCHES_COUNT_URL)) .length(); } @Override public Integer getStarsCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .get(getFormattedUrl(branch, STARS_COUNT_URL)) .getJSONObject(0) - .getInt("stars_count"); + .getInt("watchers"); } @Override public Integer getOpenIssuesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .get(getFormattedUrl(branch, OPEN_ISSUES_URL)) .length(); } @Override - public String getFormattedUrl(String gitRepositoryUrl, String template) { - String[] urlParts = gitRepositoryUrl.split("/"); - return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]); + public String getFormattedUrl(Branch branch, String template) { + String[] urlParts = branch.getGitRepository().getUrl().split("/"); + return String.format(template, urlParts[3], urlParts[4]); } @Override public Integer getAuthorsCompletedIssues(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHOR_COMPLETED_ISSUES_URL)) - .length(); - } - - @Override - public Integer getAuthorsCount(Branch branch) { - return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHORS_COUNT_URL)) + .get(getFormattedUrl(branch, AUTHOR_COMPLETED_ISSUES_URL)) .length(); } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java index 975e0f8..60feab5 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java @@ -1,5 +1,6 @@ package ru.ulstu.extractor.gitrepository.service; +import org.json.JSONArray; import org.springframework.stereotype.Service; import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.http.HttpService; @@ -7,11 +8,11 @@ import ru.ulstu.extractor.http.HttpService; @Service public class GitlabApi implements GitApi { private final HttpService httpService; - private static final String BRANCHES_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; - private static final String STARS_COUNT_URL = "%s/api/v1/repos/%s/%s"; - private static final String OPEN_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; - private static final String AUTHOR_COMPLETED_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; - private static final String AUTHORS_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; + private static final String BRANCHES_COUNT_URL = "%s/api/v4/projects/%s/repository/branches"; + private final static String PROJECT_ID_URL = "https://gitlab.com/api/v4/users/%s/projects?search=%s"; + private static final String PROJECT_INFO_URL = "%s/api/v4/projects/%s"; + private static final String OPEN_ISSUES_URL = "%s/api/v4/projects/%s/issues?state=opened"; + private static final String COMPLETED_ISSUES_URL = "%s/api/v4/projects/%s/issues?state=closed"; public GitlabApi(HttpService httpService) { this.httpService = httpService; @@ -20,42 +21,51 @@ public class GitlabApi implements GitApi { @Override public Integer getBranchesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .get(getFormattedUrl(branch, BRANCHES_COUNT_URL)) .length(); } @Override public Integer getStarsCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .get(getFormattedUrl(branch, PROJECT_INFO_URL)) .getJSONObject(0) - .getInt("stars_count"); + .getInt("star_count"); } @Override public Integer getOpenIssuesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .get(getFormattedUrl(branch, OPEN_ISSUES_URL)) .length(); } @Override - public String getFormattedUrl(String gitRepositoryUrl, String template) { - String[] urlParts = gitRepositoryUrl.split("/"); - return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]); + public String getFormattedUrl(Branch branch, String template) { + String[] urlParts = branch.getGitRepository().getUrl().split("/"); + return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], getProjectId(branch)); + } + + public String getFormattedUrlForProjectId(Branch branch, String template) { + String[] urlParts = branch.getGitRepository().getUrl().split("/"); + // получаем корректное название репозитория, gitlab всегда добавляет .git в конец + return String.format(template, urlParts[3], branch.getGitRepository().getName()); } @Override public Integer getAuthorsCompletedIssues(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHOR_COMPLETED_ISSUES_URL)) + .get(getFormattedUrl(branch, COMPLETED_ISSUES_URL)) .length(); } - @Override - public Integer getAuthorsCount(Branch branch) { - return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHORS_COUNT_URL)) - .length(); + private String getProjectId(Branch branch) { + JSONArray projects = httpService.get(getFormattedUrlForProjectId(branch, PROJECT_ID_URL)); + for (int i = 0; i < projects.length(); i++) { + if (projects.getJSONObject(i).get("name").equals(branch.getGitRepository().getName())) { + return String.valueOf(projects.getJSONObject(i).getInt("id")); + } + } + throw new RuntimeException("Id проекта не найден: " + branch.getGitRepository().getName()); } } diff --git a/src/main/java/ru/ulstu/extractor/http/HttpService.java b/src/main/java/ru/ulstu/extractor/http/HttpService.java index 2c24f1f..1e53488 100644 --- a/src/main/java/ru/ulstu/extractor/http/HttpService.java +++ b/src/main/java/ru/ulstu/extractor/http/HttpService.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; +import java.time.Duration; import java.util.Optional; @Service @@ -49,6 +50,7 @@ public class HttpService { .accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToMono(String.class) + .timeout(Duration.ofMinutes(1)) .toFuture().get(); if (response.startsWith("[")) { return new JSONArray(response); diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java deleted file mode 100644 index a07007c..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java +++ /dev/null @@ -1,36 +0,0 @@ -package ru.ulstu.extractor.ts.creator.scheduled; - -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Component; -import ru.ulstu.extractor.branch.model.Branch; -import ru.ulstu.extractor.ts.model.TimeSeriesType; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; -import ru.ulstu.extractor.ts.service.TimeSeriesService; - -@Component -public class AuthorTS extends ScheduledTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final ApplicationContext applicationContext; - - public AuthorTS(TimeSeriesService timeSeriesService, - ApplicationContext applicationContext) { - this.timeSeriesService = timeSeriesService; - this.applicationContext = applicationContext; - } - - @Override - public TimeSeriesType getTimeSeriesType() { - return TimeSeriesType.AUTHORS; - } - - @Override - public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) - .getAuthorsCount(branch)); - } - - @Override - public TimeSeriesService getTimeSeriesService() { - return timeSeriesService; - } -} -- 2.34.1 From a5c9d15d4f7f19e46bdc2bfc0d0840a9a33121ac Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 20 Feb 2023 10:10:41 +0400 Subject: [PATCH 058/110] #89 -- Fix logs --- .../ts/service/ScheduledTimeSeriesService.java | 6 +++--- .../ulstu/extractor/ts/service/TimeSeriesService.java | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java index 4dc636e..55aeae5 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java @@ -22,13 +22,13 @@ public class ScheduledTimeSeriesService { this.branchService = branchService; } - @Scheduled(cron = "0 */5 * * * *", zone = "Europe/Samara") + @Scheduled(cron = "0 0 * * * *", zone = "Europe/Samara") public void addTimeSeriesPoints() { - log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); + log.debug("Старт добавления новых точек временного ряда"); List branches = branchService.findAll(); branches.forEach(branch -> { scheduledTimeSeriesCreators.forEach(creator -> creator.addTimeSeriesValue(branch)); }); - log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished"); + log.debug("Завершение добавления новых точек временного ряда"); } } 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 3989f2e..d5e12e6 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -47,13 +47,13 @@ public class TimeSeriesService { @Transactional public TimeSeries save(String timeSeriesName, Branch branch, TimeSeriesType timeSeriesType, List timeSeriesValues) { - LOG.debug("Start save {} time series with {} time series values ", timeSeriesName, timeSeriesValues.size()); + LOG.debug("Начало сохранения временного ряда {} с {} значениями", timeSeriesName, timeSeriesValues.size()); final TimeSeries timeSeries = findOrCreate(timeSeriesName, branch, timeSeriesType); List timeSeriesValuesToRemove = timeSeries.getValues(); timeSeries.setValues(timeSeriesValues); - LOG.debug("Save time series {} ", timeSeries.getName()); + LOG.debug("Сохранение временного ряда {} ", timeSeries.getName()); TimeSeries savedTimeSeries = timeSeriesRepository.save(timeSeries); - LOG.debug("Clear {} time series values ", timeSeriesValuesToRemove.size()); + LOG.debug("Очистить {} точек временного ряда", timeSeriesValuesToRemove.size()); timeSeriesValueRepository.deleteAll(timeSeriesValuesToRemove); sendToTimeSeriesService(savedTimeSeries); return savedTimeSeries; @@ -100,7 +100,7 @@ public class TimeSeriesService { new Thread(() -> { try { httpService.post(TIME_SERIES_SAVE_SERVICE_URL, new JSONObject(new JsonTimeSeries(timeSeries))); - LOG.debug("Успешно отправлен на сервис"); + LOG.debug("{} успешно отправлен на сервис временных рядов", timeSeries.getName()); } catch (Exception ex) { LOG.debug(ex.getMessage()); } @@ -113,7 +113,7 @@ public class TimeSeriesService { public TimeSeries getById(Integer tsId) { return timeSeriesRepository.findById(tsId) - .orElseThrow(() -> new RuntimeException("Time series not found by id " + tsId)); + .orElseThrow(() -> new RuntimeException("Временной ряд не найден по идентификатору " + tsId)); } public List getAllTimeSeriesTypes() { -- 2.34.1 From 220854401efff37c955680e83d2c3de7051590d0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 20 Feb 2023 11:08:49 +0400 Subject: [PATCH 059/110] #92 -- Fix .git removing --- .../ru/ulstu/extractor/gitrepository/model/GitRepository.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java index da94301..652faf3 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java @@ -31,6 +31,8 @@ public class GitRepository extends BaseEntity { } private String removeDotGit(String prevName) { - return prevName.substring(0, prevName.lastIndexOf(".git")); + return prevName.lastIndexOf(".git") > 0 + ? prevName.substring(0, prevName.lastIndexOf(".git")) + : prevName; } } -- 2.34.1 From de6c83c2393542ecb1d78c177a492a83c7c768ee Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 20 Feb 2023 14:18:37 +0400 Subject: [PATCH 060/110] #92 -- Move id repository to model --- .../gitrepository/model/GitRepository.java | 23 +++++++++-------- .../gitrepository/service/GitApi.java | 2 ++ .../gitrepository/service/GitAtheneApi.java | 5 ++++ .../service/GitRepositoryService.java | 25 ++++++++++++++++--- .../gitrepository/service/GithubApi.java | 5 ++++ .../gitrepository/service/GitlabApi.java | 21 +++++++++------- .../gitrepository/service/IndexService.java | 4 --- .../ts/creator/scheduled/BranchTS.java | 11 +++++++- .../ts/creator/scheduled/IssuesTS.java | 13 ++++++++-- .../scheduled/ScheduledTimeSeriesCreator.java | 16 ++---------- .../ts/creator/scheduled/StarTS.java | 13 ++++++++-- .../ru/ulstu/extractor/util/StringUtils.java | 10 ++++++++ .../db/changelog-20221012_170000-schema.xml | 20 +++++++++++++++ 13 files changed, 122 insertions(+), 46 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java index 652faf3..f4707c7 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java @@ -1,18 +1,21 @@ package ru.ulstu.extractor.gitrepository.model; import ru.ulstu.extractor.core.BaseEntity; +import ru.ulstu.extractor.util.StringUtils; import javax.persistence.Entity; @Entity public class GitRepository extends BaseEntity { private String url; + private String repositoryId; public GitRepository() { } - public GitRepository(String repositoryUrl) { - url = repositoryUrl; + public GitRepository(String repositoryUrl, String repositoryId) { + this.url = repositoryUrl; + this.repositoryId = repositoryId; } public String getUrl() { @@ -23,16 +26,14 @@ public class GitRepository extends BaseEntity { this.url = url; } - public String getName() { - int lastDelimiterIndex = url.lastIndexOf("/"); - return (lastDelimiterIndex > 0 && lastDelimiterIndex < url.length()) - ? removeDotGit(url.substring(lastDelimiterIndex + 1)) - : removeDotGit(url); + public String getRepositoryId() { + return repositoryId; } - private String removeDotGit(String prevName) { - return prevName.lastIndexOf(".git") > 0 - ? prevName.substring(0, prevName.lastIndexOf(".git")) - : prevName; + public String getName() { + int lastDelimiterIndex = url.lastIndexOf("/"); + return StringUtils.removeDotGit((lastDelimiterIndex > 0 && lastDelimiterIndex < url.length()) + ? url.substring(lastDelimiterIndex + 1) + : url); } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java index 4be8736..33d3a14 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java @@ -12,4 +12,6 @@ public interface GitApi { String getFormattedUrl(Branch branch, String template); Integer getAuthorsCompletedIssues(Branch branch); + + String getRepositoryId(String repositoryUrl); } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java index d6644e1..b1fbf55 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java @@ -50,4 +50,9 @@ public class GitAtheneApi implements GitApi { .get(getFormattedUrl(branch, COMPLETED_ISSUES_URL)) .length(); } + + @Override + public String getRepositoryId(String repositoryUrl) { + return null; + } } 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 f6ead24..e400670 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java @@ -15,6 +15,7 @@ import org.eclipse.jgit.treewalk.TreeWalk; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationContext; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -29,6 +30,7 @@ import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit; import ru.ulstu.extractor.heuristic.model.EntityUnit; import ru.ulstu.extractor.heuristic.model.ResourceUnit; import ru.ulstu.extractor.heuristic.service.StructuralUnitService; +import ru.ulstu.extractor.util.StringUtils; import java.io.ByteArrayOutputStream; import java.io.File; @@ -55,7 +57,11 @@ import static org.apache.logging.log4j.util.Strings.isBlank; @Service public class GitRepositoryService { - private final static Logger LOG = LoggerFactory.getLogger(GitRepositoryService.class); + private final Map> gitApiServiceHolder = Map.of( + "git.athene.tech", GitAtheneApi.class, + "github.com", GithubApi.class, + "gitlab.com", GitlabApi.class); + private static final Logger LOG = LoggerFactory.getLogger(GitRepositoryService.class); private static final String BRANCH_PREFIX = "refs/remotes/origin/"; @Value("${extractor.custom-projects-dir}") private String customProjectsDir; @@ -63,11 +69,14 @@ public class GitRepositoryService { private final ExecutorService executorServiceCommits = Executors.newFixedThreadPool(8); private final StructuralUnitService structuralUnitService; private final GitRepositoryRepository gitRepositoryRepository; + private final ApplicationContext applicationContext; public GitRepositoryService(StructuralUnitService structuralUnitService, - GitRepositoryRepository gitRepositoryRepository) { + GitRepositoryRepository gitRepositoryRepository, + ApplicationContext applicationContext) { this.structuralUnitService = structuralUnitService; this.gitRepositoryRepository = gitRepositoryRepository; + this.applicationContext = applicationContext; } public List getRemoteBranches(String url) throws GitAPIException, IOException { @@ -430,8 +439,18 @@ public class GitRepositoryService { public GitRepository findByUrlOrCreate(String gitRepositoryUrl) { GitRepository gitRepository = gitRepositoryRepository.findByUrl(gitRepositoryUrl); + return gitRepository == null - ? gitRepositoryRepository.save(new GitRepository(gitRepositoryUrl)) + ? gitRepositoryRepository.save(new GitRepository(gitRepositoryUrl, + applicationContext.getBean(getGitApiServiceClass(gitRepositoryUrl)).getRepositoryId(gitRepositoryUrl))) : gitRepository; } + + public Class getGitApiServiceClass(Branch branch) { + return getGitApiServiceClass(branch.getGitRepository().getUrl()); + } + + public Class getGitApiServiceClass(String url) { + return gitApiServiceHolder.get(StringUtils.getServerDomain(url)); + } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java index e744bb7..717594f 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java @@ -50,4 +50,9 @@ public class GithubApi implements GitApi { .get(getFormattedUrl(branch, AUTHOR_COMPLETED_ISSUES_URL)) .length(); } + + @Override + public String getRepositoryId(String repositoryUrl) { + return null; + } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java index 60feab5..9f774a3 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java @@ -5,6 +5,9 @@ import org.springframework.stereotype.Service; import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.http.HttpService; +import static ru.ulstu.extractor.util.StringUtils.getUrlParts; +import static ru.ulstu.extractor.util.StringUtils.removeDotGit; + @Service public class GitlabApi implements GitApi { private final HttpService httpService; @@ -42,14 +45,14 @@ public class GitlabApi implements GitApi { @Override public String getFormattedUrl(Branch branch, String template) { - String[] urlParts = branch.getGitRepository().getUrl().split("/"); - return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], getProjectId(branch)); + String[] urlParts = getUrlParts(branch.getGitRepository().getUrl()); + return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], branch.getGitRepository().getRepositoryId()); } - public String getFormattedUrlForProjectId(Branch branch, String template) { - String[] urlParts = branch.getGitRepository().getUrl().split("/"); + public String getFormattedUrlForProjectId(String repositoryUrl, String template) { + String[] urlParts = getUrlParts(repositoryUrl); // получаем корректное название репозитория, gitlab всегда добавляет .git в конец - return String.format(template, urlParts[3], branch.getGitRepository().getName()); + return String.format(template, urlParts[3], removeDotGit(urlParts[4])); } @Override @@ -59,13 +62,13 @@ public class GitlabApi implements GitApi { .length(); } - private String getProjectId(Branch branch) { - JSONArray projects = httpService.get(getFormattedUrlForProjectId(branch, PROJECT_ID_URL)); + public String getRepositoryId(String repositoryUrl) { + JSONArray projects = httpService.get(getFormattedUrlForProjectId(repositoryUrl, PROJECT_ID_URL)); for (int i = 0; i < projects.length(); i++) { - if (projects.getJSONObject(i).get("name").equals(branch.getGitRepository().getName())) { + if (projects.getJSONObject(i).get("name").equals(removeDotGit(getUrlParts(repositoryUrl)[4]))) { return String.valueOf(projects.getJSONObject(i).getInt("id")); } } - throw new RuntimeException("Id проекта не найден: " + branch.getGitRepository().getName()); + throw new RuntimeException("Id проекта не найден: " + repositoryUrl); } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index 7921c21..6d43000 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -17,7 +17,6 @@ import ru.ulstu.extractor.branch.model.IndexingStatus; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.repository.GitRepositoryRepository; import ru.ulstu.extractor.ts.creator.db.DBTimeSeriesCreator; import java.io.IOException; @@ -31,17 +30,14 @@ public class IndexService { private final static Logger LOG = LoggerFactory.getLogger(IndexService.class); private final static int COMMITS_PAGE_SIZE = 10; private final GitRepositoryService gitRepositoryService; - private final GitRepositoryRepository gitRepositoryRepository; private final BranchService branchService; private final List timeSeriesCreators; private final static ExecutorService EXECUTOR = Executors.newFixedThreadPool(10); public IndexService(GitRepositoryService gitRepositoryService, - GitRepositoryRepository gitRepositoryRepository, BranchService branchService, List timeSeriesCreators) { this.gitRepositoryService = gitRepositoryService; - this.gitRepositoryRepository = gitRepositoryRepository; this.branchService = branchService; this.timeSeriesCreators = timeSeriesCreators; } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java index 81289db..2ae2510 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java @@ -3,6 +3,7 @@ package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -10,11 +11,14 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; @Component public class BranchTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; + private final GitRepositoryService gitRepositoryService; private final ApplicationContext applicationContext; public BranchTS(TimeSeriesService timeSeriesService, + GitRepositoryService gitRepositoryService, ApplicationContext applicationContext) { this.timeSeriesService = timeSeriesService; + this.gitRepositoryService = gitRepositoryService; this.applicationContext = applicationContext; } @@ -28,9 +32,14 @@ public class BranchTS extends ScheduledTimeSeriesCreator { return timeSeriesService; } + @Override + public GitRepositoryService getGitRepositoryService() { + return gitRepositoryService; + } + @Override public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) + return new TimeSeriesValue(applicationContext.getBean(getGitRepositoryService().getGitApiServiceClass(branch)) .getBranchesCount(branch)); } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java index 8d26648..4f9e9f6 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java @@ -3,6 +3,7 @@ package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -11,16 +12,19 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; public class IssuesTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final ApplicationContext applicationContext; + private final GitRepositoryService gitRepositoryService; public IssuesTS(TimeSeriesService timeSeriesService, - ApplicationContext applicationContext) { + ApplicationContext applicationContext, + GitRepositoryService gitRepositoryService) { this.timeSeriesService = timeSeriesService; this.applicationContext = applicationContext; + this.gitRepositoryService = gitRepositoryService; } @Override public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) + return new TimeSeriesValue(applicationContext.getBean(getGitRepositoryService().getGitApiServiceClass(branch)) .getOpenIssuesCount(branch)); } @@ -33,4 +37,9 @@ public class IssuesTS extends ScheduledTimeSeriesCreator { public TimeSeriesType getTimeSeriesType() { return TimeSeriesType.ISSUES; } + + @Override + public GitRepositoryService getGitRepositoryService() { + return gitRepositoryService; + } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java index 0bb3786..032bb40 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java @@ -2,24 +2,14 @@ package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.extractor.branch.model.Branch; -import ru.ulstu.extractor.gitrepository.service.GitApi; -import ru.ulstu.extractor.gitrepository.service.GitAtheneApi; -import ru.ulstu.extractor.gitrepository.service.GithubApi; -import ru.ulstu.extractor.gitrepository.service.GitlabApi; +import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesValue; -import ru.ulstu.extractor.util.StringUtils; import java.util.Collections; -import java.util.Map; public abstract class ScheduledTimeSeriesCreator extends AbstractTimeSeriesCreator { - private final Map> gitApiServiceHolder = Map.of( - "git.athene.tech", GitAtheneApi.class, - "github.com", GithubApi.class, - "gitlab.com", GitlabApi.class); - @Transactional public void addTimeSeriesValue(Branch branch) { TimeSeries timeSeries = getTimeSeriesService().findByBranchAndTypeOrCreate(branch, getTimeSeriesType()); @@ -29,7 +19,5 @@ public abstract class ScheduledTimeSeriesCreator extends AbstractTimeSeriesCreat public abstract TimeSeriesValue getNewTimeSeriesValue(Branch branch); - public Class getGitApiServiceClass(Branch branch) { - return gitApiServiceHolder.get(StringUtils.getServerDomain(branch.getGitRepository().getUrl())); - } + public abstract GitRepositoryService getGitRepositoryService(); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java index 27becfa..46f5f28 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java @@ -3,6 +3,7 @@ package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -11,11 +12,14 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; public class StarTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final ApplicationContext applicationContext; + private final GitRepositoryService gitRepositoryService; public StarTS(TimeSeriesService timeSeriesService, - ApplicationContext applicationContext) { + ApplicationContext applicationContext, + GitRepositoryService gitRepositoryService) { this.timeSeriesService = timeSeriesService; this.applicationContext = applicationContext; + this.gitRepositoryService = gitRepositoryService; } @Override @@ -28,9 +32,14 @@ public class StarTS extends ScheduledTimeSeriesCreator { return TimeSeriesType.STARS; } + @Override + public GitRepositoryService getGitRepositoryService() { + return gitRepositoryService; + } + @Override public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) + return new TimeSeriesValue(applicationContext.getBean(getGitRepositoryService().getGitApiServiceClass(branch)) .getStarsCount(branch)); } } diff --git a/src/main/java/ru/ulstu/extractor/util/StringUtils.java b/src/main/java/ru/ulstu/extractor/util/StringUtils.java index 9d137e5..0c57bcb 100644 --- a/src/main/java/ru/ulstu/extractor/util/StringUtils.java +++ b/src/main/java/ru/ulstu/extractor/util/StringUtils.java @@ -31,4 +31,14 @@ public class StringUtils { String[] urlParts = url.split("/"); return urlParts[2]; } + + public static String[] getUrlParts(String gitRepositoryUrl) { + return gitRepositoryUrl.split("/"); + } + + public static String removeDotGit(String repositoryName) { + return repositoryName.lastIndexOf(".git") > 0 + ? repositoryName.substring(0, repositoryName.lastIndexOf(".git")) + : repositoryName; + } } diff --git a/src/main/resources/db/changelog-20221012_170000-schema.xml b/src/main/resources/db/changelog-20221012_170000-schema.xml index 6ee4e83..6b8df1a 100644 --- a/src/main/resources/db/changelog-20221012_170000-schema.xml +++ b/src/main/resources/db/changelog-20221012_170000-schema.xml @@ -107,4 +107,24 @@ + + + + + + + + + + + + + \ No newline at end of file -- 2.34.1 From 1e69baea80c0779516da5586b9fc5b5d43dac8e5 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 20 Feb 2023 14:22:38 +0400 Subject: [PATCH 061/110] #92 -- Fix scheduled time --- .../ulstu/extractor/ts/service/ScheduledTimeSeriesService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java index 55aeae5..501184a 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java @@ -22,7 +22,7 @@ public class ScheduledTimeSeriesService { this.branchService = branchService; } - @Scheduled(cron = "0 0 * * * *", zone = "Europe/Samara") + @Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara") public void addTimeSeriesPoints() { log.debug("Старт добавления новых точек временного ряда"); List branches = branchService.findAll(); -- 2.34.1 From bc58d72481f94f8ec56b4741e5f8a3fb0ac89025 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 21 Feb 2023 14:43:27 +0400 Subject: [PATCH 062/110] #92 -- Fix .git removing for git --- .../ru/ulstu/extractor/gitrepository/service/GithubApi.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java index 717594f..b799474 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java @@ -3,6 +3,7 @@ package ru.ulstu.extractor.gitrepository.service; import org.springframework.stereotype.Service; import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.http.HttpService; +import ru.ulstu.extractor.util.StringUtils; @Service public class GithubApi implements GitApi { @@ -41,7 +42,7 @@ public class GithubApi implements GitApi { @Override public String getFormattedUrl(Branch branch, String template) { String[] urlParts = branch.getGitRepository().getUrl().split("/"); - return String.format(template, urlParts[3], urlParts[4]); + return String.format(template, urlParts[3], StringUtils.removeDotGit(urlParts[4])); } @Override -- 2.34.1 From d72cf99fa6c1c2f8fd2115cf50bf65b92fd351bb Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 21 Feb 2023 17:46:55 +0400 Subject: [PATCH 063/110] #92 -- Fix saving in transaction --- .../ru/ulstu/extractor/branch/service/BranchService.java | 7 ++++--- .../ru/ulstu/extractor/commit/service/CommitService.java | 8 -------- .../extractor/gitrepository/service/IndexService.java | 4 ++-- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java index cb8537e..e123a71 100644 --- a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java +++ b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java @@ -41,6 +41,7 @@ public class BranchService { @Transactional public Branch save(Branch branch, List commits) { LOG.debug("Start save {} branch with {} commits ", branch.getName(), commits.size()); + LOG.debug("Current branch contains {} commits ", branch.getCommits().size()); List commitsToRemoveIds = branch.getCommits().stream().map(BaseEntity::getId).collect(Collectors.toList()); branch.setCommits(commitService.save(commits)); LOG.debug("Save branch {} ", branch.getName()); @@ -50,12 +51,12 @@ public class BranchService { return branch; } + @Transactional public Branch addCommits(Branch branch, List commits) { LOG.debug("Start add commits to {} branch with {} commits ", branch.getName(), commits.size()); - commitService.save(commits); + branch.getCommits().addAll(commitService.save(commits)); LOG.debug("Save branch {} ", branch.getName()); - commitService.updateBranchId(commits, branch.getId()); - return branch; + return save(branch); } public Branch findByRepositoryAndName(GitRepository gitRepository, String branchName) { diff --git a/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java b/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java index df8d389..79aaa9b 100644 --- a/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java +++ b/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java @@ -44,14 +44,6 @@ public class CommitService { jdbcTemplate.update("DELETE FROM commit where branch_id is null"); } - public void updateBranchId(List commits, Integer branchId) { - List commitIds = commits.stream().map(c -> c.getId().toString()).collect(Collectors.toList()); - String updateQuery = "update commit set branch_id = ? where id in (%s)"; - updateQuery = String.format(updateQuery, String.join(",", commitIds)); - jdbcTemplate.update(updateQuery, branchId); - } - - public List findByRepositoryIdAndName(Integer repositoryId, String branchName) { return commitRepository.findByRepositoryIdAndBranchName(repositoryId, branchName); } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index 6d43000..7345254 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -74,9 +74,9 @@ public class IndexService { commitsTo += COMMITS_PAGE_SIZE; commits = gitRepositoryService.getCommits(gitRepository.getUrl(), branch.getName(), commitsFrom, commitsTo, false); } - final Branch branchForSave = branch; + branch = branchService.findByBranchId(branch.getId()).orElseThrow(() -> new RuntimeException("Branch not found by id")); + final Branch branchForSave = branchService.updateStatus(branch, IndexingStatus.FINISHED); timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(branchForSave)); - branchService.updateStatus(branch, IndexingStatus.FINISHED); LOG.debug("Complete indexing {} branch", branch.getName()); } -- 2.34.1 From 9d5672cdcf06054df77af702f270d15cb0f1bbef Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 21 Feb 2023 18:22:41 +0400 Subject: [PATCH 064/110] #91 -- Add markup page --- .../TimeSeriesMarkupController.java | 27 +++++++++++++++++++ src/main/resources/templates/markup.html | 24 +++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java create mode 100644 src/main/resources/templates/markup.html diff --git a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java new file mode 100644 index 0000000..5caad5c --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java @@ -0,0 +1,27 @@ +package ru.ulstu.extractor.ts.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.service.TimeSeriesService; +import springfox.documentation.annotations.ApiIgnore; + +import java.util.List; + +@Controller +@ApiIgnore +public class TimeSeriesMarkupController { + private final TimeSeriesService timeSeriesService; + + public TimeSeriesMarkupController(TimeSeriesService timeSeriesService) { + this.timeSeriesService = timeSeriesService; + } + + @GetMapping("time-series-markup") + public String markupTs(Model model) { + List ts = timeSeriesService.getAllTimeSeries(); + model.addAttribute("ts", ts); + return "markup"; + } +} diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html new file mode 100644 index 0000000..329d010 --- /dev/null +++ b/src/main/resources/templates/markup.html @@ -0,0 +1,24 @@ + + + + Простая обработка формы на Spring MVC + + +
+ + + + + + + + + + + + +
Разметка временных рядов
+
+ -- 2.34.1 From 9972f5e925bf0ca43c81ece6c948844c3d0c1393 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 22 Feb 2023 15:49:10 +0400 Subject: [PATCH 065/110] #92 -- Add api call --- .../extractor/gitrepository/service/IndexService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index 7345254..d8d1c1e 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -18,12 +18,11 @@ import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.creator.db.DBTimeSeriesCreator; +import ru.ulstu.extractor.ts.service.ScheduledTimeSeriesService; import java.io.IOException; import java.util.Collections; import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; @Service public class IndexService { @@ -32,14 +31,16 @@ public class IndexService { private final GitRepositoryService gitRepositoryService; private final BranchService branchService; private final List timeSeriesCreators; - private final static ExecutorService EXECUTOR = Executors.newFixedThreadPool(10); + private final ScheduledTimeSeriesService scheduledTimeSeriesService; public IndexService(GitRepositoryService gitRepositoryService, BranchService branchService, - List timeSeriesCreators) { + List timeSeriesCreators, + ScheduledTimeSeriesService scheduledTimeSeriesService) { this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; this.timeSeriesCreators = timeSeriesCreators; + this.scheduledTimeSeriesService = scheduledTimeSeriesService; } @Transactional @@ -78,6 +79,7 @@ public class IndexService { final Branch branchForSave = branchService.updateStatus(branch, IndexingStatus.FINISHED); timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(branchForSave)); LOG.debug("Complete indexing {} branch", branch.getName()); + scheduledTimeSeriesService.addTimeSeriesPoints(); } @Transactional -- 2.34.1 From 7ad962494a78c172168a0f9c738fb06c91e1d430 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 22 Feb 2023 15:59:32 +0400 Subject: [PATCH 066/110] #92 -- Restore --- .../extractor/gitrepository/service/IndexService.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index d8d1c1e..8e89f21 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -18,7 +18,6 @@ import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.creator.db.DBTimeSeriesCreator; -import ru.ulstu.extractor.ts.service.ScheduledTimeSeriesService; import java.io.IOException; import java.util.Collections; @@ -31,16 +30,13 @@ public class IndexService { private final GitRepositoryService gitRepositoryService; private final BranchService branchService; private final List timeSeriesCreators; - private final ScheduledTimeSeriesService scheduledTimeSeriesService; public IndexService(GitRepositoryService gitRepositoryService, BranchService branchService, - List timeSeriesCreators, - ScheduledTimeSeriesService scheduledTimeSeriesService) { + List timeSeriesCreators) { this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; this.timeSeriesCreators = timeSeriesCreators; - this.scheduledTimeSeriesService = scheduledTimeSeriesService; } @Transactional @@ -79,7 +75,6 @@ public class IndexService { final Branch branchForSave = branchService.updateStatus(branch, IndexingStatus.FINISHED); timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(branchForSave)); LOG.debug("Complete indexing {} branch", branch.getName()); - scheduledTimeSeriesService.addTimeSeriesPoints(); } @Transactional -- 2.34.1 From 4bd2f460467cbe85159ab8d095046e36fee91444 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 22 Feb 2023 22:31:53 +0400 Subject: [PATCH 067/110] #91 -- Add markup page menu item --- src/main/resources/templates/default.html | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 45c036d..e7c1cec 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -1,8 +1,3 @@ - - @@ -37,6 +32,9 @@
+ -- 2.34.1 From f08e5447fdf5ff571ad8ae822626c995d6c43329 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 22 Feb 2023 23:01:56 +0400 Subject: [PATCH 068/110] #91 -- Fix menu --- src/main/resources/templates/default.html | 6 +++--- src/main/resources/templates/listRepositories.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index e7c1cec..aa66144 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -33,13 +33,13 @@ Link
diff --git a/src/main/resources/templates/listRepositories.html b/src/main/resources/templates/listRepositories.html index 8e07b46..ab2ff08 100644 --- a/src/main/resources/templates/listRepositories.html +++ b/src/main/resources/templates/listRepositories.html @@ -19,7 +19,7 @@ + th:text="${repo.name}" th:title="${repo.url}"> -- 2.34.1 From a701f943eb677fd2c2b13f4c4d36e445e180b647 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 25 Feb 2023 11:30:08 +0400 Subject: [PATCH 069/110] #91 -- Fix mvc config --- src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java b/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java index d4f9a9c..a85543c 100644 --- a/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java +++ b/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java @@ -16,9 +16,7 @@ import static ru.ulstu.extractor.core.Route.LIST_INDEXED_REPOSITORIES; public class MvcConfiguration implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/{articlename:\\w+}"); registry.addRedirectViewController("/", LIST_INDEXED_REPOSITORIES); - registry.addRedirectViewController("/default", "/home"); } @Override -- 2.34.1 From 41b23570c03a9878522bdcbaa3e97f7955085ef3 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 25 Feb 2023 12:26:48 +0400 Subject: [PATCH 070/110] #91 -- Fix buttons --- .../resources/templates/listBranches.html | 29 ++++++++++--------- .../resources/templates/listRepositories.html | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/resources/templates/listBranches.html b/src/main/resources/templates/listBranches.html index a9cb074..db6d729 100644 --- a/src/main/resources/templates/listBranches.html +++ b/src/main/resources/templates/listBranches.html @@ -22,19 +22,22 @@ th:text="${branch.name}"> - - - - Индексируется... - - - - + diff --git a/src/main/resources/templates/listRepositories.html b/src/main/resources/templates/listRepositories.html index ab2ff08..8c9289b 100644 --- a/src/main/resources/templates/listRepositories.html +++ b/src/main/resources/templates/listRepositories.html @@ -21,7 +21,7 @@ - -- 2.34.1 From f4600c2ba5d144ca3b7de486fa780f86016df3a0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 27 Feb 2023 14:47:51 +0400 Subject: [PATCH 071/110] #91 -- Group ts tendencies --- .../controller/TimeSeriesMarkupController.java | 1 + .../ulstu/extractor/ts/model/TimeSeries.java | 12 ++++++++++++ .../extractor/ts/model/TimeSeriesValue.java | 13 +++++++++++++ .../ts/service/TimeSeriesService.java | 13 +++++++++++++ .../ru/ulstu/extractor/util/JsonUtils.java | 18 ++++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 src/main/java/ru/ulstu/extractor/util/JsonUtils.java diff --git a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java index 5caad5c..32674c5 100644 --- a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java @@ -22,6 +22,7 @@ public class TimeSeriesMarkupController { public String markupTs(Model model) { List ts = timeSeriesService.getAllTimeSeries(); model.addAttribute("ts", ts); + model.addAttribute("fts", timeSeriesService.getGroupedTendencies(ts.get(0))); return "markup"; } } 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 76abf70..34a2b4c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java @@ -2,6 +2,7 @@ package ru.ulstu.extractor.ts.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import org.json.JSONObject; import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.core.BaseEntity; @@ -15,6 +16,9 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; + +import static ru.ulstu.extractor.util.JsonUtils.getListOfObjects; @Entity public class TimeSeries extends BaseEntity { @@ -51,6 +55,14 @@ public class TimeSeries extends BaseEntity { this.branch = branch; } + public TimeSeries(JSONObject timeSeries) { + this.name = timeSeries.getString("name"); + this.values = getListOfObjects(timeSeries.getJSONArray("values")) + .stream() + .map(TimeSeriesValue::new) + .collect(Collectors.toList()); + } + public String getName() { return name; } diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java index 9b77f2a..e9ac965 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java @@ -1,8 +1,11 @@ package ru.ulstu.extractor.ts.model; +import org.json.JSONObject; import ru.ulstu.extractor.core.BaseEntity; import javax.persistence.Entity; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Date; @Entity @@ -28,6 +31,16 @@ public class TimeSeriesValue extends BaseEntity { this.value = value; } + public TimeSeriesValue(JSONObject jsonValue) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss"); + try { + this.date = formatter.parse(jsonValue.getString("date")); + } catch (ParseException e) { + e.printStackTrace(); + } + this.value = jsonValue.getDouble("value"); + } + public Date getDate() { return date; } 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 d5e12e6..1cdf4cc 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -36,6 +36,7 @@ public class TimeSeriesService { private final HttpService httpService; private final static String TIME_SERIES_SAVE_SERVICE_URL = "http://time-series.athene.tech/api/1.0/add-time-series?setKey=git-extractor"; private final static String TIME_SERIES_TENDENCY_URL = "http://time-series.athene.tech/api/1.0/getSpecificMethodSmoothed"; + private final static String TIME_SERIES_GROUPED_TENDENCIES_URL = "http://time-series.athene.tech/api/1.0/getGroupedTendencies"; public TimeSeriesService(TimeSeriesRepository timeSeriesRepository, TimeSeriesValueRepository timeSeriesValueRepository, @@ -136,4 +137,16 @@ public class TimeSeriesService { } return Optional.empty(); } + + public Optional getGroupedTendencies(TimeSeries ts) { + if (ts != null && ts.getValues().size() > 5) { + JSONObject response = httpService.post(TIME_SERIES_GROUPED_TENDENCIES_URL, new JSONObject(new JsonTimeSeries(ts))); + LOG.debug("Send to group time series tendencies"); + if (response.has("response") && response.getString("response").equals("empty")) { + return Optional.empty(); + } + return Optional.of(new TimeSeries(response)); + } + return Optional.empty(); + } } diff --git a/src/main/java/ru/ulstu/extractor/util/JsonUtils.java b/src/main/java/ru/ulstu/extractor/util/JsonUtils.java new file mode 100644 index 0000000..6ac8927 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/util/JsonUtils.java @@ -0,0 +1,18 @@ +package ru.ulstu.extractor.util; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class JsonUtils { + + public static List getListOfObjects(JSONArray jsonArray) { + List result = new ArrayList<>(); + for (int i = 0; i < jsonArray.length(); i++) { + result.add(jsonArray.getJSONObject(i)); + } + return result; + } +} -- 2.34.1 From 704366f11ada7b4bf027e18e56b1390f9db1dac9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 27 Feb 2023 23:35:31 +0400 Subject: [PATCH 072/110] #91 -- Group list of ts tendencies --- .../ru/ulstu/extractor/http/HttpService.java | 20 +++++++++++++++++++ .../TimeSeriesMarkupController.java | 2 +- .../ts/service/TimeSeriesService.java | 19 +++++++++--------- src/main/resources/templates/markup.html | 2 +- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/http/HttpService.java b/src/main/java/ru/ulstu/extractor/http/HttpService.java index 1e53488..97dd0df 100644 --- a/src/main/java/ru/ulstu/extractor/http/HttpService.java +++ b/src/main/java/ru/ulstu/extractor/http/HttpService.java @@ -41,6 +41,26 @@ public class HttpService { return response; } + public JSONArray post(String url, JSONArray postData) { + log.debug("Service call: {}", url); + JSONArray response = null; + try { + response = new JSONArray(Optional.ofNullable(client + .post() + .uri(url) + .contentType(MediaType.APPLICATION_JSON) + .body(BodyInserters.fromValue(postData.toString())) + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(String.class) + .toFuture().get()).orElse("[{response:\"empty\"}]")); + } catch (Exception e) { + return new JSONArray("[{response:\"empty\"}]"); + } + log.debug("Service response: {}", response); + return response; + } + public JSONArray get(String url) { log.debug("Service call: {}", url); try { diff --git a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java index 32674c5..fbe7493 100644 --- a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java @@ -22,7 +22,7 @@ public class TimeSeriesMarkupController { public String markupTs(Model model) { List ts = timeSeriesService.getAllTimeSeries(); model.addAttribute("ts", ts); - model.addAttribute("fts", timeSeriesService.getGroupedTendencies(ts.get(0))); + model.addAttribute("groupedTs", timeSeriesService.getGroupedTendencies(ts)); return "markup"; } } 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 1cdf4cc..dac66fe 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -20,12 +20,14 @@ import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.repository.TimeSeriesRepository; import ru.ulstu.extractor.ts.repository.TimeSeriesValueRepository; import ru.ulstu.extractor.ts.util.TimeSeriesDateMapper; +import ru.ulstu.extractor.util.JsonUtils; import javax.transaction.Transactional; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; @Service public class TimeSeriesService { @@ -138,15 +140,12 @@ public class TimeSeriesService { return Optional.empty(); } - public Optional getGroupedTendencies(TimeSeries ts) { - if (ts != null && ts.getValues().size() > 5) { - JSONObject response = httpService.post(TIME_SERIES_GROUPED_TENDENCIES_URL, new JSONObject(new JsonTimeSeries(ts))); - LOG.debug("Send to group time series tendencies"); - if (response.has("response") && response.getString("response").equals("empty")) { - return Optional.empty(); - } - return Optional.of(new TimeSeries(response)); - } - return Optional.empty(); + public List getGroupedTendencies(List tsList) { + JSONArray response = httpService.post(TIME_SERIES_GROUPED_TENDENCIES_URL, new JSONArray(tsList.stream().map(JsonTimeSeries::new).collect(Collectors.toList()))); + LOG.debug("Send to group time series tendencies"); + return JsonUtils.getListOfObjects(response) + .stream() + .map(TimeSeries::new) + .collect(Collectors.toList()); } } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 329d010..533e30a 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -14,7 +14,7 @@ - + -- 2.34.1 From ed68fa47f7a0c686836f438f8bd1d4ddeff55af0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 2 Mar 2023 21:02:10 +0400 Subject: [PATCH 073/110] #91 -- Add markup table --- .../TimeSeriesMarkupController.java | 2 +- .../ulstu/extractor/markup/model/Markup.java | 30 +++++++++++++++++++ .../db/changelog-20230302_210000-schema.xml | 23 ++++++++++++++ src/main/resources/db/changelog-master.xml | 1 + 4 files changed, 55 insertions(+), 1 deletion(-) rename src/main/java/ru/ulstu/extractor/{ts => markup}/controller/TimeSeriesMarkupController.java (95%) create mode 100644 src/main/java/ru/ulstu/extractor/markup/model/Markup.java create mode 100644 src/main/resources/db/changelog-20230302_210000-schema.xml diff --git a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java similarity index 95% rename from src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java rename to src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index fbe7493..d9571a8 100644 --- a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.controller; +package ru.ulstu.extractor.markup.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; diff --git a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java new file mode 100644 index 0000000..84c6d80 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java @@ -0,0 +1,30 @@ +package ru.ulstu.extractor.markup.model; + +import ru.ulstu.extractor.core.BaseEntity; +import ru.ulstu.extractor.ts.model.TimeSeries; + +import javax.persistence.Entity; +import javax.persistence.ManyToOne; + +@Entity +public class Markup extends BaseEntity { + @ManyToOne + private TimeSeries timeSeries; + private String markup; + + public TimeSeries getTimeSeries() { + return timeSeries; + } + + public void setTimeSeries(TimeSeries timeSeries) { + this.timeSeries = timeSeries; + } + + public String getMarkup() { + return markup; + } + + public void setMarkup(String markup) { + this.markup = markup; + } +} \ No newline at end of file diff --git a/src/main/resources/db/changelog-20230302_210000-schema.xml b/src/main/resources/db/changelog-20230302_210000-schema.xml new file mode 100644 index 0000000..7ccb661 --- /dev/null +++ b/src/main/resources/db/changelog-20230302_210000-schema.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index dfde9f7..aa59e26 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -15,4 +15,5 @@ + -- 2.34.1 From 0883c5193bb35934a2090de0154a0e8b694dc3fc Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 2 Mar 2023 22:03:29 +0400 Subject: [PATCH 074/110] #91 -- Add dtos --- .../java/ru/ulstu/extractor/core/Route.java | 5 ++++ .../TimeSeriesMarkupController.java | 15 ++++++++-- .../extractor/markup/model/MarkupForm.java | 15 ++++++++++ .../extractor/markup/model/MarkupRow.java | 28 +++++++++++++++++++ src/main/resources/templates/markup.html | 28 ++++++++++--------- 5 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java create mode 100644 src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java diff --git a/src/main/java/ru/ulstu/extractor/core/Route.java b/src/main/java/ru/ulstu/extractor/core/Route.java index be9cb53..e1605e7 100644 --- a/src/main/java/ru/ulstu/extractor/core/Route.java +++ b/src/main/java/ru/ulstu/extractor/core/Route.java @@ -21,6 +21,7 @@ public class Route { public static final String ADD_RULE = "addRule"; public static final String ASSESSMENTS = "assessments"; public static final String DELETE_RULE = "deleteRule"; + public static final String ADD_MARKUP = "addMarkup"; public static String getLIST_INDEXED_REPOSITORIES() { return LIST_INDEXED_REPOSITORIES; @@ -45,4 +46,8 @@ public class Route { public static String getASSESSMENTS() { return ASSESSMENTS; } + + public static String getADD_MARKUP() { + return ADD_MARKUP; + } } diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index d9571a8..c816987 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -3,11 +3,16 @@ package ru.ulstu.extractor.markup.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import ru.ulstu.extractor.markup.model.MarkupForm; +import ru.ulstu.extractor.markup.model.MarkupRow; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; import java.util.List; +import java.util.stream.Collectors; @Controller @ApiIgnore @@ -20,9 +25,13 @@ public class TimeSeriesMarkupController { @GetMapping("time-series-markup") public String markupTs(Model model) { - List ts = timeSeriesService.getAllTimeSeries(); - model.addAttribute("ts", ts); - model.addAttribute("groupedTs", timeSeriesService.getGroupedTendencies(ts)); + List tss = timeSeriesService.getAllTimeSeries(); + model.addAttribute("markupForm", new MarkupForm(tss.stream().map(MarkupRow::new).collect(Collectors.toList()))); + return "markup"; + } + + @PostMapping("addMarkups") + public String addMarkups(@RequestBody MarkupForm markupForm) { return "markup"; } } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java new file mode 100644 index 0000000..987103a --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java @@ -0,0 +1,15 @@ +package ru.ulstu.extractor.markup.model; + +import java.util.List; + +public class MarkupForm { + private List markupRows; + + public MarkupForm(List markupRows) { + this.markupRows = markupRows; + } + + public List getMarkupRows() { + return markupRows; + } +} diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java new file mode 100644 index 0000000..f62640e --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java @@ -0,0 +1,28 @@ +package ru.ulstu.extractor.markup.model; + +import ru.ulstu.extractor.ts.model.TimeSeries; + +public class MarkupRow { + private TimeSeries timeSeries; + private String markup; + + public MarkupRow(TimeSeries ts) { + this.timeSeries = ts; + } + + public TimeSeries getTimeSeries() { + return timeSeries; + } + + public void setTimeSeries(TimeSeries timeSeries) { + this.timeSeries = timeSeries; + } + + public String getMarkup() { + return markup; + } + + public void setMarkup(String markup) { + this.markup = markup; + } +} diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 533e30a..3579887 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -7,18 +7,20 @@
- - - - - - - - - - - - -
Разметка временных рядов
+
+ + + + + + + + + + + + +
Разметка временных рядов
+
-- 2.34.1 From 0239b0afd479e8f59ba4b704dd369c04fdb36ff9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 3 Mar 2023 10:44:26 +0400 Subject: [PATCH 075/110] #91 -- Add save operation --- .../TimeSeriesMarkupController.java | 14 ++++++++++---- .../ulstu/extractor/markup/model/Markup.java | 8 ++++++++ .../extractor/markup/model/MarkupForm.java | 4 ++++ .../markup/repository/MarkupRepository.java | 7 +++++++ .../markup/service/MarkupService.java | 19 +++++++++++++++++++ src/main/resources/templates/markup.html | 3 ++- 6 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java create mode 100644 src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index c816987..9eeab36 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -3,10 +3,12 @@ package ru.ulstu.extractor.markup.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; +import ru.ulstu.extractor.core.Route; import ru.ulstu.extractor.markup.model.MarkupForm; import ru.ulstu.extractor.markup.model.MarkupRow; +import ru.ulstu.extractor.markup.service.MarkupService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; @@ -18,9 +20,12 @@ import java.util.stream.Collectors; @ApiIgnore public class TimeSeriesMarkupController { private final TimeSeriesService timeSeriesService; + private final MarkupService markupService; - public TimeSeriesMarkupController(TimeSeriesService timeSeriesService) { + public TimeSeriesMarkupController(TimeSeriesService timeSeriesService, + MarkupService markupService) { this.timeSeriesService = timeSeriesService; + this.markupService = markupService; } @GetMapping("time-series-markup") @@ -30,8 +35,9 @@ public class TimeSeriesMarkupController { return "markup"; } - @PostMapping("addMarkups") - public String addMarkups(@RequestBody MarkupForm markupForm) { + @PostMapping(Route.ADD_MARKUP) + public String addMarkups(@ModelAttribute MarkupForm markupForm) { + markupService.saveMarkup(markupForm); return "markup"; } } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java index 84c6d80..0117bc8 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java @@ -12,6 +12,14 @@ public class Markup extends BaseEntity { private TimeSeries timeSeries; private String markup; + public Markup() { + } + + public Markup(MarkupRow markupRow) { + this.timeSeries = markupRow.getTimeSeries(); + this.markup = markupRow.getMarkup(); + } + public TimeSeries getTimeSeries() { return timeSeries; } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java index 987103a..e197b6b 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java @@ -12,4 +12,8 @@ public class MarkupForm { public List getMarkupRows() { return markupRows; } + + public void setMarkupRows(List markupRows) { + this.markupRows = markupRows; + } } diff --git a/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java b/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java new file mode 100644 index 0000000..0d149f1 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.extractor.markup.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.extractor.markup.model.Markup; + +public interface MarkupRepository extends JpaRepository { +} diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java new file mode 100644 index 0000000..266240c --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -0,0 +1,19 @@ +package ru.ulstu.extractor.markup.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.markup.model.Markup; +import ru.ulstu.extractor.markup.model.MarkupForm; +import ru.ulstu.extractor.markup.repository.MarkupRepository; + +@Service +public class MarkupService { + private final MarkupRepository markupRepository; + + public MarkupService(MarkupRepository markupRepository) { + this.markupRepository = markupRepository; + } + + public void saveMarkup(MarkupForm markupForm) { + markupForm.getMarkupRows().forEach(markupRow -> markupRepository.save(new Markup(markupRow))); + } +} diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 3579887..6417ba2 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -7,7 +7,7 @@
-
+ @@ -21,6 +21,7 @@
+
-- 2.34.1 From 211a8b004c8d1cf47cd63ba30904e12cc75838fa Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 3 Mar 2023 11:10:35 +0400 Subject: [PATCH 076/110] #91 -- Add get markups form --- .../ulstu/extractor/GitExtractorApplication.java | 1 - .../controller/TimeSeriesMarkupController.java | 2 +- .../ulstu/extractor/markup/model/MarkupForm.java | 6 +++++- .../ru/ulstu/extractor/markup/model/MarkupRow.java | 3 +++ src/main/resources/templates/markup.html | 14 ++++++++------ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java index 1cf7928..8491e6c 100644 --- a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java +++ b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java @@ -26,5 +26,4 @@ public class GitExtractorApplication { public void doSomethingAfterStartup() { indexService.indexFailedBranchesOnStart(); } - } diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index 9eeab36..0c1600c 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -31,7 +31,7 @@ public class TimeSeriesMarkupController { @GetMapping("time-series-markup") public String markupTs(Model model) { List tss = timeSeriesService.getAllTimeSeries(); - model.addAttribute("markupForm", new MarkupForm(tss.stream().map(MarkupRow::new).collect(Collectors.toList()))); + model.addAttribute("markupForm", new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList()))); return "markup"; } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java index e197b6b..b81a110 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java @@ -1,9 +1,13 @@ package ru.ulstu.extractor.markup.model; +import java.util.ArrayList; import java.util.List; public class MarkupForm { - private List markupRows; + private List markupRows = new ArrayList<>(); + + public MarkupForm() { + } public MarkupForm(List markupRows) { this.markupRows = markupRows; diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java index f62640e..3989a6f 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java @@ -6,6 +6,9 @@ public class MarkupRow { private TimeSeries timeSeries; private String markup; + public MarkupRow() { + } + public MarkupRow(TimeSeries ts) { this.timeSeries = ts; } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 6417ba2..b2b1d4e 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -7,21 +7,23 @@
-
+ - + - - - + + + +
Разметка временных рядовРазметка временных рядов
- +
-- 2.34.1 From d7790dff700c3e0a1c1ff96ac03f0f1e51365c63 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 7 Mar 2023 16:59:17 +0400 Subject: [PATCH 077/110] #91 -- Save markup --- .../TimeSeriesMarkupController.java | 35 ++++++++++++++++--- .../ulstu/extractor/markup/model/Markup.java | 6 ++-- .../extractor/markup/model/MarkupForm.java | 27 ++++++++++++++ .../markup/service/MarkupService.java | 14 ++++++-- src/main/resources/templates/markup.html | 25 +++++++++++++ 5 files changed, 98 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index 0c1600c..0672544 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -5,6 +5,7 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; +import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.core.Route; import ru.ulstu.extractor.markup.model.MarkupForm; import ru.ulstu.extractor.markup.model.MarkupRow; @@ -20,24 +21,50 @@ import java.util.stream.Collectors; @ApiIgnore public class TimeSeriesMarkupController { private final TimeSeriesService timeSeriesService; + private final BranchService branchService; private final MarkupService markupService; public TimeSeriesMarkupController(TimeSeriesService timeSeriesService, + BranchService branchService, MarkupService markupService) { this.timeSeriesService = timeSeriesService; + this.branchService = branchService; this.markupService = markupService; } @GetMapping("time-series-markup") public String markupTs(Model model) { - List tss = timeSeriesService.getAllTimeSeries(); - model.addAttribute("markupForm", new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList()))); + model.addAttribute("branches", branchService.findAll()); + model.addAttribute("markupForm", new MarkupForm()); + return "markup"; + } + + @PostMapping("time-series-markup") + public String filter(Model model, @ModelAttribute MarkupForm markupForm) { + model.addAttribute("branches", branchService.findAll()); + if (markupForm != null && markupForm.getBranchId() != null) { + List tss = timeSeriesService.getByBranch(markupForm.getBranchId()); + MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList())); + markupFormWithTs.setBranchId(markupForm.getBranchId()); + model.addAttribute("markupForm", markupFormWithTs); + } else { + model.addAttribute("markupForm", new MarkupForm()); + } return "markup"; } @PostMapping(Route.ADD_MARKUP) - public String addMarkups(@ModelAttribute MarkupForm markupForm) { - markupService.saveMarkup(markupForm); + public String addMarkups(Model model, @ModelAttribute MarkupForm markupForm) { + model.addAttribute("branches", branchService.findAll()); + if (markupForm.getBranchId() != null) { + List tss = timeSeriesService.getByBranch(markupForm.getBranchId()); + MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList())); + markupFormWithTs.setBranchId(markupForm.getBranchId()); + model.addAttribute("markupForm", markupFormWithTs); + if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) { + markupService.saveMarkup(markupForm); + } + } return "markup"; } } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java index 0117bc8..f119e41 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java @@ -15,9 +15,9 @@ public class Markup extends BaseEntity { public Markup() { } - public Markup(MarkupRow markupRow) { - this.timeSeries = markupRow.getTimeSeries(); - this.markup = markupRow.getMarkup(); + public Markup(TimeSeries timeSeries, String markup) { + this.timeSeries = timeSeries; + this.markup = markup; } public TimeSeries getTimeSeries() { diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java index b81a110..c07c837 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java @@ -5,6 +5,9 @@ import java.util.List; public class MarkupForm { private List markupRows = new ArrayList<>(); + private Integer branchId; + private boolean save; + private boolean filter; public MarkupForm() { } @@ -20,4 +23,28 @@ public class MarkupForm { public void setMarkupRows(List markupRows) { this.markupRows = markupRows; } + + public Integer getBranchId() { + return branchId; + } + + public void setBranchId(Integer branchId) { + this.branchId = branchId; + } + + public boolean isSave() { + return save; + } + + public void setSave(boolean save) { + this.save = save; + } + + public boolean isFilter() { + return filter; + } + + public void setFilter(boolean filter) { + this.filter = filter; + } } diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index 266240c..ae3e35f 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -1,19 +1,29 @@ package ru.ulstu.extractor.markup.service; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import ru.ulstu.extractor.markup.model.Markup; import ru.ulstu.extractor.markup.model.MarkupForm; import ru.ulstu.extractor.markup.repository.MarkupRepository; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.service.TimeSeriesService; @Service public class MarkupService { private final MarkupRepository markupRepository; + private final TimeSeriesService timeSeriesService; - public MarkupService(MarkupRepository markupRepository) { + public MarkupService(MarkupRepository markupRepository, + TimeSeriesService timeSeriesService) { this.markupRepository = markupRepository; + this.timeSeriesService = timeSeriesService; } + @Transactional public void saveMarkup(MarkupForm markupForm) { - markupForm.getMarkupRows().forEach(markupRow -> markupRepository.save(new Markup(markupRow))); + markupForm.getMarkupRows().forEach(markupRow -> { + TimeSeries timeSeries = timeSeriesService.getById(markupRow.getTimeSeries().getId()); + markupRepository.save(new Markup(timeSeries, markupRow.getMarkup())); + }); } } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index b2b1d4e..c0c98a7 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -8,6 +8,31 @@
+
+
+ Репозиторий-ветка +
+
+ + +
+
+ +
+
-- 2.34.1 From 71652c7b79225bcef75d5fa5c7433334a3c1c8c9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 11 Mar 2023 00:55:43 +0400 Subject: [PATCH 078/110] #91 -- Add some rule generator --- .../extractor/GitExtractorApplication.java | 6 ++- .../assessment/service/AssessmentService.java | 3 +- .../markup/service/MarkupService.java | 6 +++ .../extractor/rule/model/AntecedentValue.java | 3 +- .../repository/AntecedentValueRepository.java | 3 ++ .../rule/service/AntecedentValueService.java | 5 ++ .../extractor/rule/service/DbRuleService.java | 48 +++++++++++++++++-- 7 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java index 8491e6c..95e1008 100644 --- a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java +++ b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java @@ -7,15 +7,18 @@ import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import ru.ulstu.extractor.gitrepository.service.IndexService; +import ru.ulstu.extractor.rule.service.DbRuleService; @SpringBootApplication @EnableScheduling @EnableAsync public class GitExtractorApplication { private final IndexService indexService; + private final DbRuleService dbRuleService; - public GitExtractorApplication(IndexService indexService) { + public GitExtractorApplication(IndexService indexService, DbRuleService dbRuleService) { this.indexService = indexService; + this.dbRuleService = dbRuleService; } public static void main(String[] args) { @@ -25,5 +28,6 @@ public class GitExtractorApplication { @EventListener(ApplicationReadyEvent.class) public void doSomethingAfterStartup() { indexService.indexFailedBranchesOnStart(); + //dbRuleService.generateRulesFromMarkup(); } } diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index d221806..2514e6a 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -71,8 +71,9 @@ public class AssessmentService { Map variableValues = new HashMap<>(); timeSeries .stream() - .filter(ts -> ts.getTimeSeriesType() == dbRule.getFirstAntecedent() + .filter(ts -> (ts.getTimeSeriesType() == dbRule.getFirstAntecedent() || ts.getTimeSeriesType() == dbRule.getSecondAntecedent()) + && ts.getValues().size() > 0) .forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService .getLastTimeSeriesTendency(ts) .orElse(ts.getValues().get(ts.getValues().size() - 1).getValue()))); diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index ae3e35f..c4d3fd3 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -8,6 +8,8 @@ import ru.ulstu.extractor.markup.repository.MarkupRepository; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.service.TimeSeriesService; +import java.util.List; + @Service public class MarkupService { private final MarkupRepository markupRepository; @@ -26,4 +28,8 @@ public class MarkupService { markupRepository.save(new Markup(timeSeries, markupRow.getMarkup())); }); } + + public List findAll() { + return markupRepository.findAll(); + } } diff --git a/src/main/java/ru/ulstu/extractor/rule/model/AntecedentValue.java b/src/main/java/ru/ulstu/extractor/rule/model/AntecedentValue.java index 3583e6a..39b5eb6 100644 --- a/src/main/java/ru/ulstu/extractor/rule/model/AntecedentValue.java +++ b/src/main/java/ru/ulstu/extractor/rule/model/AntecedentValue.java @@ -11,8 +11,7 @@ public class AntecedentValue extends BaseEntity { public AntecedentValue() { } - public AntecedentValue(Integer id, String antecedentValue) { - this.setId(id); + public AntecedentValue(String antecedentValue) { this.antecedentValue = antecedentValue; } diff --git a/src/main/java/ru/ulstu/extractor/rule/repository/AntecedentValueRepository.java b/src/main/java/ru/ulstu/extractor/rule/repository/AntecedentValueRepository.java index 1ea84d7..3ae5795 100644 --- a/src/main/java/ru/ulstu/extractor/rule/repository/AntecedentValueRepository.java +++ b/src/main/java/ru/ulstu/extractor/rule/repository/AntecedentValueRepository.java @@ -4,5 +4,8 @@ package ru.ulstu.extractor.rule.repository; import org.springframework.data.jpa.repository.JpaRepository; import ru.ulstu.extractor.rule.model.AntecedentValue; +import java.util.Optional; + public interface AntecedentValueRepository extends JpaRepository { + Optional findByAntecedentValue(String antecedentValue); } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/AntecedentValueService.java b/src/main/java/ru/ulstu/extractor/rule/service/AntecedentValueService.java index ef3c124..8de502a 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/AntecedentValueService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/AntecedentValueService.java @@ -22,4 +22,9 @@ public class AntecedentValueService { return antecedentValueRepository.findById(antecedentValueId) .orElseThrow(() -> new RuntimeException("Antecedent value not found by id " + antecedentValueId)); } + + public AntecedentValue getByValue(String antecedentValue) { + return antecedentValueRepository.findByAntecedentValue(antecedentValue) + .orElseThrow(() -> new RuntimeException("Antecedent value not found by value " + antecedentValue)); + } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java index 198d486..c0a2dc5 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java @@ -1,10 +1,15 @@ package ru.ulstu.extractor.rule.service; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.extractor.markup.model.Markup; +import ru.ulstu.extractor.markup.service.MarkupService; import ru.ulstu.extractor.rule.model.AddRuleForm; +import ru.ulstu.extractor.rule.model.AntecedentValue; import ru.ulstu.extractor.rule.model.DbRule; import ru.ulstu.extractor.rule.repository.RuleRepository; import ru.ulstu.extractor.ts.model.TimeSeriesType; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.List; @@ -13,15 +18,16 @@ import java.util.stream.Collectors; @Service public class DbRuleService { private final RuleRepository ruleRepository; - private final TimeSeriesService timeSeriesService; private final AntecedentValueService antecedentValueService; + private final MarkupService markupService; public DbRuleService(RuleRepository ruleRepository, TimeSeriesService timeSeriesService, - AntecedentValueService antecedentValueService) { + AntecedentValueService antecedentValueService, + MarkupService markupService) { this.ruleRepository = ruleRepository; - this.timeSeriesService = timeSeriesService; this.antecedentValueService = antecedentValueService; + this.markupService = markupService; } public List getList() { @@ -65,4 +71,40 @@ public class DbRuleService { public List getConsequentList() { return ruleRepository.findAll().stream().map(DbRule::getConsequent).collect(Collectors.toList()); } + + @Transactional + public void generateRulesFromMarkup() { + List markups = markupService.findAll(); + for (Markup markup1 : markups) { + for (Markup markup2 : markups) { + if (!markup1.equals(markup2)) { + List values1 = markup1.getTimeSeries().getValues(); + for (int i = 1; i < values1.size(); i++) { + List values2 = markup2.getTimeSeries().getValues(); + for (int j = 1; j < values2.size(); j++) { + ruleRepository.save(new DbRule( + getAntecedent(values1.get(i).getValue() - values1.get(i - 1).getValue()), + markup1.getTimeSeries().getTimeSeriesType(), + getAntecedent(values2.get(j).getValue() - values2.get(j - 1).getValue()), + markup2.getTimeSeries().getTimeSeriesType(), + "сгенерированный консеквент" + )); + } + } + } + } + } + } + + private AntecedentValue getAntecedent(Double diff) { + String antecedentValue; + if (diff < 0) { + antecedentValue = "спад"; + } else if (diff > 0) { + antecedentValue = "рост"; + } else { + antecedentValue = "стабильно"; + } + return antecedentValueService.getByValue(antecedentValue); + } } -- 2.34.1 From 80904e622148e740e0d09fd6fbf0730776fde1f5 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 14 Mar 2023 23:20:57 +0400 Subject: [PATCH 079/110] #91 -- Restore --- .../ulstu/extractor/assessment/service/AssessmentService.java | 3 +-- .../ru/ulstu/extractor/rule/controller/RuleController.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index 2514e6a..d221806 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -71,9 +71,8 @@ public class AssessmentService { Map variableValues = new HashMap<>(); timeSeries .stream() - .filter(ts -> (ts.getTimeSeriesType() == dbRule.getFirstAntecedent() + .filter(ts -> ts.getTimeSeriesType() == dbRule.getFirstAntecedent() || ts.getTimeSeriesType() == dbRule.getSecondAntecedent()) - && ts.getValues().size() > 0) .forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService .getLastTimeSeriesTendency(ts) .orElse(ts.getValues().get(ts.getValues().size() - 1).getValue()))); diff --git a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java index 4e855df..a9a8258 100644 --- a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java @@ -54,7 +54,7 @@ public class RuleController { } @GetMapping(DELETE_RULE) - public String deleteRule(Model model, @RequestParam Integer id) { + public String deleteRule(@RequestParam Integer id) { ruleService.deleteById(id); return "redirect:/" + LIST_RULE; } -- 2.34.1 From 9e431757044345632f7c6710d7281619bca1aca1 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 15 Mar 2023 14:18:23 +0400 Subject: [PATCH 080/110] #80 -- Add validation --- .../controller/AssessmentController.java | 2 +- .../assessment/service/AssessmentService.java | 7 ++----- .../branch/service/BranchService.java | 13 +++++++++++- .../ts/service/TimeSeriesService.java | 20 ++++++++++++++----- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java b/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java index 3434377..e5721fa 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java +++ b/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java @@ -27,7 +27,7 @@ public class AssessmentController { @GetMapping(ASSESSMENTS) public String getAssessments(Model model, @RequestParam Optional branchId) { - model.addAttribute("branches", branchService.findAll()); + model.addAttribute("branches", branchService.findAllValid()); if (branchId.isPresent()) { model.addAttribute("assessments", assessmentService.getAssessmentsByForecastTendencies(branchId.get())); model.addAttribute("filterBranchForm", new FilterBranchForm(branchId.get())); diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index d221806..e1a2020 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -54,9 +54,7 @@ public class AssessmentService { private List getSingleAssessmentByTimeSeriesTendencies(List dbRules, List timeSeries) throws AssessmentException { Map variableValues = new HashMap<>(); - timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), - timeSeriesService.getLastTimeSeriesTendency(ts) - .orElseThrow(() -> new AssessmentException("")))); + timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService.getLastTimeSeriesTendency(ts))); return fuzzyInferenceService.getFuzzyInference(dbRules, antecedentValueService.getList(), variableValues, @@ -74,8 +72,7 @@ public class AssessmentService { .filter(ts -> ts.getTimeSeriesType() == dbRule.getFirstAntecedent() || ts.getTimeSeriesType() == dbRule.getSecondAntecedent()) .forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService - .getLastTimeSeriesTendency(ts) - .orElse(ts.getValues().get(ts.getValues().size() - 1).getValue()))); + .getLastTimeSeriesTendency(ts))); return fuzzyInferenceService.getFuzzyInference(List.of(dbRule), antecedentValueService.getList(), variableValues, diff --git a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java index e123a71..0684ed4 100644 --- a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java +++ b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java @@ -16,6 +16,7 @@ import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.core.BaseEntity; import ru.ulstu.extractor.gitrepository.model.GitRepository; +import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.List; import java.util.Optional; @@ -26,11 +27,14 @@ public class BranchService { private final static Logger LOG = LoggerFactory.getLogger(BranchService.class); private final BranchRepository branchRepository; private final CommitService commitService; + private final TimeSeriesService timeSeriesService; public BranchService(BranchRepository branchRepository, - CommitService commitService) { + CommitService commitService, + TimeSeriesService timeSeriesService) { this.branchRepository = branchRepository; this.commitService = commitService; + this.timeSeriesService = timeSeriesService; } @Transactional @@ -87,4 +91,11 @@ public class BranchService { branch.setIndexingStatus(indexingStatus); return branchRepository.save(branch); } + + public List findAllValid() { + return findAll() + .stream() + .filter(timeSeriesService::isBranchContainsAllTimeSeries) + .collect(Collectors.toList()); + } } 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 d5e12e6..234757f 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -26,10 +26,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.stream.Stream; @Service public class TimeSeriesService { private final static Logger LOG = LoggerFactory.getLogger(TimeSeriesService.class); + private final static int MIN_TIME_SERIES_LENGTH = 5; + private final static double DEFAULT_TIME_SERIES_TENDENCY = 0.0; private final TimeSeriesRepository timeSeriesRepository; private final TimeSeriesValueRepository timeSeriesValueRepository; private final TimeSeriesDateMapper.TimeSeriesInterval timeSeriesInterval = TimeSeriesDateMapper.TimeSeriesInterval.HOUR; @@ -124,16 +127,23 @@ public class TimeSeriesService { return timeSeriesRepository.getTimeSeriesByBranchId(branchId); } - public Optional getLastTimeSeriesTendency(TimeSeries ts) { - if (ts != null && ts.getValues().size() > 5) { + public double getLastTimeSeriesTendency(TimeSeries ts) { + if (ts != null && ts.getValues().size() > MIN_TIME_SERIES_LENGTH) { JSONObject response = httpService.post(TIME_SERIES_TENDENCY_URL, new JSONObject(new SmoothingTimeSeries(ts))); LOG.debug("Успешно отправлен на сервис сглаживания"); if (response.has("response") && response.getString("response").equals("empty")) { - return Optional.empty(); + return DEFAULT_TIME_SERIES_TENDENCY; } JSONArray jsonArray = response.getJSONObject("timeSeries").getJSONArray("values"); - return Optional.of(jsonArray.getJSONObject(jsonArray.length() - 1).getDouble("value")); + return jsonArray.getJSONObject(jsonArray.length() - 1).getDouble("value"); } - return Optional.empty(); + return DEFAULT_TIME_SERIES_TENDENCY; + } + + public boolean isBranchContainsAllTimeSeries(Branch b) { + List timeSeries = getByBranch(b.getId()); + return Stream.of(TimeSeriesType.values()).allMatch(type -> timeSeries + .stream() + .anyMatch(ts -> type == ts.getTimeSeriesType())); } } -- 2.34.1 From 394873f63b31287aa1a48932cbc64d6e6402bfec Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 15 Mar 2023 14:21:37 +0400 Subject: [PATCH 081/110] #91 -- Remove copyright --- .../ru/ulstu/extractor/ts/service/TimeSeriesService.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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 1067649..5d48ae7 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.ts.service; import org.json.JSONArray; @@ -27,8 +22,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.stream.Stream; import java.util.stream.Collectors; +import java.util.stream.Stream; @Service public class TimeSeriesService { -- 2.34.1 From ddedfc97515ca08d36af264b8f4724146c506154 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 15 Mar 2023 14:36:47 +0400 Subject: [PATCH 082/110] #91 -- Fix form --- src/main/resources/templates/assessments.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/resources/templates/assessments.html b/src/main/resources/templates/assessments.html index a303e2d..8a8c7f7 100644 --- a/src/main/resources/templates/assessments.html +++ b/src/main/resources/templates/assessments.html @@ -31,8 +31,6 @@
Выбрерите ветку для получения оценки репозитория
- -
Состояние репозитория описывается следующими выражениями:
-- 2.34.1 From d111121e2437d39cc8d2841693c15456e8caa1cb Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 16 Mar 2023 23:09:04 +0400 Subject: [PATCH 083/110] #91 -- Use new models --- .../TimeSeriesMarkupController.java | 36 ++++++++------- .../extractor/markup/model/MarkupForm.java | 33 ++++---------- .../markup/model/TimeSeriesForMarkup.java | 44 +++++++++++++++++++ .../markup/service/MarkupService.java | 41 +++++++++++++++-- src/main/resources/templates/markup.html | 12 ++--- 5 files changed, 115 insertions(+), 51 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index 0672544..94d1ec4 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -8,14 +8,12 @@ import org.springframework.web.bind.annotation.PostMapping; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.core.Route; import ru.ulstu.extractor.markup.model.MarkupForm; -import ru.ulstu.extractor.markup.model.MarkupRow; +import ru.ulstu.extractor.markup.model.TimeSeriesForMarkup; import ru.ulstu.extractor.markup.service.MarkupService; -import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; import java.util.List; -import java.util.stream.Collectors; @Controller @ApiIgnore @@ -34,18 +32,21 @@ public class TimeSeriesMarkupController { @GetMapping("time-series-markup") public String markupTs(Model model) { - model.addAttribute("branches", branchService.findAll()); + model.addAttribute("branches", branchService.findAllValid()); model.addAttribute("markupForm", new MarkupForm()); return "markup"; } @PostMapping("time-series-markup") public String filter(Model model, @ModelAttribute MarkupForm markupForm) { - model.addAttribute("branches", branchService.findAll()); + model.addAttribute("branches", branchService.findAllValid()); if (markupForm != null && markupForm.getBranchId() != null) { - List tss = timeSeriesService.getByBranch(markupForm.getBranchId()); - MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList())); - markupFormWithTs.setBranchId(markupForm.getBranchId()); + List tss = markupService.getTimeSeriesForMarkup( + timeSeriesService.getGroupedTendencies( + timeSeriesService.getByBranch(markupForm.getBranchId()) + ) + ); + MarkupForm markupFormWithTs = new MarkupForm(markupForm.getBranchId(), tss); model.addAttribute("markupForm", markupFormWithTs); } else { model.addAttribute("markupForm", new MarkupForm()); @@ -55,15 +56,18 @@ public class TimeSeriesMarkupController { @PostMapping(Route.ADD_MARKUP) public String addMarkups(Model model, @ModelAttribute MarkupForm markupForm) { - model.addAttribute("branches", branchService.findAll()); - if (markupForm.getBranchId() != null) { - List tss = timeSeriesService.getByBranch(markupForm.getBranchId()); - MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList())); - markupFormWithTs.setBranchId(markupForm.getBranchId()); + model.addAttribute("branches", branchService.findAllValid()); + if (markupForm != null && markupForm.getBranchId() != null) { + List tss = markupService.getTimeSeriesForMarkup( + timeSeriesService.getGroupedTendencies( + timeSeriesService.getByBranch(markupForm.getBranchId()) + ) + ); + MarkupForm markupFormWithTs = new MarkupForm(markupForm.getBranchId(), tss); model.addAttribute("markupForm", markupFormWithTs); - if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) { - markupService.saveMarkup(markupForm); - } +// if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) { +// markupService.saveMarkup(markupForm); +// } } return "markup"; } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java index c07c837..098a379 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java @@ -4,24 +4,23 @@ import java.util.ArrayList; import java.util.List; public class MarkupForm { - private List markupRows = new ArrayList<>(); + private List timeSeriesForMarkupList = new ArrayList<>(); private Integer branchId; - private boolean save; - private boolean filter; public MarkupForm() { } - public MarkupForm(List markupRows) { - this.markupRows = markupRows; + public MarkupForm(Integer branchId, List tss) { + this.timeSeriesForMarkupList = tss; + this.branchId = branchId; } - public List getMarkupRows() { - return markupRows; + public List getTimeSeriesForMarkupList() { + return timeSeriesForMarkupList; } - public void setMarkupRows(List markupRows) { - this.markupRows = markupRows; + public void setTimeSeriesForMarkupList(List timeSeriesForMarkupList) { + this.timeSeriesForMarkupList = timeSeriesForMarkupList; } public Integer getBranchId() { @@ -31,20 +30,4 @@ public class MarkupForm { public void setBranchId(Integer branchId) { this.branchId = branchId; } - - public boolean isSave() { - return save; - } - - public void setSave(boolean save) { - this.save = save; - } - - public boolean isFilter() { - return filter; - } - - public void setFilter(boolean filter) { - this.filter = filter; - } } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java new file mode 100644 index 0000000..3bb84ff --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java @@ -0,0 +1,44 @@ +package ru.ulstu.extractor.markup.model; + +import ru.ulstu.extractor.ts.model.TimeSeries; + +import java.util.Date; +import java.util.Set; +import java.util.TreeSet; + +public class TimeSeriesForMarkup { + private Set timeSeriesSet = new TreeSet<>(); + private Date dateFrom; + private Date dateTo; + + public TimeSeriesForMarkup(TimeSeries ts1, TimeSeries ts2, Date dateFrom, Date dateTo) { + this.dateFrom = dateFrom; + this.dateTo = dateTo; + this.timeSeriesSet.add(ts1); + this.timeSeriesSet.add(ts2); + } + + public Set getTimeSeriesSet() { + return timeSeriesSet; + } + + public void setTimeSeriesSet(Set timeSeriesSet) { + this.timeSeriesSet = timeSeriesSet; + } + + public Date getDateFrom() { + return dateFrom; + } + + public void setDateFrom(Date dateFrom) { + this.dateFrom = dateFrom; + } + + public Date getDateTo() { + return dateTo; + } + + public void setDateTo(Date dateTo) { + this.dateTo = dateTo; + } +} diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index c4d3fd3..2d3096f 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -1,13 +1,14 @@ package ru.ulstu.extractor.markup.service; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import ru.ulstu.extractor.markup.model.Markup; -import ru.ulstu.extractor.markup.model.MarkupForm; +import ru.ulstu.extractor.markup.model.TimeSeriesForMarkup; import ru.ulstu.extractor.markup.repository.MarkupRepository; import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; +import java.util.ArrayList; import java.util.List; @Service @@ -21,15 +22,47 @@ public class MarkupService { this.timeSeriesService = timeSeriesService; } - @Transactional + /*@Transactional public void saveMarkup(MarkupForm markupForm) { markupForm.getMarkupRows().forEach(markupRow -> { TimeSeries timeSeries = timeSeriesService.getById(markupRow.getTimeSeries().getId()); markupRepository.save(new Markup(timeSeries, markupRow.getMarkup())); }); - } + }*/ public List findAll() { return markupRepository.findAll(); } + + public List getTimeSeriesForMarkup(List timeSeriesList) { + List tsForMarkup = new ArrayList<>(); + for (int i = 0; i < timeSeriesList.size(); i++) { + TimeSeries ts1 = timeSeriesList.get(i); + for (int j = i + 1; j < timeSeriesList.size(); j++) { + TimeSeries ts2 = timeSeriesList.get(j); + List values1 = ts1.getValues(); + for (int k = 0; k < values1.size() - 1; k++) { + List values2 = ts2.getValues(); + for (int l = 0; l < values2.size() - 1; l++) { + if (values1.get(k).getDate().equals(values2.get(l).getDate()) + && values1.get(k + 1).getDate().equals(values2.get(l + 1).getDate())) { + final int index = k; + TimeSeriesForMarkup found = tsForMarkup + .stream() + .filter(m -> m.getDateFrom().equals(values1.get(index).getDate()) && m.getDateTo().equals(values1.get(index + 1).getDate())) + .findAny() + .orElse(null); + if (found == null) { + tsForMarkup.add(new TimeSeriesForMarkup(ts1, ts2, values1.get(index).getDate(), values1.get(index + 1).getDate())); + } else { + found.getTimeSeriesSet().add(ts1); + found.getTimeSeriesSet().add(ts2); + } + } + } + } + } + } + return tsForMarkup; + } } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index c0c98a7..0f085fe 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -36,15 +36,15 @@
- + - - - - + + + + +
Разметка временных рядовОхарактеризуйте периоды вашего проекта
-- 2.34.1 From 5c6b38890185d3dd6e7054471c338c1290fdc844 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 16 Mar 2023 23:09:26 +0400 Subject: [PATCH 084/110] #91 -- Reformat --- .../extractor/markup/service/MarkupService.java | 12 ++++++------ src/main/resources/templates/markup.html | 8 +++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index 2d3096f..c222d39 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -38,22 +38,22 @@ public class MarkupService { List tsForMarkup = new ArrayList<>(); for (int i = 0; i < timeSeriesList.size(); i++) { TimeSeries ts1 = timeSeriesList.get(i); - for (int j = i + 1; j < timeSeriesList.size(); j++) { + for (int j = i+1; j < timeSeriesList.size(); j++) { TimeSeries ts2 = timeSeriesList.get(j); List values1 = ts1.getValues(); - for (int k = 0; k < values1.size() - 1; k++) { + for (int k = 0; k < values1.size()-1; k++) { List values2 = ts2.getValues(); - for (int l = 0; l < values2.size() - 1; l++) { + for (int l = 0; l < values2.size()-1; l++) { if (values1.get(k).getDate().equals(values2.get(l).getDate()) - && values1.get(k + 1).getDate().equals(values2.get(l + 1).getDate())) { + && values1.get(k+1).getDate().equals(values2.get(l+1).getDate())) { final int index = k; TimeSeriesForMarkup found = tsForMarkup .stream() - .filter(m -> m.getDateFrom().equals(values1.get(index).getDate()) && m.getDateTo().equals(values1.get(index + 1).getDate())) + .filter(m -> m.getDateFrom().equals(values1.get(index).getDate()) && m.getDateTo().equals(values1.get(index+1).getDate())) .findAny() .orElse(null); if (found == null) { - tsForMarkup.add(new TimeSeriesForMarkup(ts1, ts2, values1.get(index).getDate(), values1.get(index + 1).getDate())); + tsForMarkup.add(new TimeSeriesForMarkup(ts1, ts2, values1.get(index).getDate(), values1.get(index+1).getDate())); } else { found.getTimeSeriesSet().add(ts1); found.getTimeSeriesSet().add(ts2); diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 0f085fe..87746b9 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -22,9 +22,7 @@
@@ -41,10 +39,10 @@ - + - + -- 2.34.1 From 4596a25a595a21bf356d2b94ea809e6b7e7b34cb Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 11 Apr 2023 16:36:05 +0400 Subject: [PATCH 085/110] #91 -- Fix fuzzy inference --- .../assessment/service/AssessmentService.java | 49 ++----------------- .../rule/service/FuzzyInferenceService.java | 26 +++++----- .../ts/service/TimeSeriesService.java | 16 +++++- 3 files changed, 28 insertions(+), 63 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index e1a2020..2d9899c 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -8,7 +8,6 @@ import ru.ulstu.extractor.rule.service.AntecedentValueService; import ru.ulstu.extractor.rule.service.DbRuleService; import ru.ulstu.extractor.rule.service.FuzzyInferenceService; import ru.ulstu.extractor.ts.model.TimeSeries; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.ArrayList; @@ -57,9 +56,7 @@ public class AssessmentService { timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService.getLastTimeSeriesTendency(ts))); return fuzzyInferenceService.getFuzzyInference(dbRules, antecedentValueService.getList(), - variableValues, - getTSsMin(timeSeries), - getTSsMax(timeSeries)); + variableValues); } private List getAssessmentsByTimeSeriesTendencies(List dbRules, List timeSeries) { @@ -75,9 +72,7 @@ public class AssessmentService { .getLastTimeSeriesTendency(ts))); return fuzzyInferenceService.getFuzzyInference(List.of(dbRule), antecedentValueService.getList(), - variableValues, - getTSsMin(timeSeries), - getTSsMax(timeSeries)).stream(); + variableValues).stream(); }) .sorted(Comparator.comparing(Assessment::getDegree)) .collect(Collectors.toList()); @@ -88,44 +83,6 @@ public class AssessmentService { timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), ts.getValues().get(ts.getValues().size() - 1).getValue())); return fuzzyInferenceService.getFuzzyInference(dbRules, antecedentValueService.getList(), - variableValues, - getTSsMin(timeSeries), - getTSsMax(timeSeries)); - } - - private Double getMin(List values) { - return values.stream().mapToDouble(v -> v).min().getAsDouble(); - } - - private Map.Entry getTSMin(TimeSeries ts) { - return Map.entry(ts.getTimeSeriesType().name(), - getMin(ts.getValues().stream().map(TimeSeriesValue::getValue).collect(Collectors.toList()))); - } - - private Map getTSsMin(List tss) { - Map res = new HashMap<>(); - tss.forEach(ts -> { - Map.Entry entry = getTSMin(ts); - res.put(entry.getKey(), entry.getValue()); - }); - return res; - } - - private Double getMax(List values) { - return values.stream().mapToDouble(v -> v).max().getAsDouble(); - } - - private Map.Entry getTSMax(TimeSeries ts) { - return Map.entry(ts.getTimeSeriesType().name(), - getMax(ts.getValues().stream().map(TimeSeriesValue::getValue).collect(Collectors.toList()))); - } - - private Map getTSsMax(List tss) { - Map res = new HashMap<>(); - tss.forEach(ts -> { - Map.Entry entry = getTSMax(ts); - res.put(entry.getKey(), entry.getValue()); - }); - return res; + variableValues); } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java index 6768c87..910dde5 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java @@ -34,8 +34,7 @@ public class FuzzyInferenceService { + " is %s"; private final static String NO_RESULT = "Нет результата"; - private List getRulesFromDb(List dbRules, Map variableValues) { - validateVariables(variableValues, dbRules); + private List mapRulesToString(List dbRules) { return dbRules.stream().map(this::getFuzzyRule).collect(Collectors.toList()); } @@ -51,8 +50,6 @@ public class FuzzyInferenceService { private RuleBlock getRuleBlock(Engine engine, List dbRules, Map variableValues, - Map min, - Map max, List antecedentValues, List consequentValues) { variableValues.forEach((key, value) -> { @@ -61,16 +58,16 @@ public class FuzzyInferenceService { input.setDescription(""); input.setEnabled(true); double delta = antecedentValues.size() > 1 - ? (max.get(key) - min.get(key)) / (antecedentValues.size() - 1) - : (max.get(key) - min.get(key)); - input.setRange(min.get(key), max.get(key)); + ? 2.0 / (antecedentValues.size() - 1) + : 2.0; + input.setRange(-1, 1); input.setLockValueInRange(false); for (int i = 0; i < antecedentValues.size(); i++) { input.addTerm( new Triangle( antecedentValues.get(i).getAntecedentValue(), - min.get(key) + i * delta - 0.5 * delta, - min.get(key) + i * delta + delta + 0.5 * delta + -1 + i * delta - 0.5 * delta, + -1 + i * delta + delta + 0.5 * delta ) ); } @@ -87,7 +84,7 @@ public class FuzzyInferenceService { output.setDefaultValue(Double.NaN); output.setLockValueInRange(false); for (int i = 0; i < consequentValues.size(); i++) { - output.addTerm(new Triangle(consequentValues.get(i).toString(), i, i + 2.1)); + output.addTerm(new Triangle(consequentValues.get(i).toString(), i, i + 1)); } engine.addOutputVariable(output); @@ -99,7 +96,7 @@ public class FuzzyInferenceService { //mamdani.setDisjunction(null); mamdani.setImplication(new AlgebraicProduct()); mamdani.setActivation(new General()); - getRulesFromDb(dbRules, variableValues).forEach(r -> { + mapRulesToString(dbRules).forEach(r -> { LOG.info(r); mamdani.addRule(Rule.parse(r, engine)); }); @@ -115,12 +112,11 @@ public class FuzzyInferenceService { public List getFuzzyInference(List dbRules, List antecedentValues, - Map variableValues, - Map min, - Map max) { + Map variableValues) { + validateVariables(variableValues, dbRules); Engine engine = getFuzzyEngine(); List consequentValues = dbRules.stream().map(DbRule::getId).collect(Collectors.toList()); - engine.addRuleBlock(getRuleBlock(engine, dbRules, variableValues, min, max, antecedentValues, consequentValues)); + engine.addRuleBlock(getRuleBlock(engine, dbRules, variableValues, antecedentValues, consequentValues)); Map.Entry consequent = getConsequent(engine, variableValues); if (consequent.getKey().equals(NO_RESULT)) { return new ArrayList<>(); 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 5d48ae7..038a3c0 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -127,17 +127,29 @@ public class TimeSeriesService { public double getLastTimeSeriesTendency(TimeSeries ts) { if (ts != null && ts.getValues().size() > MIN_TIME_SERIES_LENGTH) { - JSONObject response = httpService.post(TIME_SERIES_TENDENCY_URL, new JSONObject(new SmoothingTimeSeries(ts))); + JSONObject response = httpService.post(TIME_SERIES_TENDENCY_URL, new JSONObject(new SmoothingTimeSeries(normalizeTimeSeries(ts)))); LOG.debug("Успешно отправлен на сервис сглаживания"); if (response.has("response") && response.getString("response").equals("empty")) { return DEFAULT_TIME_SERIES_TENDENCY; } JSONArray jsonArray = response.getJSONObject("timeSeries").getJSONArray("values"); - return jsonArray.getJSONObject(jsonArray.length() - 1).getDouble("value"); + return jsonArray.getJSONObject(jsonArray.length() - 1).getDouble("value") - + jsonArray.getJSONObject(jsonArray.length() - 2).getDouble("value"); } return DEFAULT_TIME_SERIES_TENDENCY; } + private TimeSeries normalizeTimeSeries(TimeSeries ts) { + double sum = ts.getValues().stream().mapToDouble(TimeSeriesValue::getValue).sum(); + + if (sum > 0.0d) { + for (int i = 0; i < ts.getValues().size(); i++) { + ts.getValues().get(i).setValue(ts.getValues().get(i).getValue() / sum); + } + } + return ts; + } + public boolean isBranchContainsAllTimeSeries(Branch b) { List timeSeries = getByBranch(b.getId()); return Stream.of(TimeSeriesType.values()).allMatch(type -> timeSeries -- 2.34.1 From d03cb194ee0ef081af66d40fd63081155a68def7 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Apr 2023 13:23:48 +0400 Subject: [PATCH 086/110] #91 -- Fix fuzzy inference --- .../controller/AssessmentController.java | 3 ++- .../assessment/service/AssessmentService.java | 20 ++++++------------- src/main/resources/templates/assessments.html | 19 +++++++++++++++++- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java b/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java index e5721fa..35beb28 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java +++ b/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java @@ -29,7 +29,8 @@ public class AssessmentController { public String getAssessments(Model model, @RequestParam Optional branchId) { model.addAttribute("branches", branchService.findAllValid()); if (branchId.isPresent()) { - model.addAttribute("assessments", assessmentService.getAssessmentsByForecastTendencies(branchId.get())); + model.addAttribute("assessments", assessmentService.getAssessments(branchId.get())); + model.addAttribute("singleAssessment", assessmentService.getSingleAssessment(branchId.get())); model.addAttribute("filterBranchForm", new FilterBranchForm(branchId.get())); } else { model.addAttribute("filterBranchForm", new FilterBranchForm()); diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index 2d9899c..83e99ef 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -34,24 +34,24 @@ public class AssessmentService { this.fuzzyInferenceService = fuzzyInferenceService; } - public List getAssessmentsByForecastTendencies(Integer branchId) { + public List getAssessments(Integer branchId) { List timeSeries = timeSeriesService.getByBranch(branchId); List dbRules = ruleService.getList(); try { - return getAssessmentsByTimeSeriesTendencies(dbRules, timeSeries); + return getAssessments(dbRules, timeSeries); } catch (AssessmentException ex) { ex.printStackTrace(); return new ArrayList<>(); } } - public List getAssessmentsByLastValues(Integer branchId) { + public List getSingleAssessment(Integer branchId) throws AssessmentException { List timeSeries = timeSeriesService.getByBranch(branchId); List dbRules = ruleService.getList(); - return getAssessmentsByLastValues(dbRules, timeSeries); + return getSingleAssessment(dbRules, timeSeries); } - private List getSingleAssessmentByTimeSeriesTendencies(List dbRules, List timeSeries) throws AssessmentException { + private List getSingleAssessment(List dbRules, List timeSeries) throws AssessmentException { Map variableValues = new HashMap<>(); timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService.getLastTimeSeriesTendency(ts))); return fuzzyInferenceService.getFuzzyInference(dbRules, @@ -59,7 +59,7 @@ public class AssessmentService { variableValues); } - private List getAssessmentsByTimeSeriesTendencies(List dbRules, List timeSeries) { + private List getAssessments(List dbRules, List timeSeries) { return dbRules .stream() .flatMap(dbRule -> { @@ -77,12 +77,4 @@ public class AssessmentService { .sorted(Comparator.comparing(Assessment::getDegree)) .collect(Collectors.toList()); } - - private List getAssessmentsByLastValues(List dbRules, List timeSeries) { - Map variableValues = new HashMap<>(); - timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), ts.getValues().get(ts.getValues().size() - 1).getValue())); - return fuzzyInferenceService.getFuzzyInference(dbRules, - antecedentValueService.getList(), - variableValues); - } } diff --git a/src/main/resources/templates/assessments.html b/src/main/resources/templates/assessments.html index 8a8c7f7..f213f81 100644 --- a/src/main/resources/templates/assessments.html +++ b/src/main/resources/templates/assessments.html @@ -33,7 +33,7 @@
Выбрерите ветку для получения оценки репозитория
-
Состояние репозитория описывается следующими выражениями:
+
Состояние репозитория по нескольким правилам описывается следующими выражениями:
вследствие тенденции '' показателя '
Нет результатов
+ +
+ +
+
Состояние репозитория по лидирующему правилу описывается следующими выражениями:
+
+ + вследствие тенденции '' показателя '' + и тенденции '' показателя ''; + +
+
+
+
Нет результатов
+
-- 2.34.1 From 6823f3499759e7db6b91ab9f86d0b127ce2debb1 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Apr 2023 15:00:14 +0400 Subject: [PATCH 087/110] #91 -- Fix fuzzy sets --- .../rule/service/FuzzyInferenceService.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java index 910dde5..a1a7f53 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java @@ -57,20 +57,11 @@ public class FuzzyInferenceService { input.setName(key); input.setDescription(""); input.setEnabled(true); - double delta = antecedentValues.size() > 1 - ? 2.0 / (antecedentValues.size() - 1) - : 2.0; input.setRange(-1, 1); input.setLockValueInRange(false); - for (int i = 0; i < antecedentValues.size(); i++) { - input.addTerm( - new Triangle( - antecedentValues.get(i).getAntecedentValue(), - -1 + i * delta - 0.5 * delta, - -1 + i * delta + delta + 0.5 * delta - ) - ); - } + input.addTerm(new Triangle("спад", -1, 0)); + input.addTerm(new Triangle("стабильно", -0.1, 0.1)); + input.addTerm(new Triangle("рост", 0, 1)); engine.addInputVariable(input); }); @@ -114,6 +105,7 @@ public class FuzzyInferenceService { List antecedentValues, Map variableValues) { validateVariables(variableValues, dbRules); + variableValues.entrySet().forEach(e -> System.out.println(e.getKey() + " " + e.getValue())); Engine engine = getFuzzyEngine(); List consequentValues = dbRules.stream().map(DbRule::getId).collect(Collectors.toList()); engine.addRuleBlock(getRuleBlock(engine, dbRules, variableValues, antecedentValues, consequentValues)); -- 2.34.1 From 1dc44f79889eae29b0f0bbb36e5abb5f0965304e Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Apr 2023 15:47:27 +0400 Subject: [PATCH 088/110] #91 -- Fix fuzzy inference --- .../controller/AssessmentController.java | 1 - .../assessment/service/AssessmentService.java | 38 ------------------- .../rule/service/FuzzyInferenceService.java | 27 +++++++------ src/main/resources/templates/assessments.html | 17 --------- 4 files changed, 16 insertions(+), 67 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java b/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java index 35beb28..9a7ffd8 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java +++ b/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java @@ -30,7 +30,6 @@ public class AssessmentController { model.addAttribute("branches", branchService.findAllValid()); if (branchId.isPresent()) { model.addAttribute("assessments", assessmentService.getAssessments(branchId.get())); - model.addAttribute("singleAssessment", assessmentService.getSingleAssessment(branchId.get())); model.addAttribute("filterBranchForm", new FilterBranchForm(branchId.get())); } else { model.addAttribute("filterBranchForm", new FilterBranchForm()); diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index 83e99ef..0bae62a 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -2,7 +2,6 @@ package ru.ulstu.extractor.assessment.service; import org.springframework.stereotype.Service; import ru.ulstu.extractor.assessment.model.Assessment; -import ru.ulstu.extractor.rule.model.AssessmentException; import ru.ulstu.extractor.rule.model.DbRule; import ru.ulstu.extractor.rule.service.AntecedentValueService; import ru.ulstu.extractor.rule.service.DbRuleService; @@ -10,12 +9,9 @@ import ru.ulstu.extractor.rule.service.FuzzyInferenceService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; @Service public class AssessmentService { @@ -37,44 +33,10 @@ public class AssessmentService { public List getAssessments(Integer branchId) { List timeSeries = timeSeriesService.getByBranch(branchId); List dbRules = ruleService.getList(); - try { - return getAssessments(dbRules, timeSeries); - } catch (AssessmentException ex) { - ex.printStackTrace(); - return new ArrayList<>(); - } - } - - public List getSingleAssessment(Integer branchId) throws AssessmentException { - List timeSeries = timeSeriesService.getByBranch(branchId); - List dbRules = ruleService.getList(); - return getSingleAssessment(dbRules, timeSeries); - } - - private List getSingleAssessment(List dbRules, List timeSeries) throws AssessmentException { Map variableValues = new HashMap<>(); timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService.getLastTimeSeriesTendency(ts))); return fuzzyInferenceService.getFuzzyInference(dbRules, antecedentValueService.getList(), variableValues); } - - private List getAssessments(List dbRules, List timeSeries) { - return dbRules - .stream() - .flatMap(dbRule -> { - Map variableValues = new HashMap<>(); - timeSeries - .stream() - .filter(ts -> ts.getTimeSeriesType() == dbRule.getFirstAntecedent() - || ts.getTimeSeriesType() == dbRule.getSecondAntecedent()) - .forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService - .getLastTimeSeriesTendency(ts))); - return fuzzyInferenceService.getFuzzyInference(List.of(dbRule), - antecedentValueService.getList(), - variableValues).stream(); - }) - .sorted(Comparator.comparing(Assessment::getDegree)) - .collect(Collectors.toList()); - } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java index a1a7f53..28838c6 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java @@ -8,6 +8,7 @@ import com.fuzzylite.norm.t.AlgebraicProduct; import com.fuzzylite.norm.t.Minimum; import com.fuzzylite.rule.Rule; import com.fuzzylite.rule.RuleBlock; +import com.fuzzylite.term.Activated; import com.fuzzylite.term.Triangle; import com.fuzzylite.variable.InputVariable; import com.fuzzylite.variable.OutputVariable; @@ -109,15 +110,19 @@ public class FuzzyInferenceService { Engine engine = getFuzzyEngine(); List consequentValues = dbRules.stream().map(DbRule::getId).collect(Collectors.toList()); engine.addRuleBlock(getRuleBlock(engine, dbRules, variableValues, antecedentValues, consequentValues)); - Map.Entry consequent = getConsequent(engine, variableValues); - if (consequent.getKey().equals(NO_RESULT)) { + Map consequents = getConsequent(engine, variableValues); + if (consequents.containsKey(NO_RESULT)) { return new ArrayList<>(); } - return dbRules - .stream() - .filter(r -> r.getId().equals(Integer.valueOf(consequent.getKey()))) - .map(r -> new Assessment(r, consequent.getValue())) - .collect(Collectors.toList()); + List assessments = new ArrayList<>(); + for (Map.Entry consequent : consequents.entrySet()) { + for (DbRule dbRule : dbRules) { + if (dbRule.getId().equals(Integer.valueOf(consequent.getKey()))) { + assessments.add(new Assessment(dbRule, consequent.getValue())); + } + } + } + return assessments; } @@ -134,7 +139,7 @@ public class FuzzyInferenceService { } } - private Map.Entry getConsequent(Engine engine, Map variableValues) { + private Map getConsequent(Engine engine, Map variableValues) { OutputVariable outputVariable = engine.getOutputVariable(OUTPUT_VARIABLE_NAME); for (Map.Entry variableValue : variableValues.entrySet()) { InputVariable inputVariable = engine.getInputVariable(variableValue.getKey()); @@ -144,8 +149,8 @@ public class FuzzyInferenceService { if (outputVariable != null) { LOG.info("Output: {}", outputVariable.getValue()); } - return (outputVariable == null || Double.isNaN(outputVariable.getValue())) - ? Map.entry(NO_RESULT, 0.0) - : Map.entry(outputVariable.highestMembershipTerm(outputVariable.getValue()).getName(), outputVariable.getValue()); + return Double.isNaN(outputVariable.getValue()) + ? Map.of(NO_RESULT, 0.0) + : outputVariable.fuzzyOutput().getTerms().stream().collect(Collectors.toMap(t -> t.getTerm().getName(), Activated::getDegree)); } } diff --git a/src/main/resources/templates/assessments.html b/src/main/resources/templates/assessments.html index f213f81..d88b271 100644 --- a/src/main/resources/templates/assessments.html +++ b/src/main/resources/templates/assessments.html @@ -46,22 +46,5 @@
Нет результатов
- -
- -
-
Состояние репозитория по лидирующему правилу описывается следующими выражениями:
-
- - вследствие тенденции '' показателя '' - и тенденции '' показателя ''; - -
-
-
-
Нет результатов
-
-- 2.34.1 From 3bb4f5c49c0ddb09e63f77ddd7884c2d265a5279 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Apr 2023 22:49:33 +0400 Subject: [PATCH 089/110] #91 -- Run scheduled time series creators --- .../gitrepository/service/IndexService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index 8e89f21..9b2cca7 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.gitrepository.service; import com.sun.istack.NotNull; @@ -18,6 +13,7 @@ import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.creator.db.DBTimeSeriesCreator; +import ru.ulstu.extractor.ts.service.ScheduledTimeSeriesService; import java.io.IOException; import java.util.Collections; @@ -30,13 +26,16 @@ public class IndexService { private final GitRepositoryService gitRepositoryService; private final BranchService branchService; private final List timeSeriesCreators; + private final ScheduledTimeSeriesService scheduledTimeSeriesService; public IndexService(GitRepositoryService gitRepositoryService, BranchService branchService, - List timeSeriesCreators) { + List timeSeriesCreators, + ScheduledTimeSeriesService scheduledTimeSeriesService) { this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; this.timeSeriesCreators = timeSeriesCreators; + this.scheduledTimeSeriesService = scheduledTimeSeriesService; } @Transactional @@ -74,6 +73,7 @@ public class IndexService { branch = branchService.findByBranchId(branch.getId()).orElseThrow(() -> new RuntimeException("Branch not found by id")); final Branch branchForSave = branchService.updateStatus(branch, IndexingStatus.FINISHED); timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(branchForSave)); + scheduledTimeSeriesService.addTimeSeriesPoints(); LOG.debug("Complete indexing {} branch", branch.getName()); } -- 2.34.1 From 8d31dc36b36fb27940e732d426c7539912c3e1b4 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Apr 2023 23:11:09 +0400 Subject: [PATCH 090/110] #91 -- Fix time series types --- src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java index f694064..27487b7 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java @@ -3,9 +3,6 @@ package ru.ulstu.extractor.ts.model; public enum TimeSeriesType { COMMITS("Временной ряд коммитов"), AUTHOR_COMMITS("Временной ряд коммитов авторов"), - AUTHOR_ISSUES("Временной ряд задач авторов"), - AUTHOR_COMPLETED_ISSUES("Временной ряд завершенных задач авторов"), - AUTHORS("Временной ряд авторов"), BRANCHES("Временной ряд веток"), CLASSES("Временной ряд классов"), DEPENDENCIES("Временной ряд зависимостей"), -- 2.34.1 From 1c62c520e940cf815b7f07068a5db599ecec75e1 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 22 Apr 2023 12:26:54 +0400 Subject: [PATCH 091/110] #91 -- Fix db --- .../db/changelog-20230302_210000-schema.xml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/resources/db/changelog-20230302_210000-schema.xml b/src/main/resources/db/changelog-20230302_210000-schema.xml index 7ccb661..670658e 100644 --- a/src/main/resources/db/changelog-20230302_210000-schema.xml +++ b/src/main/resources/db/changelog-20230302_210000-schema.xml @@ -20,4 +20,30 @@ referencedTableName="time_series" referencedColumnNames="id"/> + + + delete + from time_series + where time_series_type = 'AUTHORS'; + delete + from rule + where first_antecedent = 'AUTHORS' + OR second_antecedent = 'AUTHORS'; + delete + from time_series + where time_series_type = 'AUTHOR_COMPLETED_ISSUES'; + delete + from rule + where first_antecedent = 'AUTHOR_COMPLETED_ISSUES' + OR second_antecedent = 'AUTHOR_COMPLETED_ISSUES'; + delete + from time_series + where time_series_type = 'AUTHOR_ISSUES'; + delete + from rule + where first_antecedent = 'AUTHOR_ISSUES' + OR second_antecedent = 'AUTHOR_ISSUES'; + + + \ No newline at end of file -- 2.34.1 From 9c3a64b0d0c7707ebcb8e380a337a3b1453b944c Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 22 Apr 2023 12:58:12 +0400 Subject: [PATCH 092/110] #91 -- Fix smoothing --- .../ru/ulstu/extractor/ts/service/TimeSeriesService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 038a3c0..2279b0d 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -8,7 +8,6 @@ import org.springframework.stereotype.Service; import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.http.HttpService; import ru.ulstu.extractor.http.JsonTimeSeries; -import ru.ulstu.extractor.http.SmoothingTimeSeries; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -35,7 +34,7 @@ public class TimeSeriesService { private final TimeSeriesDateMapper.TimeSeriesInterval timeSeriesInterval = TimeSeriesDateMapper.TimeSeriesInterval.HOUR; private final HttpService httpService; private final static String TIME_SERIES_SAVE_SERVICE_URL = "http://time-series.athene.tech/api/1.0/add-time-series?setKey=git-extractor"; - private final static String TIME_SERIES_TENDENCY_URL = "http://time-series.athene.tech/api/1.0/getSpecificMethodSmoothed"; + private final static String TIME_SERIES_TENDENCY_URL = "http://time-series.athene.tech/api/1.0/getMaxSmoothing"; private final static String TIME_SERIES_GROUPED_TENDENCIES_URL = "http://time-series.athene.tech/api/1.0/getGroupedTendencies"; public TimeSeriesService(TimeSeriesRepository timeSeriesRepository, @@ -127,7 +126,7 @@ public class TimeSeriesService { public double getLastTimeSeriesTendency(TimeSeries ts) { if (ts != null && ts.getValues().size() > MIN_TIME_SERIES_LENGTH) { - JSONObject response = httpService.post(TIME_SERIES_TENDENCY_URL, new JSONObject(new SmoothingTimeSeries(normalizeTimeSeries(ts)))); + JSONObject response = httpService.post(TIME_SERIES_TENDENCY_URL, new JSONObject(new JsonTimeSeries(normalizeTimeSeries(ts)))); LOG.debug("Успешно отправлен на сервис сглаживания"); if (response.has("response") && response.getString("response").equals("empty")) { return DEFAULT_TIME_SERIES_TENDENCY; -- 2.34.1 From e506566a5ddc79ac28b98b06861d3830e44e2572 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 23 Apr 2023 15:08:26 +0400 Subject: [PATCH 093/110] #91 -- Fix data for markup --- .../TimeSeriesMarkupController.java | 7 +- .../ulstu/extractor/markup/model/Markup.java | 38 --------- .../markup/model/TimeSeriesForMarkup.java | 26 +++--- .../markup/repository/MarkupRepository.java | 7 -- .../markup/service/MarkupService.java | 83 +++++++++++++------ .../extractor/rule/service/DbRuleService.java | 58 +++---------- src/main/resources/templates/markup.html | 29 +++---- 7 files changed, 98 insertions(+), 150 deletions(-) delete mode 100644 src/main/java/ru/ulstu/extractor/markup/model/Markup.java delete mode 100644 src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index 94d1ec4..3aef93a 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -65,9 +65,10 @@ public class TimeSeriesMarkupController { ); MarkupForm markupFormWithTs = new MarkupForm(markupForm.getBranchId(), tss); model.addAttribute("markupForm", markupFormWithTs); -// if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) { -// markupService.saveMarkup(markupForm); -// } + if (markupForm.getTimeSeriesForMarkupList() != null + && !markupForm.getTimeSeriesForMarkupList().isEmpty()) { + markupService.generateRules(markupForm); + } } return "markup"; } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java deleted file mode 100644 index f119e41..0000000 --- a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java +++ /dev/null @@ -1,38 +0,0 @@ -package ru.ulstu.extractor.markup.model; - -import ru.ulstu.extractor.core.BaseEntity; -import ru.ulstu.extractor.ts.model.TimeSeries; - -import javax.persistence.Entity; -import javax.persistence.ManyToOne; - -@Entity -public class Markup extends BaseEntity { - @ManyToOne - private TimeSeries timeSeries; - private String markup; - - public Markup() { - } - - public Markup(TimeSeries timeSeries, String markup) { - this.timeSeries = timeSeries; - this.markup = markup; - } - - public TimeSeries getTimeSeries() { - return timeSeries; - } - - public void setTimeSeries(TimeSeries timeSeries) { - this.timeSeries = timeSeries; - } - - public String getMarkup() { - return markup; - } - - public void setMarkup(String markup) { - this.markup = markup; - } -} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java index 3bb84ff..9aaa903 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java @@ -1,29 +1,27 @@ package ru.ulstu.extractor.markup.model; +import ru.ulstu.extractor.rule.model.AntecedentValue; import ru.ulstu.extractor.ts.model.TimeSeries; import java.util.Date; -import java.util.Set; -import java.util.TreeSet; +import java.util.HashMap; +import java.util.Map; public class TimeSeriesForMarkup { - private Set timeSeriesSet = new TreeSet<>(); + private Map timeSeriesTendencyMap = new HashMap<>(); + private String markup; private Date dateFrom; private Date dateTo; - public TimeSeriesForMarkup(TimeSeries ts1, TimeSeries ts2, Date dateFrom, Date dateTo) { + public TimeSeriesForMarkup(TimeSeries ts1, AntecedentValue tendency1, TimeSeries ts2, AntecedentValue tendency2, Date dateFrom, Date dateTo) { this.dateFrom = dateFrom; this.dateTo = dateTo; - this.timeSeriesSet.add(ts1); - this.timeSeriesSet.add(ts2); + this.timeSeriesTendencyMap.put(ts1, tendency1); + this.timeSeriesTendencyMap.put(ts2, tendency2); } - public Set getTimeSeriesSet() { - return timeSeriesSet; - } - - public void setTimeSeriesSet(Set timeSeriesSet) { - this.timeSeriesSet = timeSeriesSet; + public Map getTimeSeriesTendencyMap() { + return timeSeriesTendencyMap; } public Date getDateFrom() { @@ -41,4 +39,8 @@ public class TimeSeriesForMarkup { public void setDateTo(Date dateTo) { this.dateTo = dateTo; } + + public String getMarkup() { + return markup; + } } diff --git a/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java b/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java deleted file mode 100644 index 0d149f1..0000000 --- a/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.ulstu.extractor.markup.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import ru.ulstu.extractor.markup.model.Markup; - -public interface MarkupRepository extends JpaRepository { -} diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index c222d39..12ee087 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -1,68 +1,97 @@ package ru.ulstu.extractor.markup.service; import org.springframework.stereotype.Service; -import ru.ulstu.extractor.markup.model.Markup; +import ru.ulstu.extractor.markup.model.MarkupForm; import ru.ulstu.extractor.markup.model.TimeSeriesForMarkup; -import ru.ulstu.extractor.markup.repository.MarkupRepository; +import ru.ulstu.extractor.rule.model.AntecedentValue; +import ru.ulstu.extractor.rule.service.AntecedentValueService; +import ru.ulstu.extractor.rule.service.DbRuleService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesValue; -import ru.ulstu.extractor.ts.service.TimeSeriesService; +import javax.transaction.Transactional; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; @Service public class MarkupService { - private final MarkupRepository markupRepository; - private final TimeSeriesService timeSeriesService; + private final DbRuleService dbRuleService; + private final AntecedentValueService antecedentValueService; - public MarkupService(MarkupRepository markupRepository, - TimeSeriesService timeSeriesService) { - this.markupRepository = markupRepository; - this.timeSeriesService = timeSeriesService; + public MarkupService(DbRuleService dbRuleService, + AntecedentValueService antecedentValueService) { + this.dbRuleService = dbRuleService; + this.antecedentValueService = antecedentValueService; } - /*@Transactional - public void saveMarkup(MarkupForm markupForm) { - markupForm.getMarkupRows().forEach(markupRow -> { - TimeSeries timeSeries = timeSeriesService.getById(markupRow.getTimeSeries().getId()); - markupRepository.save(new Markup(timeSeries, markupRow.getMarkup())); + @Transactional + public void generateRules(MarkupForm markupForm) { + markupForm.getTimeSeriesForMarkupList().forEach(markupRow -> { + Set> timeSeriesEntry1 = markupRow.getTimeSeriesTendencyMap().entrySet(); + Set> timeSeriesEntry2 = markupRow.getTimeSeriesTendencyMap().entrySet(); + for (Map.Entry entry1 : timeSeriesEntry1) { + for (Map.Entry entry2 : timeSeriesEntry2) { + if (!entry1.equals(entry2)) { + dbRuleService.saveRule(entry1.getKey().getTimeSeriesType(), entry1.getValue(), + entry2.getKey().getTimeSeriesType(), entry2.getValue(), + markupRow.getMarkup()); + } + } + } }); - }*/ - - public List findAll() { - return markupRepository.findAll(); } + private AntecedentValue getAntecedent(Double diff) { + String antecedentValue; + if (diff < 0) { + antecedentValue = "спад"; + } else if (diff > 0) { + antecedentValue = "рост"; + } else { + antecedentValue = "стабильно"; + } + return antecedentValueService.getByValue(antecedentValue); + } + + public List getTimeSeriesForMarkup(List timeSeriesList) { List tsForMarkup = new ArrayList<>(); for (int i = 0; i < timeSeriesList.size(); i++) { TimeSeries ts1 = timeSeriesList.get(i); - for (int j = i+1; j < timeSeriesList.size(); j++) { + for (int j = i + 1; j < timeSeriesList.size(); j++) { TimeSeries ts2 = timeSeriesList.get(j); List values1 = ts1.getValues(); - for (int k = 0; k < values1.size()-1; k++) { + for (int k = 0; k < values1.size() - 1; k++) { List values2 = ts2.getValues(); - for (int l = 0; l < values2.size()-1; l++) { + for (int l = 0; l < values2.size() - 1; l++) { if (values1.get(k).getDate().equals(values2.get(l).getDate()) - && values1.get(k+1).getDate().equals(values2.get(l+1).getDate())) { + && values1.get(k + 1).getDate().equals(values2.get(l + 1).getDate())) { final int index = k; TimeSeriesForMarkup found = tsForMarkup .stream() - .filter(m -> m.getDateFrom().equals(values1.get(index).getDate()) && m.getDateTo().equals(values1.get(index+1).getDate())) + .filter(m -> m.getDateFrom().equals(values1.get(index).getDate()) && m.getDateTo().equals(values1.get(index + 1).getDate())) .findAny() .orElse(null); + AntecedentValue antecedentValue1 = getAntecedent(values1.get(index + 1).getValue() - values1.get(index).getValue()); + AntecedentValue antecedentValue2 = getAntecedent(values2.get(l + 1).getValue() - values2.get(l).getValue()); if (found == null) { - tsForMarkup.add(new TimeSeriesForMarkup(ts1, ts2, values1.get(index).getDate(), values1.get(index+1).getDate())); + tsForMarkup.add(new TimeSeriesForMarkup(ts1, antecedentValue1, ts2, antecedentValue2, values1.get(index).getDate(), values1.get(index + 1).getDate())); } else { - found.getTimeSeriesSet().add(ts1); - found.getTimeSeriesSet().add(ts2); + found.getTimeSeriesTendencyMap().put(ts1, antecedentValue1); + found.getTimeSeriesTendencyMap().put(ts2, antecedentValue2); } } } } } } - return tsForMarkup; + return tsForMarkup + .stream() + .sorted(Comparator.comparing(TimeSeriesForMarkup::getDateFrom)) + .collect(Collectors.toList()); } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java index c0a2dc5..44fe3cf 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java @@ -1,16 +1,11 @@ package ru.ulstu.extractor.rule.service; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import ru.ulstu.extractor.markup.model.Markup; -import ru.ulstu.extractor.markup.service.MarkupService; import ru.ulstu.extractor.rule.model.AddRuleForm; import ru.ulstu.extractor.rule.model.AntecedentValue; import ru.ulstu.extractor.rule.model.DbRule; import ru.ulstu.extractor.rule.repository.RuleRepository; import ru.ulstu.extractor.ts.model.TimeSeriesType; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; -import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.List; import java.util.stream.Collectors; @@ -19,15 +14,11 @@ import java.util.stream.Collectors; public class DbRuleService { private final RuleRepository ruleRepository; private final AntecedentValueService antecedentValueService; - private final MarkupService markupService; public DbRuleService(RuleRepository ruleRepository, - TimeSeriesService timeSeriesService, - AntecedentValueService antecedentValueService, - MarkupService markupService) { + AntecedentValueService antecedentValueService) { this.ruleRepository = ruleRepository; this.antecedentValueService = antecedentValueService; - this.markupService = markupService; } public List getList() { @@ -52,6 +43,17 @@ public class DbRuleService { } } + public void saveRule(TimeSeriesType timeSeriesType1, AntecedentValue antecedentValue1, + TimeSeriesType timeSeriesType2, AntecedentValue antecedentValue2, + String consequent) { + ruleRepository.save(new DbRule(antecedentValueService.getById(antecedentValue1.getId()), + timeSeriesType1, + antecedentValueService.getById(antecedentValue2.getId()), + timeSeriesType2, + consequent)); + + } + public DbRule findById(Integer id) { return ruleRepository.getOne(id); } @@ -71,40 +73,4 @@ public class DbRuleService { public List getConsequentList() { return ruleRepository.findAll().stream().map(DbRule::getConsequent).collect(Collectors.toList()); } - - @Transactional - public void generateRulesFromMarkup() { - List markups = markupService.findAll(); - for (Markup markup1 : markups) { - for (Markup markup2 : markups) { - if (!markup1.equals(markup2)) { - List values1 = markup1.getTimeSeries().getValues(); - for (int i = 1; i < values1.size(); i++) { - List values2 = markup2.getTimeSeries().getValues(); - for (int j = 1; j < values2.size(); j++) { - ruleRepository.save(new DbRule( - getAntecedent(values1.get(i).getValue() - values1.get(i - 1).getValue()), - markup1.getTimeSeries().getTimeSeriesType(), - getAntecedent(values2.get(j).getValue() - values2.get(j - 1).getValue()), - markup2.getTimeSeries().getTimeSeriesType(), - "сгенерированный консеквент" - )); - } - } - } - } - } - } - - private AntecedentValue getAntecedent(Double diff) { - String antecedentValue; - if (diff < 0) { - antecedentValue = "спад"; - } else if (diff > 0) { - antecedentValue = "рост"; - } else { - antecedentValue = "стабильно"; - } - return antecedentValueService.getByValue(antecedentValue); - } } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 87746b9..0d0fc58 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -22,7 +22,9 @@ @@ -31,22 +33,15 @@ value="Применить"/> - - - - - - - - - - - - - - -
Охарактеризуйте периоды вашего проекта
- +
+ Охарактеризуйте периоды вашего проекта
+
+ + + +
+ -- 2.34.1 From 07cd5abe9cca85ed5df57540e41da1f8c87d7200 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 23 Apr 2023 15:09:00 +0400 Subject: [PATCH 094/110] #91 -- Fix format --- src/main/resources/templates/markup.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 0d0fc58..1009701 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -22,9 +22,7 @@ -- 2.34.1 From d2f898d758d9c4671a19df6dda4897ddc005b5e4 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 23 Apr 2023 23:41:44 +0400 Subject: [PATCH 095/110] #91 -- fix markup --- .../markup/model/TimeSeriesForMarkup.java | 44 ++++++++++++++++++- .../markup/service/MarkupService.java | 15 +++---- .../extractor/rule/service/DbRuleService.java | 4 +- .../ulstu/extractor/ts/model/TimeSeries.java | 5 ++- .../ts/service/TimeSeriesService.java | 2 +- src/main/resources/templates/markup.html | 9 +++- 6 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java index 9aaa903..3a48a57 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java @@ -2,22 +2,35 @@ package ru.ulstu.extractor.markup.model; import ru.ulstu.extractor.rule.model.AntecedentValue; import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class TimeSeriesForMarkup { + //output private Map timeSeriesTendencyMap = new HashMap<>(); - private String markup; private Date dateFrom; private Date dateTo; + //input + private List timeSeriesTypes; + private List antecedentValues; + private String markup; + + public TimeSeriesForMarkup() { + } + public TimeSeriesForMarkup(TimeSeries ts1, AntecedentValue tendency1, TimeSeries ts2, AntecedentValue tendency2, Date dateFrom, Date dateTo) { this.dateFrom = dateFrom; this.dateTo = dateTo; this.timeSeriesTendencyMap.put(ts1, tendency1); this.timeSeriesTendencyMap.put(ts2, tendency2); + refresh(); } public Map getTimeSeriesTendencyMap() { @@ -43,4 +56,33 @@ public class TimeSeriesForMarkup { public String getMarkup() { return markup; } + + public void setTimeSeriesTendencyMap(Map timeSeriesTendencyMap) { + this.timeSeriesTendencyMap = timeSeriesTendencyMap; + } + + public void setMarkup(String markup) { + this.markup = markup; + } + + public List getTimeSeriesTypes() { + return timeSeriesTypes; + } + + public void setTimeSeriesTypes(List timeSeriesTypes) { + this.timeSeriesTypes = timeSeriesTypes; + } + + public List getAntecedentValues() { + return antecedentValues; + } + + public void setAntecedentValues(List antecedentValues) { + this.antecedentValues = antecedentValues; + } + + public void refresh() { + this.antecedentValues = new ArrayList<>(timeSeriesTendencyMap.values()); + this.timeSeriesTypes = timeSeriesTendencyMap.keySet().stream().map(TimeSeries::getTimeSeriesType).collect(Collectors.toList()); + } } diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index 12ee087..5c4508d 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -13,8 +13,6 @@ import javax.transaction.Transactional; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; @Service @@ -31,13 +29,11 @@ public class MarkupService { @Transactional public void generateRules(MarkupForm markupForm) { markupForm.getTimeSeriesForMarkupList().forEach(markupRow -> { - Set> timeSeriesEntry1 = markupRow.getTimeSeriesTendencyMap().entrySet(); - Set> timeSeriesEntry2 = markupRow.getTimeSeriesTendencyMap().entrySet(); - for (Map.Entry entry1 : timeSeriesEntry1) { - for (Map.Entry entry2 : timeSeriesEntry2) { - if (!entry1.equals(entry2)) { - dbRuleService.saveRule(entry1.getKey().getTimeSeriesType(), entry1.getValue(), - entry2.getKey().getTimeSeriesType(), entry2.getValue(), + for (int i = 0; i < markupRow.getTimeSeriesTypes().size(); i++) { + for (int j = i+1; j < markupRow.getTimeSeriesTypes().size(); j++) { + if (i != j) { + dbRuleService.saveRule(markupRow.getTimeSeriesTypes().get(i), markupRow.getAntecedentValues().get(i), + markupRow.getTimeSeriesTypes().get(j), markupRow.getAntecedentValues().get(j), markupRow.getMarkup()); } } @@ -83,6 +79,7 @@ public class MarkupService { } else { found.getTimeSeriesTendencyMap().put(ts1, antecedentValue1); found.getTimeSeriesTendencyMap().put(ts2, antecedentValue2); + found.refresh(); } } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java index 44fe3cf..537ef59 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java @@ -46,9 +46,9 @@ public class DbRuleService { public void saveRule(TimeSeriesType timeSeriesType1, AntecedentValue antecedentValue1, TimeSeriesType timeSeriesType2, AntecedentValue antecedentValue2, String consequent) { - ruleRepository.save(new DbRule(antecedentValueService.getById(antecedentValue1.getId()), + ruleRepository.save(new DbRule(antecedentValueService.getByValue(antecedentValue1.getAntecedentValue()), timeSeriesType1, - antecedentValueService.getById(antecedentValue2.getId()), + antecedentValueService.getByValue(antecedentValue2.getAntecedentValue()), timeSeriesType2, consequent)); 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 34a2b4c..a7519ce 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java @@ -16,6 +16,7 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import static ru.ulstu.extractor.util.JsonUtils.getListOfObjects; @@ -55,8 +56,10 @@ public class TimeSeries extends BaseEntity { this.branch = branch; } - public TimeSeries(JSONObject timeSeries) { + public TimeSeries(JSONObject timeSeries, Optional maybeTimeSeries) { this.name = timeSeries.getString("name"); + this.timeSeriesType = maybeTimeSeries.map(TimeSeries::getTimeSeriesType).orElse(null); + this.setId(maybeTimeSeries.map(TimeSeries::getId).orElse(null)); this.values = getListOfObjects(timeSeries.getJSONArray("values")) .stream() .map(TimeSeriesValue::new) 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 2279b0d..6dba38c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -161,7 +161,7 @@ public class TimeSeriesService { LOG.debug("Send to group time series tendencies"); return JsonUtils.getListOfObjects(response) .stream() - .map(TimeSeries::new) + .map(jsonTs -> new TimeSeries(jsonTs, tsList.stream().filter(ts -> jsonTs.get("name").equals("Model of " + ts.getName())).findAny())) .collect(Collectors.toList()); } } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 1009701..fa92dad 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -34,9 +34,14 @@
Охарактеризуйте периоды вашего проекта
- +
+ +
+
+ +
- +
-- 2.34.1 From 09abd351fb87bba3fbbd9f7368cd59b88d00865a Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 24 Apr 2023 10:31:31 +0400 Subject: [PATCH 096/110] #91 -- remove copyrights --- .../ulstu/extractor/author/repository/AuthorRepository.java | 5 ----- .../ru/ulstu/extractor/author/service/AuthorService.java | 5 ----- .../ulstu/extractor/branch/controller/BranchController.java | 5 ----- src/main/java/ru/ulstu/extractor/branch/model/Branch.java | 5 ----- .../ru/ulstu/extractor/branch/service/BranchService.java | 5 ----- src/main/java/ru/ulstu/extractor/commit/model/Commit.java | 5 ----- .../ulstu/extractor/commit/repository/CommitRepository.java | 5 ----- .../ru/ulstu/extractor/commit/service/CommitService.java | 5 ----- .../extractor/config/GlobalDefaultExceptionHandler.java | 5 ----- .../java/ru/ulstu/extractor/config/MvcConfiguration.java | 5 ----- src/main/java/ru/ulstu/extractor/core/Route.java | 5 ----- .../gitrepository/controler/GitFilteringController.java | 5 ----- .../gitrepository/controler/GitIndexingController.java | 5 ----- .../extractor/gitrepository/controler/RepoController.java | 5 ----- .../gitrepository/controler/RepositoryController.java | 5 ----- .../gitrepository/controler/StatisticController.java | 5 ----- .../ru/ulstu/extractor/gitrepository/model/FileChange.java | 5 ----- .../ru/ulstu/extractor/gitrepository/model/FilterForm.java | 5 ----- .../ru/ulstu/extractor/gitrepository/model/LineChange.java | 5 ----- .../extractor/gitrepository/service/FilteringService.java | 5 ----- .../extractor/heuristic/api/StructuralUnitIdentifier.java | 5 ----- .../ru/ulstu/extractor/heuristic/component/BuildTool.java | 5 ----- .../ulstu/extractor/heuristic/component/GradleBuildTool.java | 5 ----- .../heuristic/component/JavaProgrammingLanguage.java | 5 ----- .../ulstu/extractor/heuristic/component/MavenBuildTool.java | 5 ----- .../extractor/heuristic/component/ProgrammingLanguage.java | 5 ----- .../heuristic/controller/StructuralUnitController.java | 5 ----- .../ulstu/extractor/heuristic/model/BusinessLogicUnit.java | 5 ----- .../java/ru/ulstu/extractor/heuristic/model/EntityUnit.java | 5 ----- .../ru/ulstu/extractor/heuristic/model/ResourceUnit.java | 5 ----- .../ru/ulstu/extractor/heuristic/model/StructuralUnit.java | 5 ----- .../ulstu/extractor/heuristic/service/BuildToolService.java | 5 ----- .../ulstu/extractor/heuristic/service/DetectorService.java | 5 ----- .../ulstu/extractor/heuristic/service/DirectoryService.java | 5 ----- .../ru/ulstu/extractor/heuristic/service/JavaIdentifier.java | 5 ----- .../heuristic/service/ProgrammingLanguageService.java | 5 ----- .../extractor/heuristic/service/StructuralUnitService.java | 5 ----- src/main/java/ru/ulstu/extractor/util/HttpUtils.java | 5 ----- src/main/java/ru/ulstu/extractor/util/StringUtils.java | 5 ----- src/main/resources/application.properties | 4 ---- src/main/resources/messages.properties | 5 ----- src/main/resources/messages_en.properties | 5 ----- src/main/resources/messages_ru.properties | 5 ----- src/main/resources/templates/error.html | 5 ----- src/main/resources/templates/filterCommits.html | 5 ----- src/main/resources/templates/indexNewRepository.html | 5 ----- src/main/resources/templates/listBranches.html | 5 ----- src/main/resources/templates/listRepositories.html | 5 ----- src/main/resources/templates/statistic.html | 5 ----- 49 files changed, 244 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/author/repository/AuthorRepository.java b/src/main/java/ru/ulstu/extractor/author/repository/AuthorRepository.java index 2ad2ceb..5b430e9 100644 --- a/src/main/java/ru/ulstu/extractor/author/repository/AuthorRepository.java +++ b/src/main/java/ru/ulstu/extractor/author/repository/AuthorRepository.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.author.repository; import org.springframework.data.jpa.repository.JpaRepository; 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 ce80869..86da224 100644 --- a/src/main/java/ru/ulstu/extractor/author/service/AuthorService.java +++ b/src/main/java/ru/ulstu/extractor/author/service/AuthorService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.author.service; import org.slf4j.Logger; diff --git a/src/main/java/ru/ulstu/extractor/branch/controller/BranchController.java b/src/main/java/ru/ulstu/extractor/branch/controller/BranchController.java index 8b79a93..81700e5 100644 --- a/src/main/java/ru/ulstu/extractor/branch/controller/BranchController.java +++ b/src/main/java/ru/ulstu/extractor/branch/controller/BranchController.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.branch.controller; import org.springframework.stereotype.Controller; diff --git a/src/main/java/ru/ulstu/extractor/branch/model/Branch.java b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java index 97c03df..6d63841 100644 --- a/src/main/java/ru/ulstu/extractor/branch/model/Branch.java +++ b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.branch.model; import org.hibernate.annotations.Fetch; diff --git a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java index 0684ed4..2b68c45 100644 --- a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java +++ b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.branch.service; import org.slf4j.Logger; diff --git a/src/main/java/ru/ulstu/extractor/commit/model/Commit.java b/src/main/java/ru/ulstu/extractor/commit/model/Commit.java index 5906a3f..535a6b7 100644 --- a/src/main/java/ru/ulstu/extractor/commit/model/Commit.java +++ b/src/main/java/ru/ulstu/extractor/commit/model/Commit.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.commit.model; import org.hibernate.annotations.Fetch; diff --git a/src/main/java/ru/ulstu/extractor/commit/repository/CommitRepository.java b/src/main/java/ru/ulstu/extractor/commit/repository/CommitRepository.java index 70f9888..384e8aa 100644 --- a/src/main/java/ru/ulstu/extractor/commit/repository/CommitRepository.java +++ b/src/main/java/ru/ulstu/extractor/commit/repository/CommitRepository.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.commit.repository; import org.springframework.data.domain.Page; diff --git a/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java b/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java index 79aaa9b..251fbc8 100644 --- a/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java +++ b/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.commit.service; import org.springframework.jdbc.core.JdbcTemplate; diff --git a/src/main/java/ru/ulstu/extractor/config/GlobalDefaultExceptionHandler.java b/src/main/java/ru/ulstu/extractor/config/GlobalDefaultExceptionHandler.java index 62f2b4d..412ddce 100644 --- a/src/main/java/ru/ulstu/extractor/config/GlobalDefaultExceptionHandler.java +++ b/src/main/java/ru/ulstu/extractor/config/GlobalDefaultExceptionHandler.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.config; import org.slf4j.Logger; diff --git a/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java b/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java index a85543c..d430ed3 100644 --- a/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java +++ b/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.config; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/ru/ulstu/extractor/core/Route.java b/src/main/java/ru/ulstu/extractor/core/Route.java index e1605e7..9c56182 100644 --- a/src/main/java/ru/ulstu/extractor/core/Route.java +++ b/src/main/java/ru/ulstu/extractor/core/Route.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.core; import org.springframework.stereotype.Component; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitFilteringController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitFilteringController.java index f083161..84cad9d 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitFilteringController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitFilteringController.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.gitrepository.controler; import org.springframework.data.domain.Page; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitIndexingController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitIndexingController.java index bcd7917..8b98a35 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitIndexingController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/GitIndexingController.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.gitrepository.controler; import org.eclipse.jgit.api.errors.GitAPIException; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepoController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepoController.java index 8bd5299..ebe954f 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepoController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepoController.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.gitrepository.controler; import org.eclipse.jgit.api.errors.GitAPIException; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java index 69b643b..d27ee14 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.gitrepository.controler; import org.springframework.stereotype.Controller; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java index eb2024e..63e75d8 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.gitrepository.controler; import org.springframework.stereotype.Controller; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/model/FileChange.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/FileChange.java index 65d0815..374d757 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/FileChange.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/FileChange.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.gitrepository.model; import org.hibernate.annotations.Fetch; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/model/FilterForm.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/FilterForm.java index f883c82..5574f29 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/FilterForm.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/FilterForm.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.gitrepository.model; import org.springframework.data.domain.Page; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/model/LineChange.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/LineChange.java index 99d78b3..00dbdfc 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/LineChange.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/LineChange.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.gitrepository.model; import ru.ulstu.extractor.core.BaseEntity; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/FilteringService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/FilteringService.java index d3b2a23..246666a 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/FilteringService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/FilteringService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.gitrepository.service; import com.sun.istack.NotNull; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/api/StructuralUnitIdentifier.java b/src/main/java/ru/ulstu/extractor/heuristic/api/StructuralUnitIdentifier.java index 1cfabcf..549e7e4 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/api/StructuralUnitIdentifier.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/api/StructuralUnitIdentifier.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.api; import ru.ulstu.extractor.heuristic.component.BuildTool; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/component/BuildTool.java b/src/main/java/ru/ulstu/extractor/heuristic/component/BuildTool.java index 273e46e..ea450a4 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/component/BuildTool.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/component/BuildTool.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.component; import java.io.File; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/component/GradleBuildTool.java b/src/main/java/ru/ulstu/extractor/heuristic/component/GradleBuildTool.java index 4d1f4d1..c6801d2 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/component/GradleBuildTool.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/component/GradleBuildTool.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.component; import org.springframework.stereotype.Component; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/component/JavaProgrammingLanguage.java b/src/main/java/ru/ulstu/extractor/heuristic/component/JavaProgrammingLanguage.java index 4b2a725..5952984 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/component/JavaProgrammingLanguage.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/component/JavaProgrammingLanguage.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.component; import org.springframework.stereotype.Component; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/component/MavenBuildTool.java b/src/main/java/ru/ulstu/extractor/heuristic/component/MavenBuildTool.java index 7897e1c..b73ee1d 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/component/MavenBuildTool.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/component/MavenBuildTool.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.component; import org.springframework.stereotype.Component; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/component/ProgrammingLanguage.java b/src/main/java/ru/ulstu/extractor/heuristic/component/ProgrammingLanguage.java index 5fa9c30..daa751a 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/component/ProgrammingLanguage.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/component/ProgrammingLanguage.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.component; import java.util.Locale; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java b/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java index db95ab2..a224806 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.controller; import org.eclipse.jgit.api.errors.GitAPIException; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/model/BusinessLogicUnit.java b/src/main/java/ru/ulstu/extractor/heuristic/model/BusinessLogicUnit.java index 9d8e132..307e9d1 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/model/BusinessLogicUnit.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/model/BusinessLogicUnit.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.model; import java.io.File; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/model/EntityUnit.java b/src/main/java/ru/ulstu/extractor/heuristic/model/EntityUnit.java index 3e99784..b6d04d4 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/model/EntityUnit.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/model/EntityUnit.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.model; import java.io.File; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/model/ResourceUnit.java b/src/main/java/ru/ulstu/extractor/heuristic/model/ResourceUnit.java index cf0e517..1c39373 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/model/ResourceUnit.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/model/ResourceUnit.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.model; import java.io.File; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/model/StructuralUnit.java b/src/main/java/ru/ulstu/extractor/heuristic/model/StructuralUnit.java index 6c4ebd8..ff2b195 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/model/StructuralUnit.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/model/StructuralUnit.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.model; import java.io.File; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/service/BuildToolService.java b/src/main/java/ru/ulstu/extractor/heuristic/service/BuildToolService.java index 2ce46cb..bf78f93 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/service/BuildToolService.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/service/BuildToolService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.service; import org.springframework.stereotype.Service; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/service/DetectorService.java b/src/main/java/ru/ulstu/extractor/heuristic/service/DetectorService.java index c989a2f..f6210d5 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/service/DetectorService.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/service/DetectorService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.service; import com.gargoylesoftware.htmlunit.WebClient; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/service/DirectoryService.java b/src/main/java/ru/ulstu/extractor/heuristic/service/DirectoryService.java index 344e09d..ffa8a55 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/service/DirectoryService.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/service/DirectoryService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.service; import com.sun.istack.NotNull; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java b/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java index 5ed971d..178c304 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.service; import com.github.javaparser.JavaParser; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/service/ProgrammingLanguageService.java b/src/main/java/ru/ulstu/extractor/heuristic/service/ProgrammingLanguageService.java index 405ae41..777f44b 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/service/ProgrammingLanguageService.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/service/ProgrammingLanguageService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.service; import org.springframework.stereotype.Service; diff --git a/src/main/java/ru/ulstu/extractor/heuristic/service/StructuralUnitService.java b/src/main/java/ru/ulstu/extractor/heuristic/service/StructuralUnitService.java index aa2e02e..6286600 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/service/StructuralUnitService.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/service/StructuralUnitService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.heuristic.service; import org.springframework.stereotype.Service; diff --git a/src/main/java/ru/ulstu/extractor/util/HttpUtils.java b/src/main/java/ru/ulstu/extractor/util/HttpUtils.java index 5561566..86583b6 100644 --- a/src/main/java/ru/ulstu/extractor/util/HttpUtils.java +++ b/src/main/java/ru/ulstu/extractor/util/HttpUtils.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.util; import javax.servlet.http.HttpServletRequest; diff --git a/src/main/java/ru/ulstu/extractor/util/StringUtils.java b/src/main/java/ru/ulstu/extractor/util/StringUtils.java index 0c57bcb..5770308 100644 --- a/src/main/java/ru/ulstu/extractor/util/StringUtils.java +++ b/src/main/java/ru/ulstu/extractor/util/StringUtils.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.util; import java.nio.file.FileSystems; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 193890c..db1ecfd 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,3 @@ -# -# Copyright (C) 2021 Anton Romanov - All Rights Reserved -# You may use, distribute and modify this code, please write to: romanov73@gmail.com. -# spring.main.banner-mode=off server.port=8080 server.jetty.connection-idle-timeout=1000s diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index e6edf95..d4abcc1 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -1,8 +1,3 @@ -# -# Copyright (C) 2021 Anton Romanov - All Rights Reserved -# You may use, distribute and modify this code, please write to: romanov73@gmail.com. -# - messages.app-name=GitExtractor v0.1.0 messages.menu.home=Main messages.menu.indexed-repos=List of indexed repos diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index e6edf95..d4abcc1 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -1,8 +1,3 @@ -# -# Copyright (C) 2021 Anton Romanov - All Rights Reserved -# You may use, distribute and modify this code, please write to: romanov73@gmail.com. -# - messages.app-name=GitExtractor v0.1.0 messages.menu.home=Main messages.menu.indexed-repos=List of indexed repos diff --git a/src/main/resources/messages_ru.properties b/src/main/resources/messages_ru.properties index 30c525b..e9eadea 100644 --- a/src/main/resources/messages_ru.properties +++ b/src/main/resources/messages_ru.properties @@ -1,8 +1,3 @@ -# -# Copyright (C) 2021 Anton Romanov - All Rights Reserved -# You may use, distribute and modify this code, please write to: romanov73@gmail.com. -# - messages.app-name=GitЁxtractor v0.1.0 messages.menu.home=На главную messages.menu.indexed-repos=Список проиндексированных репозиториев diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html index 47f0e37..23f7172 100644 --- a/src/main/resources/templates/error.html +++ b/src/main/resources/templates/error.html @@ -1,8 +1,3 @@ - - - - - - - Date: Mon, 24 Apr 2023 13:57:37 +0400 Subject: [PATCH 097/110] #91 -- fix time series tendency estimation --- .../java/ru/ulstu/extractor/ts/service/TimeSeriesService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 6dba38c..f28a031 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -128,7 +128,8 @@ public class TimeSeriesService { if (ts != null && ts.getValues().size() > MIN_TIME_SERIES_LENGTH) { JSONObject response = httpService.post(TIME_SERIES_TENDENCY_URL, new JSONObject(new JsonTimeSeries(normalizeTimeSeries(ts)))); LOG.debug("Успешно отправлен на сервис сглаживания"); - if (response.has("response") && response.getString("response").equals("empty")) { + if (response.has("response") && response.getString("response").equals("empty") + || !response.has("timeSeries")) { return DEFAULT_TIME_SERIES_TENDENCY; } JSONArray jsonArray = response.getJSONObject("timeSeries").getJSONArray("values"); -- 2.34.1 From 9cc721849c6d4a59972891c3a18212e1d3000543 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 24 Apr 2023 16:09:12 +0400 Subject: [PATCH 098/110] #91 -- show assessments --- .../assessment/service/AssessmentService.java | 9 +++++-- src/main/resources/templates/assessments.html | 26 +++++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index 0bae62a..488eed6 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -9,9 +9,11 @@ import ru.ulstu.extractor.rule.service.FuzzyInferenceService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.service.TimeSeriesService; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Service public class AssessmentService { @@ -36,7 +38,10 @@ public class AssessmentService { Map variableValues = new HashMap<>(); timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService.getLastTimeSeriesTendency(ts))); return fuzzyInferenceService.getFuzzyInference(dbRules, - antecedentValueService.getList(), - variableValues); + antecedentValueService.getList(), + variableValues) + .stream() + .sorted(Comparator.comparing(Assessment::getDegree).reversed()) + .collect(Collectors.toList()); } } diff --git a/src/main/resources/templates/assessments.html b/src/main/resources/templates/assessments.html index d88b271..98db8ac 100644 --- a/src/main/resources/templates/assessments.html +++ b/src/main/resources/templates/assessments.html @@ -12,9 +12,9 @@
Репозиторий-ветка
-
-
+
+
- -
Выбрерите ветку для получения оценки репозитория
-
Состояние репозитория по нескольким правилам описывается следующими выражениями:
-
+
Состояние репозитория описывается следующими выражениями:
+
+ вследствие тенденции '' показателя '' и тенденции '' показателя ''; - + +
-- 2.34.1 From 14e0266d0bb0b1c447a7ae2fbf1e29fd979d90f8 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 25 Apr 2023 12:32:59 +0400 Subject: [PATCH 099/110] #91 -- fix api call --- .../extractor/gitrepository/service/IndexService.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index 9b2cca7..b1841c3 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -13,7 +13,6 @@ import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.creator.db.DBTimeSeriesCreator; -import ru.ulstu.extractor.ts.service.ScheduledTimeSeriesService; import java.io.IOException; import java.util.Collections; @@ -26,16 +25,13 @@ public class IndexService { private final GitRepositoryService gitRepositoryService; private final BranchService branchService; private final List timeSeriesCreators; - private final ScheduledTimeSeriesService scheduledTimeSeriesService; public IndexService(GitRepositoryService gitRepositoryService, BranchService branchService, - List timeSeriesCreators, - ScheduledTimeSeriesService scheduledTimeSeriesService) { + List timeSeriesCreators) { this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; this.timeSeriesCreators = timeSeriesCreators; - this.scheduledTimeSeriesService = scheduledTimeSeriesService; } @Transactional @@ -73,7 +69,6 @@ public class IndexService { branch = branchService.findByBranchId(branch.getId()).orElseThrow(() -> new RuntimeException("Branch not found by id")); final Branch branchForSave = branchService.updateStatus(branch, IndexingStatus.FINISHED); timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(branchForSave)); - scheduledTimeSeriesService.addTimeSeriesPoints(); LOG.debug("Complete indexing {} branch", branch.getName()); } -- 2.34.1 From 6dbf60cb570b98346402efffdeab532ce518335f Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 25 Apr 2023 15:53:25 +0400 Subject: [PATCH 100/110] #91 -- add accordion --- src/main/resources/templates/assessments.html | 63 ++++++++++++++++--- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/src/main/resources/templates/assessments.html b/src/main/resources/templates/assessments.html index 98db8ac..d9a3721 100644 --- a/src/main/resources/templates/assessments.html +++ b/src/main/resources/templates/assessments.html @@ -35,17 +35,60 @@
-
Состояние репозитория описывается следующими выражениями:
-
- - - вследствие тенденции '' показателя '' - и тенденции '' показателя ''; - -
+
На основе прогноза тенденций показателей репозитория отмечаются следующие характеристики:
+
+
+
+

+ +

+
+ +
+
+ вследствие тенденции '' показателя + '' + и тенденции '' показателя ''; + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Нет результатов
-- 2.34.1 From 23b41ba2832a3431273f7715db358c0444cd1c33 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 25 Apr 2023 16:15:34 +0400 Subject: [PATCH 101/110] #91 -- fix markup UI --- src/main/resources/templates/markup.html | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index fa92dad..41734fb 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -31,20 +31,23 @@ value="Применить"/>
-
+
Охарактеризуйте периоды вашего проекта
-
+
- +
- +
- +
+ class="btn btn-outline-success m-5" value="Сгенерировать правила"/>
-- 2.34.1 From 422864e489ba75a17019e9dc713658c3b12335fa Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 8 May 2023 00:52:35 +0400 Subject: [PATCH 102/110] #91 -- fix ts classes --- .../gitrepository/model/LineChange.java | 4 +- .../service/GitRepositoryService.java | 67 ++++++------------- .../api/StructuralUnitIdentifier.java | 2 + .../heuristic/service/JavaIdentifier.java | 22 ++++-- .../extractor/ts/creator/db/ClassTS.java | 52 ++++++++++---- .../extractor/ts/model/TimeSeriesType.java | 2 +- 6 files changed, 82 insertions(+), 67 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/model/LineChange.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/LineChange.java index 00dbdfc..317db4f 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/LineChange.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/LineChange.java @@ -9,8 +9,8 @@ public class LineChange extends BaseEntity { private Boolean added = false; private Boolean removed = false; - private String lineFrom; - private String lineTo; + private String lineFrom = ""; + private String lineTo = ""; public LineChange() { 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 e400670..391a9a8 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitRepositoryService.java @@ -377,58 +377,33 @@ public class GitRepositoryService { } 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) { + int i = 0; + int added = 0; + int removed = 0; + while (i < fileContent.size()) { 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); - } + while ((i < fileContent.size()) && fileContent.get(i).startsWith("-")) { + lineChange.setRemoved(true); + lineChange.setLineFrom(lineChange.getLineFrom() + "\n" + fileContent.get(i).replaceFirst("\\-", "")); + removed++; + i++; } + while ((i < fileContent.size()) && fileContent.get(i).startsWith("+")) { + lineChange.setAdded(true); + lineChange.setLineTo(lineChange.getLineTo() + "\n" + fileContent.get(i).replaceFirst("\\+", "")); + added++; + i++; + } + if (!lineChange.getLineTo().isEmpty() || !lineChange.getLineFrom().isEmpty()) { + fileChange.getLineChanges().add(lineChange); + } + i++; } - fileChange.setRemoved(removedLine == fileContent.size() - 1); - fileChange.setAdded(addedLine == fileContent.size() - 1); + fileChange.setRemoved(removed == fileContent.size()); + fileChange.setAdded(added == fileContent.size()); 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/heuristic/api/StructuralUnitIdentifier.java b/src/main/java/ru/ulstu/extractor/heuristic/api/StructuralUnitIdentifier.java index 549e7e4..c65fed7 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/api/StructuralUnitIdentifier.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/api/StructuralUnitIdentifier.java @@ -107,4 +107,6 @@ public abstract class StructuralUnitIdentifier { public abstract boolean isResourceClass(String sourceCode); protected abstract boolean isResourceClass(File file); + + public abstract List getClasses(String sourceCode); } diff --git a/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java b/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java index 178c304..d4247f0 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java @@ -6,6 +6,7 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.TypeDeclaration; +import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; import org.springframework.stereotype.Service; import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier; import ru.ulstu.extractor.heuristic.component.BuildTool; @@ -19,6 +20,7 @@ import ru.ulstu.extractor.util.StringUtils; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -52,6 +54,9 @@ public class JavaIdentifier extends StructuralUnitIdentifier { } public boolean canAppliedToCode(String sourceCode) { + if (sourceCode == null || sourceCode.isEmpty()) { + return false; + } return getMainProgrammingLanguage(sourceCode).orElse(null) instanceof JavaProgrammingLanguage; } @@ -169,12 +174,7 @@ public class JavaIdentifier extends StructuralUnitIdentifier { } private boolean sourceCodeContainsClass(String sourceCode) { - JavaParser parser = new JavaParser(); - ParseResult parseResult = parser.parse(sourceCode); - if (parseResult.getResult().isPresent() && parseResult.getResult().get().findCompilationUnit().isPresent()) { - return parseResult.getResult().get().getTypes().stream().findAny().isPresent(); - } - return false; + return getClasses(sourceCode).size() > 0; } @Override @@ -243,4 +243,14 @@ public class JavaIdentifier extends StructuralUnitIdentifier { } return false; } + + @Override + public List getClasses(String sourceCode) { + JavaParser parser = new JavaParser(); + ParseResult parseResult = parser.parse(sourceCode); + if (parseResult.getResult().isPresent() && parseResult.getResult().get().findCompilationUnit().isPresent()) { + return parseResult.getResult().get().getTypes().stream().map(NodeWithSimpleName::getNameAsString).collect(Collectors.toList()); + } + return new ArrayList<>(); + } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/db/ClassTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/ClassTS.java index 904238c..446f1d7 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/db/ClassTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/ClassTS.java @@ -3,36 +3,64 @@ package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; +import ru.ulstu.extractor.commit.model.Commit; +import ru.ulstu.extractor.commit.service.CommitService; +import ru.ulstu.extractor.gitrepository.model.FileChange; +import ru.ulstu.extractor.gitrepository.model.LineChange; +import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import ru.ulstu.extractor.ts.util.Dummy; -import java.util.Collections; +import java.util.ArrayList; import java.util.List; @Component public class ClassTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; + private final CommitService commitService; private final BranchService branchService; + private final StructuralUnitIdentifier structuralUnitIdentifier; public ClassTS(TimeSeriesService timeSeriesService, - BranchService branchService) { + CommitService commitService, + BranchService branchService, + StructuralUnitIdentifier structuralUnitIdentifier) { this.timeSeriesService = timeSeriesService; + this.commitService = commitService; this.branchService = branchService; + this.structuralUnitIdentifier = structuralUnitIdentifier; } @Override public List getTimeSeries(Branch branch) { - return Collections.singletonList( - new TimeSeries( - String.format("%s %s %s", - branch.getGitRepository().getName(), - branch.getName(), - getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(branch.getGitRepository(), branch.getName()), - getTimeSeriesType(), - Dummy.getDefaultTimeSeries())); + List timeSeriesResult = new ArrayList<>(); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(branch.getGitRepository().getId(), + branch.getName())); + TimeSeries timeSeries = new TimeSeries( + String.format("%s %s %s", + branch.getGitRepository().getName(), + branch.getName(), + getTimeSeriesType().getDescription()), + branchService.findByRepositoryAndName(branch.getGitRepository(), + branch.getName()), + getTimeSeriesType()); + for (Commit commit : commits) { + double value = 0; + for (FileChange fileChange : commit.getFileChanges()) { + for (LineChange lineChange : fileChange.getLineChanges()) { + if (lineChange.getLineTo() != null && !lineChange.getLineTo().isEmpty()) { + value += structuralUnitIdentifier.getClasses(lineChange.getLineTo()).size(); + } + } + } + timeSeries.getValues().add(new TimeSeriesValue(commit.getDate(), value)); + } + if (!timeSeries.getValues().isEmpty()) { + timeSeriesResult.add(timeSeries); + } + return timeSeriesResult; } @Override diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java index 27487b7..6b422e6 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java @@ -4,7 +4,7 @@ public enum TimeSeriesType { COMMITS("Временной ряд коммитов"), AUTHOR_COMMITS("Временной ряд коммитов авторов"), BRANCHES("Временной ряд веток"), - CLASSES("Временной ряд классов"), + CLASSES("Временной ряд измененных классов"), DEPENDENCIES("Временной ряд зависимостей"), ENTITIES("Временной ряд сущностей"), FILES("Временной файлов"), -- 2.34.1 From 28697b68aa4f7f52849753cd3a1239a9cec05b3b Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 12 May 2023 11:32:23 +0400 Subject: [PATCH 103/110] test ts add --- .../extractor/ts/service/ScheduledTimeSeriesService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java index 501184a..fb41395 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java @@ -22,13 +22,13 @@ public class ScheduledTimeSeriesService { this.branchService = branchService; } - @Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara") + @Scheduled(cron = "0 */5 * * * *", zone = "Europe/Samara") public void addTimeSeriesPoints() { - log.debug("Старт добавления новых точек временного ряда"); + log.info("Старт добавления новых точек временного ряда"); List branches = branchService.findAll(); branches.forEach(branch -> { scheduledTimeSeriesCreators.forEach(creator -> creator.addTimeSeriesValue(branch)); }); - log.debug("Завершение добавления новых точек временного ряда"); + log.info("Завершение добавления новых точек временного ряда"); } } -- 2.34.1 From 6377e187794d2b5728bb0981e330323f141fa2c1 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 12 May 2023 11:54:03 +0400 Subject: [PATCH 104/110] test ts add --- .../ulstu/extractor/ts/service/ScheduledTimeSeriesService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java index fb41395..d3fe476 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java @@ -22,7 +22,7 @@ public class ScheduledTimeSeriesService { this.branchService = branchService; } - @Scheduled(cron = "0 */5 * * * *", zone = "Europe/Samara") + @Scheduled(cron = "0 0 8 * * *") public void addTimeSeriesPoints() { log.info("Старт добавления новых точек временного ряда"); List branches = branchService.findAll(); -- 2.34.1 From c5cb94f009e84e37e7259db69c99fe42e2ebc6e6 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 9 Jun 2023 06:39:27 +0400 Subject: [PATCH 105/110] wrong action --- .../java/ru/ulstu/extractor/branch/service/BranchService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java index 2b68c45..e8e147d 100644 --- a/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java +++ b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java @@ -90,7 +90,7 @@ public class BranchService { public List findAllValid() { return findAll() .stream() - .filter(timeSeriesService::isBranchContainsAllTimeSeries) + //.filter(timeSeriesService::isBranchContainsAllTimeSeries) .collect(Collectors.toList()); } } -- 2.34.1 From 5a97d107c39a884a353820e69849d35b28a322b3 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 10 May 2024 11:43:40 +0400 Subject: [PATCH 106/110] #96 -- Add db records for generated time series --- .../ru/ulstu/extractor/branch/model/Branch.java | 10 ++-------- .../controler/RepositoryController.java | 13 +++++++++++-- .../controler/StatisticController.java | 5 ++++- .../gitrepository/model/GitRepository.java | 2 ++ .../controller/TimeSeriesMarkupController.java | 15 ++++++++++++--- .../ts/service/ScheduledTimeSeriesService.java | 8 +++++++- .../db/changelog-20230302_210000-schema.xml | 11 +++++++++++ 7 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/branch/model/Branch.java b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java index 6d63841..7c428d0 100644 --- a/src/main/java/ru/ulstu/extractor/branch/model/Branch.java +++ b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java @@ -6,14 +6,7 @@ import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.core.BaseEntity; import ru.ulstu.extractor.gitrepository.model.GitRepository; -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.ManyToOne; -import javax.persistence.OneToMany; +import javax.persistence.*; import java.util.ArrayList; import java.util.List; @@ -21,6 +14,7 @@ import static ru.ulstu.extractor.branch.model.IndexingStatus.EMPTY; @Entity public class Branch extends BaseEntity { + public static Integer GENERATED_BRANCH_ID = 1; private String name; @ManyToOne diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java index d27ee14..cefbe4d 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java @@ -7,8 +7,11 @@ import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.extractor.gitrepository.repository.GitRepositoryRepository; import springfox.documentation.annotations.ApiIgnore; +import java.util.stream.Collectors; + import static ru.ulstu.extractor.core.Route.DELETE_INDEXED_REPOSITORY; import static ru.ulstu.extractor.core.Route.LIST_INDEXED_REPOSITORIES; +import static ru.ulstu.extractor.gitrepository.model.GitRepository.GENERATED_REPOSITORY_ID; @Controller @ApiIgnore @@ -21,7 +24,10 @@ public class RepositoryController { @GetMapping(LIST_INDEXED_REPOSITORIES) public String indexNewRepo(Model model) { - model.addAttribute("repositories", gitRepositoryRepository.findAll()); + model.addAttribute("repositories", gitRepositoryRepository.findAll() + .stream() + .filter(r -> !r.getId().equals(GENERATED_REPOSITORY_ID)) + .collect(Collectors.toList())); return LIST_INDEXED_REPOSITORIES; } @@ -29,7 +35,10 @@ public class RepositoryController { public String deleteRepo(Model model, @RequestParam Integer id) { gitRepositoryRepository.deleteById(id); - model.addAttribute("repositories", gitRepositoryRepository.findAll()); + model.addAttribute("repositories", gitRepositoryRepository.findAll() + .stream() + .filter(r -> !r.getId().equals(GENERATED_REPOSITORY_ID)) + .collect(Collectors.toList())); return "redirect:/" + LIST_INDEXED_REPOSITORIES; } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java index 63e75d8..766d3a7 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import static ru.ulstu.extractor.branch.model.Branch.GENERATED_BRANCH_ID; import static ru.ulstu.extractor.core.Route.STATISTIC; @Controller @@ -60,7 +61,9 @@ public class StatisticController { filterForm.setEntity(entity.orElse(null)); model.addAttribute("filterForm", filterForm); model.addAttribute("entityPresent", filteringService.getEntityPresent()); - model.addAttribute("branches", branchService.findAll()); + model.addAttribute("branches", branchService.findAll().stream() + .filter(r -> !r.getId().equals(GENERATED_BRANCH_ID)) + .collect(Collectors.toList())); model.addAttribute("authors", filteringService.getRepositoryAuthors(branchId.orElse(null))); return STATISTIC; } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java index f4707c7..8017241 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java @@ -7,6 +7,8 @@ import javax.persistence.Entity; @Entity public class GitRepository extends BaseEntity { + + public static Integer GENERATED_REPOSITORY_ID = 1; private String url; private String repositoryId; diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index 3aef93a..ad67a0d 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -14,6 +14,9 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; import java.util.List; +import java.util.stream.Collectors; + +import static ru.ulstu.extractor.branch.model.Branch.GENERATED_BRANCH_ID; @Controller @ApiIgnore @@ -32,14 +35,18 @@ public class TimeSeriesMarkupController { @GetMapping("time-series-markup") public String markupTs(Model model) { - model.addAttribute("branches", branchService.findAllValid()); + model.addAttribute("branches", branchService.findAllValid().stream() + .filter(r -> !r.getId().equals(GENERATED_BRANCH_ID)) + .collect(Collectors.toList())); model.addAttribute("markupForm", new MarkupForm()); return "markup"; } @PostMapping("time-series-markup") public String filter(Model model, @ModelAttribute MarkupForm markupForm) { - model.addAttribute("branches", branchService.findAllValid()); + model.addAttribute("branches", branchService.findAllValid().stream() + .filter(r -> !r.getId().equals(GENERATED_BRANCH_ID)) + .collect(Collectors.toList())); if (markupForm != null && markupForm.getBranchId() != null) { List tss = markupService.getTimeSeriesForMarkup( timeSeriesService.getGroupedTendencies( @@ -56,7 +63,9 @@ public class TimeSeriesMarkupController { @PostMapping(Route.ADD_MARKUP) public String addMarkups(Model model, @ModelAttribute MarkupForm markupForm) { - model.addAttribute("branches", branchService.findAllValid()); + model.addAttribute("branches", branchService.findAllValid().stream() + .filter(r -> !r.getId().equals(GENERATED_BRANCH_ID)) + .collect(Collectors.toList())); if (markupForm != null && markupForm.getBranchId() != null) { List tss = markupService.getTimeSeriesForMarkup( timeSeriesService.getGroupedTendencies( diff --git a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java index d3fe476..5b961f9 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java @@ -9,6 +9,9 @@ import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.ts.creator.scheduled.ScheduledTimeSeriesCreator; import java.util.List; +import java.util.stream.Collectors; + +import static ru.ulstu.extractor.branch.model.Branch.GENERATED_BRANCH_ID; @Service public class ScheduledTimeSeriesService { @@ -25,7 +28,10 @@ public class ScheduledTimeSeriesService { @Scheduled(cron = "0 0 8 * * *") public void addTimeSeriesPoints() { log.info("Старт добавления новых точек временного ряда"); - List branches = branchService.findAll(); + List branches = branchService.findAll() + .stream() + .filter(b -> !b.getId().equals(GENERATED_BRANCH_ID)) + .collect(Collectors.toList()); branches.forEach(branch -> { scheduledTimeSeriesCreators.forEach(creator -> creator.addTimeSeriesValue(branch)); }); diff --git a/src/main/resources/db/changelog-20230302_210000-schema.xml b/src/main/resources/db/changelog-20230302_210000-schema.xml index 670658e..135ac55 100644 --- a/src/main/resources/db/changelog-20230302_210000-schema.xml +++ b/src/main/resources/db/changelog-20230302_210000-schema.xml @@ -46,4 +46,15 @@ + + + 1 + Генерированный репозиторий + + + 1 + Сгенерированные показатели + 1 + + \ No newline at end of file -- 2.34.1 From e5d5d7312be7be49aca2f437aeb5583baad595c8 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 10 May 2024 12:11:17 +0400 Subject: [PATCH 107/110] #96 -- Add generation page --- .../java/ru/ulstu/extractor/core/Route.java | 6 +++ .../controller/GenerationController.java | 35 +++++++++++++ .../generation/model/GenerationForm.java | 50 +++++++++++++++++++ .../generation/service/GenerationService.java | 18 +++++++ src/main/resources/templates/assessments.html | 2 +- src/main/resources/templates/default.html | 3 ++ src/main/resources/templates/generation.html | 50 +++++++++++++++++++ 7 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/ulstu/extractor/generation/controller/GenerationController.java create mode 100644 src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java create mode 100644 src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java create mode 100644 src/main/resources/templates/generation.html diff --git a/src/main/java/ru/ulstu/extractor/core/Route.java b/src/main/java/ru/ulstu/extractor/core/Route.java index 9c56182..0b2fe3f 100644 --- a/src/main/java/ru/ulstu/extractor/core/Route.java +++ b/src/main/java/ru/ulstu/extractor/core/Route.java @@ -18,6 +18,8 @@ public class Route { public static final String DELETE_RULE = "deleteRule"; public static final String ADD_MARKUP = "addMarkup"; + public static final String GENERATION = "generation"; + public static String getLIST_INDEXED_REPOSITORIES() { return LIST_INDEXED_REPOSITORIES; } @@ -45,4 +47,8 @@ public class Route { public static String getADD_MARKUP() { return ADD_MARKUP; } + + public static String getGENERATION() { + return GENERATION; + } } diff --git a/src/main/java/ru/ulstu/extractor/generation/controller/GenerationController.java b/src/main/java/ru/ulstu/extractor/generation/controller/GenerationController.java new file mode 100644 index 0000000..fcb9dc4 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/generation/controller/GenerationController.java @@ -0,0 +1,35 @@ +package ru.ulstu.extractor.generation.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import ru.ulstu.extractor.generation.model.GenerationForm; +import ru.ulstu.extractor.generation.service.GenerationService; +import springfox.documentation.annotations.ApiIgnore; + +import static ru.ulstu.extractor.core.Route.GENERATION; + +@Controller +@ApiIgnore +public class GenerationController { + private final GenerationService generationService; + + public GenerationController(GenerationService generationService) { + this.generationService = generationService; + } + + @GetMapping(GENERATION) + public String getGenerationsPage(Model model) { + model.addAttribute("generationForm", new GenerationForm()); + return GENERATION; + } + + @PostMapping(GENERATION) + public String setGenerationParams(Model model, @ModelAttribute GenerationForm generationForm) { + model.addAttribute("generationForm", generationForm); + generationService.generate(generationForm); + return GENERATION; + } +} diff --git a/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java b/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java new file mode 100644 index 0000000..99b19f3 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java @@ -0,0 +1,50 @@ +package ru.ulstu.extractor.generation.model; + +public class GenerationForm { + private int tsLength; + private int min; + private int max; + private int base; + + public int getTsLength() { + return tsLength; + } + + public void setTsLength(int tsLength) { + this.tsLength = tsLength; + } + + public int getMin() { + return min; + } + + public void setMin(int min) { + this.min = min; + } + + public int getMax() { + return max; + } + + public void setMax(int max) { + this.max = max; + } + + public int getBase() { + return base; + } + + public void setBase(int base) { + this.base = base; + } + + @Override + public String toString() { + return "GenerationForm{" + + "tsLength=" + tsLength + + ", min=" + min + + ", max=" + max + + ", base=" + base + + '}'; + } +} diff --git a/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java new file mode 100644 index 0000000..0a50824 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java @@ -0,0 +1,18 @@ +package ru.ulstu.extractor.generation.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.generation.model.GenerationForm; +import ru.ulstu.extractor.ts.service.TimeSeriesService; + +@Service +public class GenerationService { + private final TimeSeriesService timeSeriesService; + + public GenerationService(TimeSeriesService timeSeriesService) { + this.timeSeriesService = timeSeriesService; + } + + public void generate(GenerationForm generationForm) { + System.out.print(generationForm); + } +} diff --git a/src/main/resources/templates/assessments.html b/src/main/resources/templates/assessments.html index d9a3721..aae7805 100644 --- a/src/main/resources/templates/assessments.html +++ b/src/main/resources/templates/assessments.html @@ -3,7 +3,7 @@ xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml" layout:decorate="~{default}"> - Простая обработка формы на Spring MVC + Оценка репозиториев
diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index aa66144..7303d7e 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -38,6 +38,9 @@ + diff --git a/src/main/resources/templates/generation.html b/src/main/resources/templates/generation.html new file mode 100644 index 0000000..4174f8b --- /dev/null +++ b/src/main/resources/templates/generation.html @@ -0,0 +1,50 @@ + + + + Генерация + + +
+
+
+
+ Длина временных рядов +
+
+ +
+
+
+
+ Минимум +
+
+ +
+
+
+
+ Максимум +
+
+ +
+
+
+
+ Основное значение +
+
+ +
+
+
+
+ +
+
+
+
+ -- 2.34.1 From eb37dd0c8ce5c89a5a5c68a6a7cf74b6c4fa352b Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 10 May 2024 23:12:22 +0400 Subject: [PATCH 108/110] #96 -- Add time series generation --- .../generation/model/GenerationForm.java | 24 +++++++++++------ .../generation/service/GenerationService.java | 26 +++++++++++++++++-- .../ru/ulstu/extractor/ts/util/DateUtils.java | 9 ++++++- .../ru/ulstu/extractor/ts/util/Dummy.java | 10 +++---- src/main/resources/templates/generation.html | 16 ++++++++++++ 5 files changed, 69 insertions(+), 16 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java b/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java index 99b19f3..8571d6a 100644 --- a/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java +++ b/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java @@ -5,6 +5,8 @@ public class GenerationForm { private int min; private int max; private int base; + private int baseTendency; + private int tendencyDynamic; public int getTsLength() { return tsLength; @@ -38,13 +40,19 @@ public class GenerationForm { this.base = base; } - @Override - public String toString() { - return "GenerationForm{" + - "tsLength=" + tsLength + - ", min=" + min + - ", max=" + max + - ", base=" + base + - '}'; + public int getBaseTendency() { + return baseTendency; + } + + public void setBaseTendency(int baseTendency) { + this.baseTendency = baseTendency; + } + + public int getTendencyDynamic() { + return tendencyDynamic; + } + + public void setTendencyDynamic(int tendencyDynamic) { + this.tendencyDynamic = tendencyDynamic; } } diff --git a/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java index 0a50824..43eb10d 100644 --- a/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java +++ b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java @@ -1,18 +1,40 @@ package ru.ulstu.extractor.generation.service; import org.springframework.stereotype.Service; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.generation.model.GenerationForm; +import ru.ulstu.extractor.ts.model.TimeSeriesType; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; +import ru.ulstu.extractor.ts.util.DateUtils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; @Service public class GenerationService { private final TimeSeriesService timeSeriesService; + private final BranchService branchService; - public GenerationService(TimeSeriesService timeSeriesService) { + public GenerationService(TimeSeriesService timeSeriesService, + BranchService branchService) { this.timeSeriesService = timeSeriesService; + this.branchService = branchService; } public void generate(GenerationForm generationForm) { - System.out.print(generationForm); + Branch branch = branchService.findByBranchId(Branch.GENERATED_BRANCH_ID).orElseThrow(); + Date startDate = DateUtils.addDays(-generationForm.getTsLength()); + Arrays.stream(TimeSeriesType.values()).forEach(tsType -> { + List tsValues = new ArrayList<>(); + for (int i = 0; i < generationForm.getTsLength(); i++) { + tsValues.add(new TimeSeriesValue(DateUtils.addDays(startDate, i), (double) i)); + } + final String tsName = "Генерированный " + tsType.getDescription(); + timeSeriesService.save(tsName, branch, tsType, tsValues); + }); } } diff --git a/src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java b/src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java index 773e9e0..d998853 100644 --- a/src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java +++ b/src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java @@ -5,9 +5,16 @@ import java.util.Date; import java.util.GregorianCalendar; public class DateUtils { - public static Date addMonths(int amount) { + public static Date addDays(int amount) { Calendar c = GregorianCalendar.getInstance(); c.add(Calendar.DAY_OF_MONTH, amount); return c.getTime(); } + + public static Date addDays(Date startDate, int amount) { + Calendar c = GregorianCalendar.getInstance(); + c.setTime(startDate); + 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 index 61b0389..59fcd52 100644 --- a/src/main/java/ru/ulstu/extractor/ts/util/Dummy.java +++ b/src/main/java/ru/ulstu/extractor/ts/util/Dummy.java @@ -6,10 +6,10 @@ 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)); + return List.of(new TimeSeriesValue(DateUtils.addDays(-5), 1.0), + new TimeSeriesValue(DateUtils.addDays(-4), 2.0), + new TimeSeriesValue(DateUtils.addDays(-3), 3.0), + new TimeSeriesValue(DateUtils.addDays(-2), 4.0), + new TimeSeriesValue(DateUtils.addDays(-1), 5.0)); } } diff --git a/src/main/resources/templates/generation.html b/src/main/resources/templates/generation.html index 4174f8b..f21f39d 100644 --- a/src/main/resources/templates/generation.html +++ b/src/main/resources/templates/generation.html @@ -40,6 +40,22 @@
+
+
+ Основная тенденция +
+
+ +
+
+
+
+ Динамика тенденции +
+
+ +
+
-- 2.34.1 From 8bcdff3ba15e6a810e2c9b67bc64368764bebd22 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 13 May 2024 00:07:41 +0400 Subject: [PATCH 109/110] #96 -- Fix time series generation --- .../generation/service/GenerationService.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java index 43eb10d..0b168cd 100644 --- a/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java +++ b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java @@ -18,6 +18,7 @@ import java.util.List; public class GenerationService { private final TimeSeriesService timeSeriesService; private final BranchService branchService; + private final static double RANDOM_WEIGHT = 0.1; public GenerationService(TimeSeriesService timeSeriesService, BranchService branchService) { @@ -31,10 +32,35 @@ public class GenerationService { Arrays.stream(TimeSeriesType.values()).forEach(tsType -> { List tsValues = new ArrayList<>(); for (int i = 0; i < generationForm.getTsLength(); i++) { - tsValues.add(new TimeSeriesValue(DateUtils.addDays(startDate, i), (double) i)); + tsValues.add(new TimeSeriesValue(DateUtils.addDays(startDate, i), + getNextAdditiveValue(tsValues, generationForm))); } final String tsName = "Генерированный " + tsType.getDescription(); timeSeriesService.save(tsName, branch, tsType, tsValues); }); } + + private double getNextAdditiveValue(List timeSeriesValues, GenerationForm generationForm) { + double newValue; + int maxTryCount = 10; + do { + if (timeSeriesValues.isEmpty()) { + if (generationForm.getBaseTendency() > 0) { + newValue = 0.1 * Math.random() * (generationForm.getMax() - generationForm.getMin()); + } else { + newValue = generationForm.getMax() - 0.1 * Math.random() * (generationForm.getMax() - generationForm.getMin()); + } + } else { + newValue = timeSeriesValues.get(timeSeriesValues.size() - 1).getValue() + + Math.random() * generationForm.getBaseTendency() + * ((generationForm.getMax() - generationForm.getMin()) / generationForm.getTsLength()) + * generationForm.getTendencyDynamic() + + RANDOM_WEIGHT * (Math.random() - 0.5) * (generationForm.getMax() - generationForm.getMin()); + } + maxTryCount--; + } while (((newValue <= generationForm.getMin()) + || (newValue >= generationForm.getMax())) + && (maxTryCount > 0)); + return newValue; + } } -- 2.34.1 From 1192201a69cfd121d47197fd903b6674695bec71 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 13 May 2024 00:52:04 +0400 Subject: [PATCH 110/110] #96 -- Fix time series generation --- .../generation/model/GenerationForm.java | 39 ++++++++++++------- .../generation/service/GenerationService.java | 15 +++---- src/main/resources/templates/generation.html | 8 ++++ 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java b/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java index 8571d6a..e1e2c69 100644 --- a/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java +++ b/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java @@ -2,11 +2,12 @@ package ru.ulstu.extractor.generation.model; public class GenerationForm { private int tsLength; - private int min; - private int max; - private int base; - private int baseTendency; - private int tendencyDynamic; + private double min; + private double max; + private double base; + private double baseTendency; + private double tendencyDynamic; + private double randomWeight; public int getTsLength() { return tsLength; @@ -16,43 +17,51 @@ public class GenerationForm { this.tsLength = tsLength; } - public int getMin() { + public double getMin() { return min; } - public void setMin(int min) { + public void setMin(double min) { this.min = min; } - public int getMax() { + public double getMax() { return max; } - public void setMax(int max) { + public void setMax(double max) { this.max = max; } - public int getBase() { + public double getBase() { return base; } - public void setBase(int base) { + public void setBase(double base) { this.base = base; } - public int getBaseTendency() { + public double getBaseTendency() { return baseTendency; } - public void setBaseTendency(int baseTendency) { + public void setBaseTendency(double baseTendency) { this.baseTendency = baseTendency; } - public int getTendencyDynamic() { + public double getTendencyDynamic() { return tendencyDynamic; } - public void setTendencyDynamic(int tendencyDynamic) { + public void setTendencyDynamic(double tendencyDynamic) { this.tendencyDynamic = tendencyDynamic; } + + public double getRandomWeight() { + return randomWeight; + } + + public void setRandomWeight(double randomWeight) { + this.randomWeight = randomWeight; + } } diff --git a/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java index 0b168cd..34a160d 100644 --- a/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java +++ b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java @@ -18,7 +18,6 @@ import java.util.List; public class GenerationService { private final TimeSeriesService timeSeriesService; private final BranchService branchService; - private final static double RANDOM_WEIGHT = 0.1; public GenerationService(TimeSeriesService timeSeriesService, BranchService branchService) { @@ -44,18 +43,20 @@ public class GenerationService { double newValue; int maxTryCount = 10; do { + double oneStepDiff = generationForm.getRandomWeight() * (Math.random() - 0.5) * (generationForm.getMax() - generationForm.getMin()) / (generationForm.getTsLength() + 10); if (timeSeriesValues.isEmpty()) { if (generationForm.getBaseTendency() > 0) { - newValue = 0.1 * Math.random() * (generationForm.getMax() - generationForm.getMin()); + newValue = 0.1 * (generationForm.getRandomWeight() > 0.0 ? oneStepDiff : 1.0) * (generationForm.getMax() - generationForm.getMin()); + } else if (generationForm.getBaseTendency() < 0) { + newValue = generationForm.getMax() - 0.1 * (generationForm.getRandomWeight() > 0.0 ? oneStepDiff : 1.0) * (generationForm.getMax() - generationForm.getMin()); } else { - newValue = generationForm.getMax() - 0.1 * Math.random() * (generationForm.getMax() - generationForm.getMin()); + newValue = generationForm.getBase(); } } else { newValue = timeSeriesValues.get(timeSeriesValues.size() - 1).getValue() - + Math.random() * generationForm.getBaseTendency() - * ((generationForm.getMax() - generationForm.getMin()) / generationForm.getTsLength()) - * generationForm.getTendencyDynamic() - + RANDOM_WEIGHT * (Math.random() - 0.5) * (generationForm.getMax() - generationForm.getMin()); + + (generationForm.getRandomWeight() > 0.0 ? oneStepDiff : 1.0) * generationForm.getBaseTendency() + * ((generationForm.getMax() - generationForm.getMin()) / (generationForm.getTsLength() + 10)) + * generationForm.getTendencyDynamic(); } maxTryCount--; } while (((newValue <= generationForm.getMin()) diff --git a/src/main/resources/templates/generation.html b/src/main/resources/templates/generation.html index f21f39d..ef7fd1d 100644 --- a/src/main/resources/templates/generation.html +++ b/src/main/resources/templates/generation.html @@ -56,6 +56,14 @@
+
+
+ Величина шума +
+
+ +
+
-- 2.34.1