#5 -- save metadata
This commit is contained in:
parent
c8c53abdec
commit
e3ce7c0647
@ -72,24 +72,31 @@ public class DbFileService implements DbService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addSet(String key) {
|
||||
public void addSet(String key) {
|
||||
TimeSeriesSet timeSeriesSet = new TimeSeriesSet(key);
|
||||
if (isTimeSeriesSetExists(timeSeriesSet)) {
|
||||
throw new RuntimeException(String.format("Time series set %s already exists", timeSeriesSet.getKey()));
|
||||
} else {
|
||||
return Paths.get(timeSeriesDbPath, timeSeriesSet.getKey()).toFile().mkdirs();
|
||||
Paths.get(timeSeriesDbPath, timeSeriesSet.getKey()).toFile().mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addTimeSeries(TimeSeriesSet timeSeriesSet, TimeSeries timeSeries) throws IOException {
|
||||
public void addTimeSeries(TimeSeriesSet timeSeriesSet, TimeSeries timeSeries) throws IOException {
|
||||
if (!isTimeSeriesSetExists(timeSeriesSet)) {
|
||||
addSet(timeSeriesSet.getKey());
|
||||
}
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(Paths.get(getSetPath(timeSeriesSet).getAbsolutePath(), timeSeries.getName() + ".csv").toFile()));
|
||||
writer.write(new UtilService().getTimeSeriesToDateValueString(timeSeries));
|
||||
writer.close();
|
||||
return true;
|
||||
createMetaFile(timeSeriesSet, timeSeries);
|
||||
}
|
||||
|
||||
private void createMetaFile(TimeSeriesSet timeSeriesSet, TimeSeries timeSeries) throws IOException {
|
||||
TimeSeriesMeta timeSeriesMeta = new TimeSeriesMeta(timeSeries);
|
||||
new ObjectMapper()
|
||||
.writeValue(Paths.get(getSetPath(timeSeriesSet).getAbsolutePath(), timeSeries.getName() + ".csv.meta")
|
||||
.toFile(), timeSeriesMeta);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -138,7 +145,7 @@ public class DbFileService implements DbService {
|
||||
}
|
||||
|
||||
private List<File> getTimeSeriesMetaFiles(TimeSeriesSet timeSeriesSet) {
|
||||
return Arrays.asList(getSetPath(timeSeriesSet).listFiles(f -> f.getName().endsWith(".meta")));
|
||||
return Arrays.asList(getSetPath(timeSeriesSet).listFiles(f -> f.getName().endsWith(".csv.meta")));
|
||||
}
|
||||
|
||||
private File getTimeSeriesFile(TimeSeriesSet timeSeriesSet, String timeSeriesKey) {
|
||||
|
@ -20,9 +20,9 @@ public interface DbService {
|
||||
|
||||
TimeSeries getTimeSeries(TimeSeriesSet timeSeriesSet, String timeSeriesKey) throws IOException;
|
||||
|
||||
boolean addSet(String key);
|
||||
void addSet(String key);
|
||||
|
||||
boolean addTimeSeries(TimeSeriesSet timeSeriesSet, TimeSeries timeSeries) throws IOException;
|
||||
void addTimeSeries(TimeSeriesSet timeSeriesSet, TimeSeries timeSeries) throws IOException;
|
||||
|
||||
void deleteTimeSeries(TimeSeriesSet set, String timeSeriesKey) throws IOException;
|
||||
|
||||
|
@ -6,11 +6,22 @@
|
||||
|
||||
package ru.ulstu.db.model;
|
||||
|
||||
import ru.ulstu.datamodel.ts.TimeSeries;
|
||||
|
||||
public class TimeSeriesMeta {
|
||||
private String key;
|
||||
private int size;
|
||||
private boolean hasDateTime;
|
||||
|
||||
public TimeSeriesMeta() {
|
||||
}
|
||||
|
||||
public TimeSeriesMeta(TimeSeries timeSeries) {
|
||||
this.key = timeSeries.getName();
|
||||
this.hasDateTime = timeSeries.getValues().stream().anyMatch(v -> v.getDate() != null);
|
||||
this.size = timeSeries.getLength();
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user