render plot with a single dataseriew
This commit is contained in:
@@ -1,23 +1,11 @@
|
||||
package org.lucares.performance.db;
|
||||
|
||||
class Fields {
|
||||
static final String TAG_PREFIX = "__tag_";
|
||||
static final String PREFIX_INTERNAL_TAG = "__internal_";
|
||||
|
||||
static final String DATE_OFFSET = "__date_offset__";
|
||||
static final String DATE_OFFSET = PREFIX_INTERNAL_TAG + "date_offset";
|
||||
|
||||
static String prefixedKey(final String key) {
|
||||
return TAG_PREFIX + key;
|
||||
static boolean isInternalField(final String key) {
|
||||
return key.startsWith(PREFIX_INTERNAL_TAG);
|
||||
}
|
||||
|
||||
static boolean isPrefixedKey(final String key) {
|
||||
return key.startsWith(TAG_PREFIX);
|
||||
}
|
||||
|
||||
static String stripPrefix(final String key) {
|
||||
if (!isPrefixedKey(key)) {
|
||||
throw new IllegalArgumentException(key + " is not prefixed by " + TAG_PREFIX);
|
||||
}
|
||||
return key.substring(TAG_PREFIX.length());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ public class PdbFileIterator implements Iterator<Entry>, AutoCloseable {
|
||||
if (reader == null) {
|
||||
nextFile();
|
||||
}
|
||||
if (reader == null) {
|
||||
return null;
|
||||
}
|
||||
final Optional<Entry> optionalEntry = reader.readEntry(currentPdbFile.getTags());
|
||||
|
||||
return optionalEntry.orElseGet(() -> {
|
||||
|
||||
@@ -115,7 +115,22 @@ public class PerformanceDb implements AutoCloseable {
|
||||
public Stream<Entry> get(final Tags tags) {
|
||||
|
||||
final List<PdbFile> pdbFiles = tagsToFile.getFilesMatchingTags(tags);
|
||||
return toStream(pdbFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entries as an unbound, ordered and non-parallel stream.
|
||||
*
|
||||
* @param query
|
||||
* @return {@link Stream} unbound, ordered and non-parallel
|
||||
*/
|
||||
public Stream<Entry> get(final String query) {
|
||||
|
||||
final List<PdbFile> pdbFiles = tagsToFile.getFilesForQuery(query);
|
||||
return toStream(pdbFiles);
|
||||
}
|
||||
|
||||
private Stream<Entry> toStream(final List<PdbFile> pdbFiles) {
|
||||
final Iterator<Entry> iterator = new PdbFileIterator(pdbFiles);
|
||||
|
||||
final Spliterator<Entry> spliterator = Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED);
|
||||
|
||||
@@ -6,7 +6,7 @@ final class Query {
|
||||
|
||||
for (final String key : tags.getKeys()) {
|
||||
tags.getValue(key).ifPresent(value -> {
|
||||
result.append(Fields.prefixedKey(key));
|
||||
result.append(key);
|
||||
result.append("=");
|
||||
result.append(value);
|
||||
result.append(" ");
|
||||
|
||||
@@ -21,6 +21,15 @@ public class Tags {
|
||||
|
||||
private Tags(final Map<String, String> tags) {
|
||||
this.tags.putAll(tags);
|
||||
ensureNoInternalFields();
|
||||
}
|
||||
|
||||
private void ensureNoInternalFields() {
|
||||
tags.keySet().forEach(key -> {
|
||||
if (Fields.isInternalField(key)) {
|
||||
throw new IllegalArgumentException(key + " is an internal field. Choose another prefix.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Tags create() {
|
||||
|
||||
@@ -48,8 +48,12 @@ public class TagsToFile implements AutoCloseable, CollectionUtils {
|
||||
}
|
||||
|
||||
List<PdbFile> getFilesMatchingTags(final Tags tags) {
|
||||
final List<PdbFile> result = new ArrayList<>();
|
||||
final String query = Query.createQuery(tags);
|
||||
return getFilesForQuery(query);
|
||||
}
|
||||
|
||||
List<PdbFile> getFilesForQuery(final String query) {
|
||||
final List<PdbFile> result = new ArrayList<>();
|
||||
try {
|
||||
final List<Document> searchResult = db.search(query);
|
||||
|
||||
@@ -81,9 +85,9 @@ public class TagsToFile implements AutoCloseable, CollectionUtils {
|
||||
|
||||
for (final String key : document.getProperties().keySet()) {
|
||||
|
||||
if (Fields.isPrefixedKey(key)) {
|
||||
if (!Fields.isInternalField(key)) {
|
||||
final String value = document.getPropertyString(key);
|
||||
tagsOfFile = tagsOfFile.copyAdd(Fields.stripPrefix(key), value);
|
||||
tagsOfFile = tagsOfFile.copyAdd(key, value);
|
||||
}
|
||||
}
|
||||
return tagsOfFile;
|
||||
@@ -130,7 +134,7 @@ public class TagsToFile implements AutoCloseable, CollectionUtils {
|
||||
ensureFieldsExist(tags);
|
||||
|
||||
tags.forEach((key, value) -> {
|
||||
db.setProperty(file, Fields.prefixedKey(key), value);
|
||||
db.setProperty(file, key, value);
|
||||
});
|
||||
|
||||
db.setProperty(file, Fields.DATE_OFFSET, day.serialize());
|
||||
@@ -145,11 +149,9 @@ public class TagsToFile implements AutoCloseable, CollectionUtils {
|
||||
|
||||
tags.forEach((key, value) -> {
|
||||
|
||||
final String prefixedKey = Fields.prefixedKey(key);
|
||||
|
||||
final Field field = fieldsMap.get(prefixedKey);
|
||||
final Field field = fieldsMap.get(key);
|
||||
if (field == null) {
|
||||
db.createField(prefixedKey, FieldType.STRING);
|
||||
db.createField(key, FieldType.STRING);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user