Search in sources :

Example 1 with TimeMap

use of org.gephi.graph.api.types.TimeMap in project gephi by gephi.

the class AppearanceModelImpl method isPartition.

private boolean isPartition(Graph graph, Column column) {
    int valueCount, elementCount;
    if (column.isDynamic()) {
        if (!column.isNumber()) {
            return true;
        }
        Set<Object> set = new HashSet<>();
        boolean hasNullValue = false;
        int elements = 0;
        ElementIterable<? extends Element> iterable = AttributeUtils.isNodeColumn(column) ? graph.getNodes() : graph.getEdges();
        for (Element el : iterable) {
            TimeMap val = (TimeMap) el.getAttribute(column);
            if (val != null) {
                Object[] va = val.toValuesArray();
                for (Object v : va) {
                    if (v != null) {
                        set.add(v);
                    } else {
                        hasNullValue = true;
                    }
                    elements++;
                }
            }
        }
        valueCount = set.size();
        elementCount = elements;
    } else if (column.isIndexed()) {
        if (!column.isNumber()) {
            return true;
        }
        Index index;
        if (AttributeUtils.isNodeColumn(column)) {
            index = graphModel.getNodeIndex(graph.getView());
        } else {
            index = graphModel.getEdgeIndex(graph.getView());
        }
        valueCount = index.countValues(column);
        elementCount = index.countElements(column);
    } else {
        return false;
    }
    double ratio = valueCount / (double) elementCount;
    return ratio <= 0.5 || (valueCount <= 100 && valueCount != elementCount);
}
Also used : Element(org.gephi.graph.api.Element) TimeMap(org.gephi.graph.api.types.TimeMap) Index(org.gephi.graph.api.Index) HashSet(java.util.HashSet)

Example 2 with TimeMap

use of org.gephi.graph.api.types.TimeMap in project gephi by gephi.

the class AttributeRankingImpl method refreshDynamic.

protected void refreshDynamic(ElementIterable<? extends Element> iterable) {
    double minN = Double.POSITIVE_INFINITY;
    double maxN = Double.NEGATIVE_INFINITY;
    for (Element el : iterable) {
        TimeMap timeMap = (TimeMap) el.getAttribute(column);
        if (timeMap != null) {
            double numMin = ((Number) timeMap.get(graph.getView().getTimeInterval(), Estimator.MIN)).doubleValue();
            double numMax = ((Number) timeMap.get(graph.getView().getTimeInterval(), Estimator.MAX)).doubleValue();
            if (numMin < minN) {
                minN = numMin;
            }
            if (numMax > maxN) {
                maxN = numMax;
            }
        }
    }
    min = minN;
    max = maxN;
}
Also used : Element(org.gephi.graph.api.Element) TimeMap(org.gephi.graph.api.types.TimeMap)

Example 3 with TimeMap

use of org.gephi.graph.api.types.TimeMap in project gephi by gephi.

the class EdgeWeightRankingImpl method refresh.

@Override
protected void refresh() {
    if (graph.getEdgeCount() > 0) {
        double minV = Double.MAX_VALUE;
        double maxV = Double.MIN_VALUE;
        for (Edge e : graph.getEdges()) {
            if (e.hasDynamicWeight()) {
                TimeMap timeMap = (TimeMap) e.getAttribute("weight");
                if (timeMap != null) {
                    Double numMin = (Double) timeMap.get(graph.getView().getTimeInterval(), Estimator.MIN);
                    Double numMax = (Double) timeMap.get(graph.getView().getTimeInterval(), Estimator.MAX);
                    minV = Math.min(numMin, minV);
                    maxV = Math.max(numMax, maxV);
                }
            } else {
                minV = Math.min(e.getWeight(), minV);
                maxV = Math.max(e.getWeight(), maxV);
            }
        }
        min = minV;
        max = maxV;
    }
}
Also used : TimeMap(org.gephi.graph.api.types.TimeMap) Edge(org.gephi.graph.api.Edge)

