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;
}
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;
}
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);
}
}
}
}
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]);
}
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;
}
Aggregations