Search in sources :

Example 16 with Element

use of org.gephi.graph.api.Element in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method mergeDateColumnsToTimeInterval.

@Override
public Column mergeDateColumnsToTimeInterval(Table table, Column startColumn, Column endColumn, SimpleDateFormat dateFormat, String defaultStartDate, String defaultEndDate) {
    checkTableAndOneColumn(table, startColumn, endColumn);
    if (dateFormat == null) {
        throw new IllegalArgumentException("Date format can't be null can't be null");
    }
    Column timeIntervalColumn = getTimeIntervalColumn(table);
    final int startColumnIndex = startColumn != null ? startColumn.getIndex() : -1;
    final int endColumnIndex = endColumn != null ? endColumn.getIndex() : -1;
    double defaultStart = parseDateToDouble(dateFormat, defaultStartDate, Double.NEGATIVE_INFINITY);
    double defaultEnd = parseDateToDouble(dateFormat, defaultEndDate, Double.POSITIVE_INFINITY);
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Object value;
    double start, end;
    for (Element row : ac.getTableAttributeRows(table)) {
        if (startColumnIndex != -1) {
            value = row.getAttribute(startColumn);
            start = parseDateToDouble(dateFormat, value != null ? value.toString() : null, defaultStart);
        } else {
            start = defaultStart;
        }
        if (endColumnIndex != -1) {
            value = row.getAttribute(endColumn);
            end = parseDateToDouble(dateFormat, value != null ? value.toString() : null, defaultEnd);
        } else {
            end = defaultEnd;
        }
        if (!Double.isInfinite(start) && !Double.isInfinite(end) && start > end) {
            //When start>end, check what column was provided and keep its value. If both columns were provided, set an infinite interval:
            if (startColumnIndex == -1) {
                start = Double.NEGATIVE_INFINITY;
            } else if (endColumnIndex == -1) {
                end = Double.POSITIVE_INFINITY;
            } else {
                start = Double.NEGATIVE_INFINITY;
                end = Double.POSITIVE_INFINITY;
            }
        }
        IntervalSet timeInterval = new IntervalSet(new double[] { start, end });
        row.setAttribute(timeIntervalColumn, timeInterval);
    }
    return timeIntervalColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) IntervalSet(org.gephi.graph.api.types.IntervalSet)

Example 17 with Element

use of org.gephi.graph.api.Element in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method firstQuartileNumberMerge.

@Override
public Column firstQuartileNumberMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
    checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Column newColumn;
    //Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
    newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
    if (newColumn == null) {
        return null;
    }
    BigDecimal Q1;
    for (Element row : ac.getTableAttributeRows(table)) {
        Q1 = StatisticsUtils.quartile1(ac.getRowNumbers(row, columnsToMerge));
        row.setAttribute(newColumn, Q1);
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) BigDecimal(java.math.BigDecimal)

Example 18 with Element

use of org.gephi.graph.api.Element in project gephi by gephi.

the class AttributeColumnsControllerImpl method copyColumnDataToOtherColumn.

@Override
public void copyColumnDataToOtherColumn(Table table, Column sourceColumn, Column targetColumn) {
    if (sourceColumn == targetColumn) {
        throw new IllegalArgumentException("Source and target columns can't be equal");
    }
    Class targetType = targetColumn.getTypeClass();
    Object value;
    if (!targetType.equals(sourceColumn.getTypeClass())) {
        for (Element row : getTableAttributeRows(table)) {
            value = row.getAttribute(sourceColumn);
            setAttributeValue(value, row, targetColumn);
        }
    } else {
        for (Element row : getTableAttributeRows(table)) {
            value = row.getAttribute(sourceColumn);
            if (value == null) {
                row.removeAttribute(targetColumn);
            } else {
                row.setAttribute(targetColumn, value);
            }
        }
    }
}
Also used : Element(org.gephi.graph.api.Element)

Example 19 with Element

use of org.gephi.graph.api.Element in project gephi by gephi.

the class AttributeColumnsControllerImpl method getRowsColumnNumbers.

@Override
public Number[] getRowsColumnNumbers(Element[] rows, Column column) {
    Class type = column.getTypeClass();
    if (!AttributeUtils.isNumberType(type)) {
        throw new IllegalArgumentException("The column has to be a number column");
    }
    boolean isDynamic = AttributeUtils.isDynamicType(type);
    boolean isArray = type.isArray();
    ArrayList<Number> numbers = new ArrayList<>();
    Number number;
    for (Element row : rows) {
        Object value = row.getAttribute(column);
        if (value != null) {
            if (!isDynamic) {
                if (isArray) {
                    numbers.addAll(getArrayNumbers(value));
                } else {
                    //Single number column:
                    number = (Number) row.getAttribute(column);
                    if (number != null) {
                        numbers.add(number);
                    }
                }
            } else {
                numbers.addAll(getDynamicNumberColumnNumbers(row, column));
            }
        }
    }
    return numbers.toArray(new Number[0]);
}
Also used : Element(org.gephi.graph.api.Element) ArrayList(java.util.ArrayList)

Example 20 with Element

use of org.gephi.graph.api.Element in project gephi by gephi.

the class AttributeColumnsControllerImpl method calculateColumnValuesFrequencies.

@Override
public Map<Object, Integer> calculateColumnValuesFrequencies(Table table, Column column) {
    Map<Object, Integer> valuesFrequencies = new HashMap<>();
    Object value;
    for (Element row : getTableAttributeRows(table)) {
        value = row.getAttribute(column);
        if (valuesFrequencies.containsKey(value)) {
            valuesFrequencies.put(value, valuesFrequencies.get(value) + 1);
        } else {
            valuesFrequencies.put(value, 1);
        }
    }
    return valuesFrequencies;
}
Also used : HashMap(java.util.HashMap) Element(org.gephi.graph.api.Element)

Aggregations

Element (org.gephi.graph.api.Element)30 Column (org.gephi.graph.api.Column)19 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)15 BigDecimal (java.math.BigDecimal)8 GraphController (org.gephi.graph.api.GraphController)4 TimeFormat (org.gephi.graph.api.TimeFormat)4 DateTimeZone (org.joda.time.DateTimeZone)4 Matcher (java.util.regex.Matcher)3 GraphModel (org.gephi.graph.api.GraphModel)3 TimeMap (org.gephi.graph.api.types.TimeMap)3 ArrayList (java.util.ArrayList)2 Graph (org.gephi.graph.api.Graph)2 Interval (org.gephi.graph.api.Interval)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JFileChooser (javax.swing.JFileChooser)1 Index (org.gephi.graph.api.Index)1 Node (org.gephi.graph.api.Node)1