Compare commits
4 Commits
80904e6221
...
394873f63b
Author | SHA1 | Date | |
---|---|---|---|
394873f63b | |||
2d374e1e20 | |||
941a251536 | |||
9e43175704 |
@ -27,7 +27,7 @@ public class AssessmentController {
|
|||||||
|
|
||||||
@GetMapping(ASSESSMENTS)
|
@GetMapping(ASSESSMENTS)
|
||||||
public String getAssessments(Model model, @RequestParam Optional<Integer> branchId) {
|
public String getAssessments(Model model, @RequestParam Optional<Integer> branchId) {
|
||||||
model.addAttribute("branches", branchService.findAll());
|
model.addAttribute("branches", branchService.findAllValid());
|
||||||
if (branchId.isPresent()) {
|
if (branchId.isPresent()) {
|
||||||
model.addAttribute("assessments", assessmentService.getAssessmentsByForecastTendencies(branchId.get()));
|
model.addAttribute("assessments", assessmentService.getAssessmentsByForecastTendencies(branchId.get()));
|
||||||
model.addAttribute("filterBranchForm", new FilterBranchForm(branchId.get()));
|
model.addAttribute("filterBranchForm", new FilterBranchForm(branchId.get()));
|
||||||
|
@ -54,9 +54,7 @@ public class AssessmentService {
|
|||||||
|
|
||||||
private List<Assessment> getSingleAssessmentByTimeSeriesTendencies(List<DbRule> dbRules, List<TimeSeries> timeSeries) throws AssessmentException {
|
private List<Assessment> getSingleAssessmentByTimeSeriesTendencies(List<DbRule> dbRules, List<TimeSeries> timeSeries) throws AssessmentException {
|
||||||
Map<String, Double> variableValues = new HashMap<>();
|
Map<String, Double> variableValues = new HashMap<>();
|
||||||
timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(),
|
timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService.getLastTimeSeriesTendency(ts)));
|
||||||
timeSeriesService.getLastTimeSeriesTendency(ts)
|
|
||||||
.orElseThrow(() -> new AssessmentException(""))));
|
|
||||||
return fuzzyInferenceService.getFuzzyInference(dbRules,
|
return fuzzyInferenceService.getFuzzyInference(dbRules,
|
||||||
antecedentValueService.getList(),
|
antecedentValueService.getList(),
|
||||||
variableValues,
|
variableValues,
|
||||||
@ -74,8 +72,7 @@ public class AssessmentService {
|
|||||||
.filter(ts -> ts.getTimeSeriesType() == dbRule.getFirstAntecedent()
|
.filter(ts -> ts.getTimeSeriesType() == dbRule.getFirstAntecedent()
|
||||||
|| ts.getTimeSeriesType() == dbRule.getSecondAntecedent())
|
|| ts.getTimeSeriesType() == dbRule.getSecondAntecedent())
|
||||||
.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())));
|
|
||||||
return fuzzyInferenceService.getFuzzyInference(List.of(dbRule),
|
return fuzzyInferenceService.getFuzzyInference(List.of(dbRule),
|
||||||
antecedentValueService.getList(),
|
antecedentValueService.getList(),
|
||||||
variableValues,
|
variableValues,
|
||||||
|
@ -16,6 +16,7 @@ import ru.ulstu.extractor.commit.model.Commit;
|
|||||||
import ru.ulstu.extractor.commit.service.CommitService;
|
import ru.ulstu.extractor.commit.service.CommitService;
|
||||||
import ru.ulstu.extractor.core.BaseEntity;
|
import ru.ulstu.extractor.core.BaseEntity;
|
||||||
import ru.ulstu.extractor.gitrepository.model.GitRepository;
|
import ru.ulstu.extractor.gitrepository.model.GitRepository;
|
||||||
|
import ru.ulstu.extractor.ts.service.TimeSeriesService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -26,11 +27,14 @@ public class BranchService {
|
|||||||
private final static Logger LOG = LoggerFactory.getLogger(BranchService.class);
|
private final static Logger LOG = LoggerFactory.getLogger(BranchService.class);
|
||||||
private final BranchRepository branchRepository;
|
private final BranchRepository branchRepository;
|
||||||
private final CommitService commitService;
|
private final CommitService commitService;
|
||||||
|
private final TimeSeriesService timeSeriesService;
|
||||||
|
|
||||||
public BranchService(BranchRepository branchRepository,
|
public BranchService(BranchRepository branchRepository,
|
||||||
CommitService commitService) {
|
CommitService commitService,
|
||||||
|
TimeSeriesService timeSeriesService) {
|
||||||
this.branchRepository = branchRepository;
|
this.branchRepository = branchRepository;
|
||||||
this.commitService = commitService;
|
this.commitService = commitService;
|
||||||
|
this.timeSeriesService = timeSeriesService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@ -87,4 +91,11 @@ public class BranchService {
|
|||||||
branch.setIndexingStatus(indexingStatus);
|
branch.setIndexingStatus(indexingStatus);
|
||||||
return branchRepository.save(branch);
|
return branchRepository.save(branch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Branch> findAllValid() {
|
||||||
|
return findAll()
|
||||||
|
.stream()
|
||||||
|
.filter(timeSeriesService::isBranchContainsAllTimeSeries)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
package ru.ulstu.extractor.ts.service;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
@ -28,10 +23,13 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class TimeSeriesService {
|
public class TimeSeriesService {
|
||||||
private final static Logger LOG = LoggerFactory.getLogger(TimeSeriesService.class);
|
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 TimeSeriesRepository timeSeriesRepository;
|
||||||
private final TimeSeriesValueRepository timeSeriesValueRepository;
|
private final TimeSeriesValueRepository timeSeriesValueRepository;
|
||||||
private final TimeSeriesDateMapper.TimeSeriesInterval timeSeriesInterval = TimeSeriesDateMapper.TimeSeriesInterval.HOUR;
|
private final TimeSeriesDateMapper.TimeSeriesInterval timeSeriesInterval = TimeSeriesDateMapper.TimeSeriesInterval.HOUR;
|
||||||
@ -127,17 +125,24 @@ public class TimeSeriesService {
|
|||||||
return timeSeriesRepository.getTimeSeriesByBranchId(branchId);
|
return timeSeriesRepository.getTimeSeriesByBranchId(branchId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Double> getLastTimeSeriesTendency(TimeSeries ts) {
|
public double getLastTimeSeriesTendency(TimeSeries ts) {
|
||||||
if (ts != null && ts.getValues().size() > 5) {
|
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(ts)));
|
||||||
LOG.debug("Успешно отправлен на сервис сглаживания");
|
LOG.debug("Успешно отправлен на сервис сглаживания");
|
||||||
if (response.has("response") && response.getString("response").equals("empty")) {
|
if (response.has("response") && response.getString("response").equals("empty")) {
|
||||||
return Optional.empty();
|
return DEFAULT_TIME_SERIES_TENDENCY;
|
||||||
}
|
}
|
||||||
JSONArray jsonArray = response.getJSONObject("timeSeries").getJSONArray("values");
|
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> timeSeries = getByBranch(b.getId());
|
||||||
|
return Stream.of(TimeSeriesType.values()).allMatch(type -> timeSeries
|
||||||
|
.stream()
|
||||||
|
.anyMatch(ts -> type == ts.getTimeSeriesType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TimeSeries> getGroupedTendencies(List<TimeSeries> tsList) {
|
public List<TimeSeries> getGroupedTendencies(List<TimeSeries> tsList) {
|
||||||
|
Loading…
Reference in New Issue
Block a user