use of au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData in project constellation by constellation-app.
the class AnalyticSchemaV2UpdateProvider method schemaUpdate.
@Override
protected void schemaUpdate(final StoreGraph graph) {
boolean updateVertexKeys = false;
// update vertex raw attribute
final int oldVertexRawAttributeId = AnalyticConcept.VertexAttribute.RAW.get(graph);
final Attribute oldVertexRawAttribute = new GraphAttribute(graph, oldVertexRawAttributeId);
if (!oldVertexRawAttribute.getAttributeType().equals(RawAttributeDescription.ATTRIBUTE_NAME)) {
graph.setPrimaryKey(GraphElementType.VERTEX);
final int newVertexRawAttribute = AnalyticConcept.VertexAttribute.RAW.ensure(graph);
final int vertexIdentifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
for (int vertexPosition = 0; vertexPosition < graph.getVertexCount(); vertexPosition++) {
final int vertexId = graph.getVertex(vertexPosition);
final String rawValue = graph.getStringValue(oldVertexRawAttributeId, vertexId);
graph.setObjectValue(newVertexRawAttribute, vertexId, new RawData(rawValue, null));
if (graph.getStringValue(vertexIdentifierAttribute, vertexId) == null) {
graph.setObjectValue(vertexIdentifierAttribute, vertexId, rawValue);
}
}
graph.removeAttribute(oldVertexRawAttributeId);
updateVertexKeys = true;
}
// update vertex type attribute
if (AnalyticConcept.VertexAttribute.TYPE.get(graph) == Graph.NOT_FOUND) {
updateVertexKeys = true;
}
final int oldVertexTypeAttributeId = graph.getAttribute(GraphElementType.VERTEX, "Type");
final Attribute oldVertexTypeAttribute = new GraphAttribute(graph, oldVertexTypeAttributeId);
if (!oldVertexTypeAttribute.getAttributeType().equals(VertexTypeAttributeDescription.ATTRIBUTE_NAME)) {
graph.setPrimaryKey(GraphElementType.VERTEX);
final int newVertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
final int vertexRawAttributeId = AnalyticConcept.VertexAttribute.RAW.ensure(graph);
for (int vertexPosition = 0; vertexPosition < graph.getVertexCount(); vertexPosition++) {
final int vertexId = graph.getVertex(vertexPosition);
final String typeValue = graph.getStringValue(oldVertexTypeAttributeId, vertexId);
final SchemaVertexType type = SchemaVertexTypeUtilities.getType(typeValue);
graph.setObjectValue(newVertexTypeAttributeId, graph.getVertex(vertexPosition), type);
final RawData rawValue = graph.getObjectValue(vertexRawAttributeId, graph.getVertex(vertexPosition));
graph.setObjectValue(vertexRawAttributeId, vertexId, rawValue != null ? new RawData(rawValue.getRawIdentifier(), typeValue) : new RawData(null, null));
}
graph.removeAttribute(oldVertexTypeAttributeId);
updateVertexKeys = true;
}
// update vertex keys and complete vertices
if (updateVertexKeys && graph.getSchema() != null) {
final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.VERTEX);
final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
graph.setPrimaryKey(GraphElementType.VERTEX, keyAttributeIds);
}
boolean updateTransactionKeys = false;
// update transaction type attribute
if (AnalyticConcept.TransactionAttribute.TYPE.get(graph) == Graph.NOT_FOUND) {
updateTransactionKeys = true;
}
final int oldTransactionTypeAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, "Type");
final Attribute oldTransactionTypeAttribute = new GraphAttribute(graph, oldTransactionTypeAttributeId);
if (!oldTransactionTypeAttribute.getAttributeType().equals(TransactionTypeAttributeDescription.ATTRIBUTE_NAME)) {
graph.setPrimaryKey(GraphElementType.TRANSACTION);
final int newTransactionTypeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
for (int transactionPosition = 0; transactionPosition < graph.getTransactionCount(); transactionPosition++) {
final int transactionId = graph.getTransaction(transactionPosition);
final String typeValue = graph.getStringValue(oldTransactionTypeAttributeId, transactionId);
final SchemaTransactionType type = SchemaTransactionTypeUtilities.getType(typeValue);
graph.setObjectValue(newTransactionTypeAttributeId, transactionId, type);
}
graph.removeAttribute(oldTransactionTypeAttributeId);
updateTransactionKeys = true;
}
// update transaction datetime attribute
if (TemporalConcept.TransactionAttribute.DATETIME.get(graph) == Graph.NOT_FOUND) {
updateTransactionKeys = true;
}
// update transaction keys and complete transactions
if (updateTransactionKeys && graph.getSchema() != null) {
final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.TRANSACTION);
final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
graph.setPrimaryKey(GraphElementType.TRANSACTION, keyAttributeIds);
}
}
use of au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData in project constellation by constellation-app.
the class RawIOProvider method readObject.
@Override
public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, final ImmutableObjectCache cache) throws IOException {
final Object newValue;
if (jnode.isNull()) {
newValue = null;
} else {
final JsonNode identifier = jnode.get(RAW_IDENTIFIER_TAG);
final JsonNode type = jnode.get(RAW_TYPE_TAG);
final RawData attributeValue = new RawData(identifier.isNull() ? null : identifier.textValue(), type.isNull() ? null : jnode.get(RAW_TYPE_TAG).textValue());
newValue = cache.deduplicate(attributeValue);
}
graph.setObjectValue(attributeId, elementId, newValue);
}
use of au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData in project constellation by constellation-app.
the class RawIOProvider method writeObject.
@Override
public void writeObject(final Attribute attr, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException {
if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) {
final RawData attributeValue = graph.getObjectValue(attr.getId(), elementId);
if (attributeValue == null) {
jsonGenerator.writeNullField(attr.getName());
} else {
jsonGenerator.writeObjectFieldStart(attr.getName());
jsonGenerator.writeStringField(RAW_IDENTIFIER_TAG, attributeValue.getRawIdentifier());
jsonGenerator.writeStringField(RAW_TYPE_TAG, attributeValue.getRawType());
jsonGenerator.writeEndObject();
}
}
}
use of au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData in project constellation by constellation-app.
the class Scatter3dArranger method getFloatValueFromObject.
private float getFloatValueFromObject(final Object attributeValue, final boolean logarithmic) {
if (attributeValue == null) {
return 0.0F;
}
if (attributeValue instanceof Float) {
return scaleValue((float) attributeValue, logarithmic);
}
if (attributeValue instanceof Double) {
return scaleValue((float) attributeValue, logarithmic);
}
if (attributeValue instanceof String) {
String val = (String) attributeValue;
float finalVal = 0.0F;
float multiplier = 1;
for (int i = 0; i < val.length(); i++) {
char ch = val.charAt(i);
float chVal = (float) ch;
finalVal += ((float) chVal) * multiplier;
multiplier /= 26;
}
return scaleValue(finalVal, logarithmic);
}
if (attributeValue instanceof Integer) {
float ret = (Integer) attributeValue;
return scaleValue(ret, logarithmic);
}
if (attributeValue instanceof ConstellationColor) {
ConstellationColor color = (ConstellationColor) attributeValue;
float red = color.getRed() / 256;
float green = color.getGreen() / 256;
float blue = color.getBlue() / 256;
return scaleValue((red + green + blue) * 100, logarithmic);
}
if (attributeValue instanceof ZonedDateTime) {
ZonedDateTime c = (ZonedDateTime) attributeValue;
float year = c.getYear();
float month = c.getMonthValue();
float monthDay = c.getDayOfMonth();
float hour = c.getHour();
float minute = c.getMinute();
return scaleValue((year - 2010) + month / 12 + monthDay / (366) + hour / (366 * 24) + minute / (366 * 24 * 60), logarithmic);
}
if (attributeValue instanceof RawData) {
String s = ((RawData) attributeValue).toString();
return getFloatValueFromObject(s, logarithmic);
}
return 0.0F;
}
Aggregations