Search in sources :

Example 6 with Element

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

the class AttributeColumnsMergeStrategiesControllerImpl method interQuartileRangeNumberMerge.

@Override
public Column interQuartileRangeNumberMerge(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 IQR, Q1, Q3;
    Number[] rowNumbers;
    for (Element row : ac.getTableAttributeRows(table)) {
        rowNumbers = ac.getRowNumbers(row, columnsToMerge);
        Q3 = StatisticsUtils.quartile3(rowNumbers);
        Q1 = StatisticsUtils.quartile1(rowNumbers);
        if (Q3 != null && Q1 != null) {
            IQR = Q3.subtract(Q1);
        } else {
            IQR = null;
        }
        row.setAttribute(newColumn, IQR);
    }
    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 7 with Element

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

the class AttributeColumnsMergeStrategiesControllerImpl method medianNumberMerge.

@Override
public Column medianNumberMerge(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;
    }
    final int newColumnIndex = newColumn.getIndex();
    BigDecimal median;
    for (Element row : ac.getTableAttributeRows(table)) {
        median = StatisticsUtils.median(ac.getRowNumbers(row, columnsToMerge));
        row.setAttribute(newColumn, median);
    }
    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 8 with Element

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

the class AttributeColumnsMergeStrategiesControllerImpl method sumNumbersMerge.

@Override
public Column sumNumbersMerge(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 sum;
    for (Element row : ac.getTableAttributeRows(table)) {
        sum = StatisticsUtils.sum(ac.getRowNumbers(row, columnsToMerge));
        row.setAttribute(newColumn, sum);
    }
    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 9 with Element

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

the class AttributeColumnsMergeStrategiesControllerImpl method thirdQuartileNumberMerge.

@Override
public Column thirdQuartileNumberMerge(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 Q3;
    for (Element row : ac.getTableAttributeRows(table)) {
        Q3 = StatisticsUtils.quartile3(ac.getRowNumbers(row, columnsToMerge));
        row.setAttribute(newColumn, Q3);
    }
    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 10 with Element

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

the class AttributeColumnsControllerImpl method copyRowDataToOtherRows.

@Override
public void copyRowDataToOtherRows(Element row, Element[] otherRows, Column[] columnsToCopy) {
    if (columnsToCopy != null) {
        for (Column column : columnsToCopy) {
            //Copy all except id and computed attributes:
            if (canChangeColumnData(column)) {
                for (Element otherRow : otherRows) {
                    Object value = row.getAttribute(column);
                    setAttributeValue(value, otherRow, column);
                }
            }
        }
    } else {
        Table table;
        if (row instanceof Node) {
            table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
        } else {
            table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
        }
        for (Column column : table) {
            if (canChangeColumnData(column)) {
                for (Element otherRow : otherRows) {
                    otherRow.removeAttribute(column);
                }
            }
        }
    }
}
Also used : Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) Element(org.gephi.graph.api.Element) Node(org.gephi.graph.api.Node) GraphController(org.gephi.graph.api.GraphController)

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