WIP: страницы для правил #62

Closed
Ghost wants to merge 132 commits from master into 61-rules-pages
7 changed files with 67 additions and 7 deletions
Showing only changes of commit 71652c7b79 - Show all commits

View File

@ -7,15 +7,18 @@ import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import ru.ulstu.extractor.gitrepository.service.IndexService; import ru.ulstu.extractor.gitrepository.service.IndexService;
import ru.ulstu.extractor.rule.service.DbRuleService;
@SpringBootApplication @SpringBootApplication
@EnableScheduling @EnableScheduling
@EnableAsync @EnableAsync
public class GitExtractorApplication { public class GitExtractorApplication {
private final IndexService indexService; private final IndexService indexService;
private final DbRuleService dbRuleService;
public GitExtractorApplication(IndexService indexService) { public GitExtractorApplication(IndexService indexService, DbRuleService dbRuleService) {
this.indexService = indexService; this.indexService = indexService;
this.dbRuleService = dbRuleService;
} }
public static void main(String[] args) { public static void main(String[] args) {
@ -25,5 +28,6 @@ public class GitExtractorApplication {
@EventListener(ApplicationReadyEvent.class) @EventListener(ApplicationReadyEvent.class)
public void doSomethingAfterStartup() { public void doSomethingAfterStartup() {
indexService.indexFailedBranchesOnStart(); indexService.indexFailedBranchesOnStart();
//dbRuleService.generateRulesFromMarkup();
} }
} }

View File

@ -71,8 +71,9 @@ public class AssessmentService {
Map<String, Double> variableValues = new HashMap<>(); Map<String, Double> variableValues = new HashMap<>();
timeSeries timeSeries
.stream() .stream()
.filter(ts -> ts.getTimeSeriesType() == dbRule.getFirstAntecedent() .filter(ts -> (ts.getTimeSeriesType() == dbRule.getFirstAntecedent()
|| ts.getTimeSeriesType() == dbRule.getSecondAntecedent()) || ts.getTimeSeriesType() == dbRule.getSecondAntecedent())
&& ts.getValues().size() > 0)
.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService .forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService
.getLastTimeSeriesTendency(ts) .getLastTimeSeriesTendency(ts)
.orElse(ts.getValues().get(ts.getValues().size() - 1).getValue()))); .orElse(ts.getValues().get(ts.getValues().size() - 1).getValue())));

View File

@ -8,6 +8,8 @@ import ru.ulstu.extractor.markup.repository.MarkupRepository;
import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeries;
import ru.ulstu.extractor.ts.service.TimeSeriesService; import ru.ulstu.extractor.ts.service.TimeSeriesService;
import java.util.List;
@Service @Service
public class MarkupService { public class MarkupService {
private final MarkupRepository markupRepository; private final MarkupRepository markupRepository;
@ -26,4 +28,8 @@ public class MarkupService {
markupRepository.save(new Markup(timeSeries, markupRow.getMarkup())); markupRepository.save(new Markup(timeSeries, markupRow.getMarkup()));
}); });
} }
public List<Markup> findAll() {
return markupRepository.findAll();
}
} }

View File

@ -11,8 +11,7 @@ public class AntecedentValue extends BaseEntity {
public AntecedentValue() { public AntecedentValue() {
} }
public AntecedentValue(Integer id, String antecedentValue) { public AntecedentValue(String antecedentValue) {
this.setId(id);
this.antecedentValue = antecedentValue; this.antecedentValue = antecedentValue;
} }

View File

@ -4,5 +4,8 @@ package ru.ulstu.extractor.rule.repository;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import ru.ulstu.extractor.rule.model.AntecedentValue; import ru.ulstu.extractor.rule.model.AntecedentValue;
import java.util.Optional;
public interface AntecedentValueRepository extends JpaRepository<AntecedentValue, Integer> { public interface AntecedentValueRepository extends JpaRepository<AntecedentValue, Integer> {
Optional<AntecedentValue> findByAntecedentValue(String antecedentValue);
} }

View File

@ -22,4 +22,9 @@ public class AntecedentValueService {
return antecedentValueRepository.findById(antecedentValueId) return antecedentValueRepository.findById(antecedentValueId)
.orElseThrow(() -> new RuntimeException("Antecedent value not found by id " + 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));
}
} }

View File

@ -1,10 +1,15 @@
package ru.ulstu.extractor.rule.service; package ru.ulstu.extractor.rule.service;
import org.springframework.stereotype.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.AddRuleForm;
import ru.ulstu.extractor.rule.model.AntecedentValue;
import ru.ulstu.extractor.rule.model.DbRule; import ru.ulstu.extractor.rule.model.DbRule;
import ru.ulstu.extractor.rule.repository.RuleRepository; import ru.ulstu.extractor.rule.repository.RuleRepository;
import ru.ulstu.extractor.ts.model.TimeSeriesType; 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.service.TimeSeriesService;
import java.util.List; import java.util.List;
@ -13,15 +18,16 @@ import java.util.stream.Collectors;
@Service @Service
public class DbRuleService { public class DbRuleService {
private final RuleRepository ruleRepository; private final RuleRepository ruleRepository;
private final TimeSeriesService timeSeriesService;
private final AntecedentValueService antecedentValueService; private final AntecedentValueService antecedentValueService;
private final MarkupService markupService;
public DbRuleService(RuleRepository ruleRepository, public DbRuleService(RuleRepository ruleRepository,
TimeSeriesService timeSeriesService, TimeSeriesService timeSeriesService,
AntecedentValueService antecedentValueService) { AntecedentValueService antecedentValueService,
MarkupService markupService) {
this.ruleRepository = ruleRepository; this.ruleRepository = ruleRepository;
this.timeSeriesService = timeSeriesService;
this.antecedentValueService = antecedentValueService; this.antecedentValueService = antecedentValueService;
this.markupService = markupService;
} }
public List<DbRule> getList() { public List<DbRule> getList() {
@ -65,4 +71,40 @@ public class DbRuleService {
public List<String> getConsequentList() { public List<String> getConsequentList() {
return ruleRepository.findAll().stream().map(DbRule::getConsequent).collect(Collectors.toList()); return ruleRepository.findAll().stream().map(DbRule::getConsequent).collect(Collectors.toList());
} }
@Transactional
public void generateRulesFromMarkup() {
List<Markup> markups = markupService.findAll();
for (Markup markup1 : markups) {
for (Markup markup2 : markups) {
if (!markup1.equals(markup2)) {
List<TimeSeriesValue> values1 = markup1.getTimeSeries().getValues();
for (int i = 1; i < values1.size(); i++) {
List<TimeSeriesValue> 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);
}
} }