提交 daafd56b 编写于 作者: M Mathieu Bastian

Add ability to set graph timestamp & interval in ImportAPI

上级 048ae20e
......@@ -41,6 +41,7 @@
*/
package org.gephi.io.importer.api;
import org.gephi.graph.api.Interval;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.TimeRepresentation;
import org.gephi.io.importer.spi.Importer;
......@@ -231,6 +232,24 @@ public interface ContainerLoader {
public void setTimeFormat(TimeFormat timeFormat);
/**
* Sets the timestamp for the entire graph. All elements and all dynamic
* columns will automatically receive this timestamp when the graph is
* processed.
*
* @param timestamp timestamp
*/
public void setTimestamp(String timestamp);
/**
* Sets the interval for the entire graph. All elements and all dynamic
* columns will automatically receive this interval when the graph is
* processed.
*
* @param start interval start
* @param end interval end
*/
public void setInterval(String start, String end);
/**
* Sets the type of the id for elements.
*
......@@ -238,6 +257,7 @@ public interface ContainerLoader {
*/
public void setElementIdType(ElementIdType type);
/**
* Sets the current time representation, either <code>TIMESTAMP</code> or
* <code>INTERVAL</code>.
* <p>
......@@ -247,6 +267,14 @@ public interface ContainerLoader {
*/
public void setTimeRepresentation(TimeRepresentation timeRepresentation);
/**
* Gets the current time representation, either <code>TIMESTAMP</code> or
* <code>INTERVAL</code>.
* <p>
* @return time representation
*/
public TimeRepresentation getTimeRepresentation();
/**
* Sets the time zone that is used to parse date and time.
* <p>
......
......@@ -41,6 +41,7 @@
*/
package org.gephi.io.importer.api;
import org.gephi.graph.api.Interval;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.TimeRepresentation;
import org.gephi.io.processor.spi.Processor;
......@@ -88,6 +89,10 @@ public interface ContainerUnloader {
public Class getEdgeTypeLabelClass();
public Double getTimestamp();
public Interval getInterval();
public ElementIdType getElementIdType();
//PARAMETERS GETTERS
......
......@@ -377,4 +377,8 @@ public interface ElementDraft {
public TimeSet getTimeSet();
public Iterable<ColumnDraft> getColumns();
public Double getGraphTimestamp();
public Interval getGraphInterval();
}
......@@ -85,6 +85,16 @@ public abstract class ElementDraftImpl implements ElementDraft {
abstract ColumnDraft getColumn(String key, Class type);
@Override
public Double getGraphTimestamp() {
return container.getTimestamp();
}
@Override
public Interval getGraphInterval() {
return container.getInterval();
}
@Override
public String getId() {
return id;
......
......@@ -57,6 +57,7 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.gephi.graph.api.AttributeUtils;
import org.gephi.graph.api.Interval;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.TimeRepresentation;
import org.gephi.io.importer.api.ColumnDraft;
......@@ -114,6 +115,8 @@ public class ImportContainerImpl implements Container, ContainerLoader, Containe
private TimeFormat timeFormat = TimeFormat.DOUBLE;
private TimeRepresentation timeRepresentation = TimeRepresentation.INTERVAL;
private DateTimeZone timeZone = DateTimeZone.getDefault();
private Double timestamp;
private Interval interval;
//Report flag
private boolean reportedUnknownNode;
private boolean reportedParallelEdges;
......@@ -528,6 +531,48 @@ public class ImportContainerImpl implements Container, ContainerLoader, Containe
}
@Override
public void setTimestamp(String timestamp) {
try {
double t = timeFormat.equals(TimeFormat.DOUBLE) ? Double.parseDouble(timestamp) : AttributeUtils.parseDateTime(timestamp);
this.timestamp = t;
} catch (Exception e) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Timestamp_Parse_Error", timestamp), Level.SEVERE));
return;
}
report.log(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerLog.GraphTimestamp", timestamp));
}
@Override
public void setInterval(String startDateTime, String endDateTime) {
try {
double start, end;
if (startDateTime == null || startDateTime.isEmpty() || "-inf".equalsIgnoreCase(startDateTime) || "-infinity".equalsIgnoreCase(startDateTime)) {
start = Double.NEGATIVE_INFINITY;
} else {
start = timeFormat.equals(TimeFormat.DOUBLE) ? Double.parseDouble(startDateTime) : AttributeUtils.parseDateTime(startDateTime);
}
if (endDateTime == null || endDateTime.isEmpty() || "inf".equalsIgnoreCase(endDateTime) || "infinity".equalsIgnoreCase(endDateTime)) {
end = Double.POSITIVE_INFINITY;
} else {
end = timeFormat.equals(TimeFormat.DOUBLE) ? Double.parseDouble(endDateTime) : AttributeUtils.parseDateTime(endDateTime);
}
this.interval = new Interval(start, end);
} catch (Exception e) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Interval_Parse_Error", timestamp), Level.SEVERE));
return;
}
report.log(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerLog.GraphInterval", "[" + startDateTime + "," + endDateTime + "]"));
}
@Override
public Interval getInterval() {
return interval;
}
@Override
public Double getTimestamp() {
return timestamp;
}
@Override
public void setElementIdType(ElementIdType type) {
......@@ -539,6 +584,8 @@ public class ImportContainerImpl implements Container, ContainerLoader, Containe
public ElementIdType getElementIdType() {
return elementIdType;
}
@Override
public boolean verify() {
//Edge weight zero or negative
for (EdgeDraftImpl edge : new NullFilterIterable<EdgeDraftImpl>(edgeList)) {
......
......@@ -8,6 +8,8 @@ ImportContainerLog.AddDynamicEdgeColumn = Edge column ''{0}'' (Dynamic {1})
ImportContainerLog.EdgeLabelType = Edge labels are of type ''{0}''
ImportContainerLog.TimeZone = Time zone is set at ''{0}''
ImportContainerLog.MultiGraphCount = Multi-graph with {0} different types
ImportContainerLog.GraphTimestamp = Graph timestamp set at ''{0}''
ImportContainerLog.GraphInterval = Graph interval set at ''{0}''
ImportContainerLog.ElementIdType = Element id type set at ''{0}''
ImportContainerException_nodeExist = Duplicated node id=''{0}''
......@@ -28,6 +30,8 @@ ImportContainerException_Weight_Zero_Ignored = Edge weight is 0, the edge id=''{
ImportContainerException_ElementIdType_Parse_Error = The id type is configured to ''{0}'' but some elements id can't be parsed, defaulting to 'STRING'
ImportContainerException_Negative_Weight = Edge id=''{0}'' has a negative weight
ImportContainerException_Column_Type_Mismatch = A column ''{0}'' already exists but with a different type=''{1}''
ImportContainerException_Timestamp_Parse_Error = The graph timestamp ''{0}'' could not be parsed
ImportContainerException_Interval_Parse_Error = The graph interval ''{0}'' could not be parsed
ElementFactoryException_NullNodeId = Node id can't be null
ElementFactoryException_NullEdgeId = Edge id can't be null
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册