Example 4 with TimeMap

use of org.gephi.graph.api.types.TimeMap in project gephi by gephi.

the class TimeMapStringConverter method getString.

@Override
public String getString(Object value) {
    String str = null;
    if (value != null) {
        TimeMap timeMap = (TimeMap) value;
        str = timeMap.toString(graphModelProvider.getGraphModel().getTimeFormat(), graphModelProvider.getGraphModel().getTimeZone());
    }
    return str;
}
Also used : TimeMap(org.gephi.graph.api.types.TimeMap)

Example 5 with TimeMap

use of org.gephi.graph.api.types.TimeMap in project gephi by gephi.

the class ImportContainerImpl method mergeParallelEdges.

protected void mergeParallelEdges(EdgeDraftImpl[] sources, EdgeDraftImpl dest) {
    Object val = dest.getValue("weight");
    if (val == null || !(val instanceof TimeMap)) {
        EdgeWeightMergeStrategy mergeStrategy = parameters.getEdgesMergeStrategy();
        int count = 1 + sources.length;
        double sum = dest.getWeight();
        double min = dest.getWeight();
        double max = dest.getWeight();
        for (EdgeDraftImpl edge : sources) {
            sum += edge.getWeight();
            min = Math.min(min, edge.getWeight());
            max = Math.max(max, edge.getWeight());
        }
        double result = dest.getWeight();
        switch(mergeStrategy) {
            case AVG:
                result = sum / count;
                break;
            case MAX:
                result = max;
                break;
            case MIN:
                result = min;
                break;
            case SUM:
                result = sum;
                break;
            default:
                break;
        }
        dest.setWeight(result);
    }
    //Add dest to sources for convenience
    sources = Arrays.copyOf(sources, sources.length + 1);
    sources[sources.length - 1] = dest;
    //Merge dynamic attributes
    for (ColumnDraft columnDraft : getEdgeColumns()) {
        if (columnDraft.isDynamic()) {
            TimeMap timeMap = null;
            for (EdgeDraftImpl edge : sources) {
                TimeMap t = (TimeMap) edge.getValue(columnDraft.getId());
                if (t != null && timeMap == null) {
                    timeMap = t;
                } else if (t != null && timeMap != null) {
                    for (Object key : t.toKeysArray()) {
                        timeMap.put(key, t.get(key, null));
                    }
                }
            }
            if (timeMap != null) {
                dest.setValue(columnDraft.getId(), timeMap);
            }
        }
    }
    //Merge timeset
    TimeSet timeSet = null;
    for (EdgeDraftImpl edge : sources) {
        TimeSet t = edge.getTimeSet();
        if (t != null && timeSet == null) {
            timeSet = t;
        } else if (t != null && timeSet != null) {
            for (Object key : t.toArray()) {
                timeSet.add(key);
            }
        }
    }
    if (timeSet != null) {
        dest.timeSet = timeSet;
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) TimeSet(org.gephi.graph.api.types.TimeSet) EdgeWeightMergeStrategy(org.gephi.io.importer.api.EdgeWeightMergeStrategy) TimeMap(org.gephi.graph.api.types.TimeMap)

Aggregations

TimeMap (org.gephi.graph.api.types.TimeMap)11 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)4 Element (org.gephi.graph.api.Element)3 TimeSet (org.gephi.graph.api.types.TimeSet)3 Column (org.gephi.graph.api.Column)2 IntervalDoubleMap (org.gephi.graph.api.types.IntervalDoubleMap)2 TimestampDoubleMap (org.gephi.graph.api.types.TimestampDoubleMap)2 EdgeDraft (org.gephi.io.importer.api.EdgeDraft)2 Issue (org.gephi.io.importer.api.Issue)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Edge (org.gephi.graph.api.Edge)1 Index (org.gephi.graph.api.Index)1 TimeRepresentation (org.gephi.graph.api.TimeRepresentation)1 IntervalIntegerMap (org.gephi.graph.api.types.IntervalIntegerMap)1