#72 -- add time series type

This commit is contained in:
Anton Romanov 2022-10-15 23:37:22 +04:00
parent 957c1bbc8c
commit bfec08c1f4
20 changed files with 246 additions and 211 deletions

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName);
public abstract List<TimeSeries> 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<String, List<TimeSeriesValue>> timeSeriesValues = getTimeSeriesValues(repositoryId, branchName);
// извлеченные временных рядов
List<TimeSeries> 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<String, List<TimeSeriesValue>> sortTimeSeriesValues(Map<String, List<TimeSeriesValue>> timeSeriesValues) {
for (Map.Entry<String, List<TimeSeriesValue>> entry : timeSeriesValues.entrySet()) {
entry.getValue().sort(Comparator.comparing(TimeSeriesValue::getDate));
private List<TimeSeries> sortTimeSeries(List<TimeSeries> timeSeries) {
for (TimeSeries ts : timeSeries) {
ts.getValues().sort(Comparator.comparing(TimeSeriesValue::getDate));
}
return timeSeriesValues;
return timeSeries;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<>();
}
@Override

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
}

View File

@ -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<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<TimeSeries>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
@Override
public TimeSeriesType getTimeSeriesType() {
return TimeSeriesType.AUTHOR_COMPLETED_ISSUES;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<TimeSeries>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
@Override
public TimeSeriesType getTimeSeriesType() {
return TimeSeriesType.AUTHOR_ISSUES;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<>();
}
@Override

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<TimeSeries>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
@Override
public TimeSeriesType getTimeSeriesType() {
return TimeSeriesType.CLASSES;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
//TODO: добавить постраничное чтение
Map<String, List<TimeSeriesValue>> result = new HashMap<>();
result.put(String.format("%s %s %s", gitRepositoryService.findById(repositoryId).getName(),
return Collections.singletonList(
new TimeSeries(
String.format("%s %s %s",
gitRepositoryService.findById(repositoryId).getName(),
branchName,
getTimeSeriesName()),
getTimeSeriesType().getDescription()),
getTimeSeriesType(),
commitService.findByRepositoryIdAndName(repositoryId, branchName)
.stream()
.map(c -> new TimeSeriesValue(c.getDate(), 1.0))
.collect(Collectors.toList()));
return result;
.collect(Collectors.toList())));
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
@Override
public TimeSeriesType getTimeSeriesType() {
return TimeSeriesType.COMMITS;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<TimeSeries>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
@Override
public TimeSeriesType getTimeSeriesType() {
return TimeSeriesType.DEPENDENCIES;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<TimeSeries>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
@Override
public TimeSeriesType getTimeSeriesType() {
return TimeSeriesType.ENTITIES;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<TimeSeries>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
@Override
public TimeSeriesType getTimeSeriesType() {
return TimeSeriesType.FILES;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<TimeSeries>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
@Override
public TimeSeriesType getTimeSeriesType() {
return TimeSeriesType.INTERFACES;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
@Override
public TimeSeriesType getTimeSeriesType() {
return TimeSeriesType.ISSUES;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
@Override
public TimeSeriesType getTimeSeriesType() {
return TimeSeriesType.PROCESSES;
}
}

View File

@ -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<String, List<TimeSeriesValue>> getTimeSeriesValues(Integer repositoryId, String branchName) {
return new HashMap<>();
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
return new ArrayList<>();
}
@Override
public TimeSeriesService getTimeSeriesService() {
return timeSeriesService;
}
@Override
public TimeSeriesType getTimeSeriesType() {
return TimeSeriesType.STARS;
}
}

View File

@ -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<TimeSeriesValue> 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<TimeSeriesValue> 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;
}
}

View File

@ -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;
}
}

View File

@ -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<TimeSeries> save(Map<String, List<TimeSeriesValue>> timeSeriesValues) {
List<TimeSeries> results = new ArrayList<>();
for (Map.Entry<String, List<TimeSeriesValue>> entry : timeSeriesValues.entrySet()) {
results.add(save(entry.getKey(), entry.getValue()));
}
return results;
}
@Transactional
public TimeSeries save(String timeSeriesName, List<TimeSeriesValue> timeSeriesValues) {
public TimeSeries save(String timeSeriesName, TimeSeriesType timeSeriesType, List<TimeSeriesValue> timeSeriesValues) {
LOG.debug("Start save {} time series with {} time series values ", timeSeriesName, timeSeriesValues.size());
final TimeSeries timeSeries = findOrCreate(timeSeriesName);
List<TimeSeriesValue> 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<TimeSeriesValue> save(List<TimeSeriesValue> timeSeriesValues) {
return timeSeriesValues.stream()
.map(timeSeriesValue -> {
timeSeriesValue.setValue((timeSeriesValue.getValue()));
timeSeriesValue.setDate((timeSeriesValue.getDate()));
return timeSeriesValueRepository.save(timeSeriesValue);
}).collect(Collectors.toList());
/**
* Сохранить список временных рядов
*
* @param timeSeries список ВР
* @return сохраненный список ВР
*/
@Transactional
public List<TimeSeries> save(List<TimeSeries> timeSeries) {
List<TimeSeries> results = new ArrayList<>();
for (TimeSeries ts : timeSeries) {
results.add(save(ts.getName(), ts.getTimeSeriesType(), ts.getValues()));
}
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<TimeSeriesValue> findAll() {
return timeSeriesValueRepository.findAll();
return results;
}
public TimeSeriesDateMapper.TimeSeriesInterval getTimeSeriesInterval() {

View File

@ -44,4 +44,9 @@
referencedTableName="time_series"
referencedColumnNames="id"/>
</changeSet>
<changeSet author="orion" id="20221012-170000-2">
<addColumn tableName="time_series">
<column name="time_series_type" type="varchar(100)"></column>
</addColumn>
</changeSet>
</databaseChangeLog>