Search in sources :

Example 21 with AttributeColumnsController

use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method mergeNumericColumnsToTimeInterval.

@Override
public Column mergeNumericColumnsToTimeInterval(Table table, Column startColumn, Column endColumn, double defaultStart, double defaultEnd) {
    checkTableAndOneColumn(table, startColumn, endColumn);
    Column timeIntervalColumn = getTimeIntervalColumn(table);
    final int startColumnIndex = startColumn != null ? startColumn.getIndex() : -1;
    final int endColumnIndex = endColumn != null ? endColumn.getIndex() : -1;
    final boolean isStartColumnNumeric = startColumn != null ? (!AttributeUtils.isDynamicType(startColumn.getTypeClass()) && AttributeUtils.isNumberType(startColumn.getTypeClass())) : false;
    final boolean isEndColumnNumeric = endColumn != null ? (!AttributeUtils.isDynamicType(endColumn.getTypeClass()) && AttributeUtils.isNumberType(endColumn.getTypeClass())) : false;
    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);
            if (value != null) {
                if (isStartColumnNumeric) {
                    start = ((Number) value).doubleValue();
                } else {
                    start = parseDouble(value.toString(), defaultStart);
                }
            } else {
                start = defaultStart;
            }
        } else {
            start = defaultStart;
        }
        if (endColumnIndex != -1) {
            value = row.getAttribute(endColumn);
            if (value != null) {
                if (isEndColumnNumeric) {
                    end = ((Number) value).doubleValue();
                } else {
                    end = parseDouble(value.toString(), defaultEnd);
                }
            } else {
                end = 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 22 with AttributeColumnsController

use of org.gephi.datalab.api.AttributeColumnsController 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 23 with AttributeColumnsController

use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method averageNumberMerge.

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

use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method joinWithSeparatorMerge.

@Override
public Column joinWithSeparatorMerge(Table table, Column[] columnsToMerge, Class newColumnType, String newColumnTitle, String separator) {
    if (table == null || columnsToMerge == null) {
        throw new IllegalArgumentException("Table or columns can't be null");
    }
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Column newColumn;
    // Create as STRING column by default. Then it can be duplicated to other type.
    newColumn = ac.addAttributeColumn(table, newColumnTitle, newColumnType != null ? newColumnType : String.class);
    if (newColumn == null) {
        return null;
    }
    if (separator == null) {
        separator = "";
    }
    Object value;
    StringBuilder sb;
    final int columnsCount = columnsToMerge.length;
    GraphModel graphModel = table.getGraph().getModel();
    TimeFormat timeFormat = graphModel.getTimeFormat();
    DateTimeZone timeZone = graphModel.getTimeZone();
    for (Element row : ac.getTableAttributeRows(table)) {
        sb = new StringBuilder();
        for (int i = 0; i < columnsCount; i++) {
            value = row.getAttribute(columnsToMerge[i]);
            if (value != null) {
                sb.append(AttributeUtils.print(value, timeFormat, timeZone));
                if (i < columnsCount - 1) {
                    sb.append(separator);
                }
            }
        }
        ac.setAttributeValue(sb.toString(), row, newColumn);
    }
    return newColumn;
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) GraphModel(org.gephi.graph.api.GraphModel) Element(org.gephi.graph.api.Element) DateTimeZone(org.joda.time.DateTimeZone)

Example 25 with AttributeColumnsController

use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method maxValueNumbersMerge.

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

Aggregations

AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)31 Column (org.gephi.graph.api.Column)23 Element (org.gephi.graph.api.Element)14 BigDecimal (java.math.BigDecimal)8 ArrayList (java.util.ArrayList)7 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)5 Edge (org.gephi.graph.api.Edge)3 PropertyEditor (java.beans.PropertyEditor)2 Node (org.gephi.graph.api.Node)2 TimeFormat (org.gephi.graph.api.TimeFormat)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 AttributeValueWrapper (org.gephi.ui.tools.plugin.edit.EditWindowUtils.AttributeValueWrapper)2 DateTimeZone (org.joda.time.DateTimeZone)2 PropertySupport (org.openide.nodes.PropertySupport)2 Sheet (org.openide.nodes.Sheet)2 CsvWriter (com.csvreader.CsvWriter)1 Dialog (java.awt.Dialog)1 File (java.io.File)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1