Class DatasetUtilities
java.lang.Object
com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities
Utility methods for manipulating datasets, exposed as system.dataset.* in scripting.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DatasetaddColumn(Dataset ds, int colId, org.python.core.PySequence col, String colName, org.python.core.PyType colType) static DatasetaddColumn(Dataset ds, org.python.core.PySequence col, String colName, org.python.core.PyType colType) static Datasetstatic Datasetstatic Datasetstatic Datasetstatic DatasetappendDataset(Dataset ds1, Dataset ds2) static DatasetclearDataset(Dataset ds) static StringdataSetToCSV(boolean headerRow, Dataset ds) Deprecated.static StringdataSetToExcel(boolean headerRow, Object[] datasets) static StringdataSetToExcel(boolean headerRow, Object[] datasets, boolean nullsEmpty) Deprecated.static byte[]dataSetToExcelBytes(boolean headerRow, Object[] objects, boolean nullsEmpty, @Nullable String[] sheetNames) static voiddataSetToExcelStreaming(boolean headerRow, Object[] objects, OutputStream out, boolean nullsEmpty) static voiddataSetToExcelStreaming(boolean headerRow, Object[] datasets, Writer out, boolean nullsEmpty) Deprecated.static StringdataSetToHTML(boolean headerRow, Dataset ds, String title) static voiddataSetToHTMLStreaming(boolean headerRow, Dataset ds, String title, Writer fw) static Datasetstatic DatasetdeleteRows(Dataset ds, int[] rows) static DatasetfilterColumns(Dataset dataset, org.python.core.PySequence columns) static DatasetformatDates(Dataset dataset, String format) static DatasetformatDates(Dataset dataset, String format, Locale locale) Returns a new dataset with all date columns changed to Strings, and the dates formatted as stringsstatic Datasetstatic DatasetfromCSVJava(String csv) A special version of fromCSV that throws Java exceptions rather than wrapped, uncaught python exceptionsstatic org.python.core.PyListstatic DatasetinsertColumn(Dataset ds, int colId, Object[] col, String colName, Class colType) static DatasetinsertColumn(Dataset ds, int colId, org.python.core.PySequence col, String colName, org.python.core.PyType colType) static DatasetinsertColumn(Dataset ds, org.python.core.PySequence row, String colName, org.python.core.PyType colType) static Datasetstatic Datasetstatic Datasetstatic Datasetstatic Datasetstatic Datasetstatic Datasetstatic Datasetstatic DatasetSorts a dataset based on one of its columns.static Datasetstatic Datasetstatic DatasetSorts a dataset based on one of its columns.static Stringstatic Stringstatic Stringstatic voidtoCSVJavaStreaming(Dataset ds, Boolean showHeaders, boolean forExport, Writer sw, boolean localized) static DatasettoDataset(org.python.core.PySequence headers, org.python.core.PySequence pyData) Converts headers and data from Jython sequences into a newDataset.static DatasetDeprecated.PyDataset implements Dataset, so there's no need for this reverse conversion method anymore.static DatasettoDataSet(org.python.core.PySequence headers, org.python.core.PySequence pyData) Deprecated.The word is 'Dataset', not 'DataSet', but backwards compatibility means this must stay forever.static byte[]Exports one or more datasets to an Excel workbook (.xlsx) format.static JSONObjecttoJSONObject(Dataset data) Returns a JSON object in the format of:static DatasetUtilities.PyDataSettoPyDataSet(Dataset dataset) Deprecated.PyDatasets are no longer necessary, becauseDatasetPyAdapterautomatically wrapsDatasetobjects inPyDatasetobjects.static Dataset
-
Constructor Details
-
DatasetUtilities
public DatasetUtilities()
-
-
Method Details
-
sort
-
sort
-
sort
-
sort
-
sort
public static Dataset sort(Dataset dataset, String keyColumn, boolean ascending, boolean naturalOrdering) Sorts a dataset based on one of its columns.- Parameters:
dataset- The dataset to sort.keyColumn- The name of the column to sort by.ascending- If true, the dataset will be sorted in ascending order.naturalOrdering- If true, uses a natural/alphanumeric comparator (useful for strings containing numbers).- Returns:
- A new, sorted dataset.
-
sort
public static Dataset sort(Dataset dataset, int keyColumn, boolean ascending, boolean naturalOrdering) Sorts a dataset based on one of its columns.- Parameters:
dataset- The dataset to sort.keyColumn- The index of the column to sort by.ascending- If true, the dataset will be sorted in ascending order.naturalOrdering- If true, uses a natural/alphanumeric comparator (useful for strings containing numbers).- Returns:
- A new, sorted dataset.
-
formatDates
- Throws:
IllegalArgumentException
-
formatDates
public static Dataset formatDates(Dataset dataset, String format, Locale locale) throws IllegalArgumentException Returns a new dataset with all date columns changed to Strings, and the dates formatted as strings- Parameters:
dataset- Dataset to formatformat- Date format to uselocale- Locale to use. If null, default will be used.- Returns:
- New dataset, formatted. If there are no date columns, original dataset is returned.
- Throws:
IllegalArgumentException- is date format is not valid
-
toPyDataSet
Deprecated.PyDatasets are no longer necessary, becauseDatasetPyAdapterautomatically wrapsDatasetobjects inPyDatasetobjects. -
toDataSet
Deprecated.PyDataset implements Dataset, so there's no need for this reverse conversion method anymore. -
toDataset
public static Dataset toDataset(org.python.core.PySequence headers, org.python.core.PySequence pyData) Converts headers and data from Jython sequences into a newDataset.- Parameters:
headers- A sequence of strings representing the column headers.pyData- A sequence of sequences representing the row data.- Returns:
- A new Dataset.
- Throws:
org.python.core.PyException- withIndexErrorif a row's column count doesn't match the header count, orTypeErrorif a value cannot be converted to a Java type.
-
toDataSet
@Deprecated(since="8.3.0") public static Dataset toDataSet(org.python.core.PySequence headers, org.python.core.PySequence pyData) Deprecated.The word is 'Dataset', not 'DataSet', but backwards compatibility means this must stay forever. -
filterColumns
-
fromCSV
-
fromCSVJava
public static Dataset fromCSVJava(String csv) throws IOException, ClassNotFoundException, IllegalArgumentException A special version of fromCSV that throws Java exceptions rather than wrapped, uncaught python exceptions -
toCSV
-
toCSVJava
-
toCSVJava
-
toCSVJavaStreaming
-
toJSONObject
Returns a JSON object in the format of:{ "columns": [ { "name": "col_1", "type": "java.lang.Integer" }, { "name": "col_2", "type": "java.lang.Integer" }, { "name": "col_3", "type": "java.lang.Integer" }], "rows": [ [ 1, 2, "hello" ], [ 3, 8, "whatever" ]] } -
dataSetToCSV
Deprecated. -
dataSetToHTML
-
dataSetToHTMLStreaming
public static void dataSetToHTMLStreaming(boolean headerRow, Dataset ds, String title, Writer fw) throws IOException - Throws:
IOException
-
dataSetToExcel
@Deprecated public static String dataSetToExcel(boolean headerRow, Object[] datasets, boolean nullsEmpty) Deprecated.Exports 1 or more datasets to excel.- Parameters:
datasets- An array of Datasets or PyDataSets. Each dataset will be on a separate sheet.
-
dataSetToExcel
-
toExcel
public static byte[] toExcel(org.python.core.PyObject[] pyArgs, String[] keywords) throws IOException Exports one or more datasets to an Excel workbook (.xlsx) format.- Parameters:
pyArgs- The keyword arguments: 'showHeaders', 'dataset', 'nullsEmpty', 'sheetNames'.keywords- The keyword names.- Returns:
- A byte array representing the Excel workbook.
- Throws:
IOException- If an error occurs during export.
-
dataSetToExcelStreaming
@Deprecated public static void dataSetToExcelStreaming(boolean headerRow, Object[] datasets, Writer out, boolean nullsEmpty) throws IOException Deprecated.- Throws:
IOException
-
dataSetToExcelStreaming
public static void dataSetToExcelStreaming(boolean headerRow, Object[] objects, OutputStream out, boolean nullsEmpty) -
dataSetToExcelBytes
-
addRow
public static Dataset addRow(Dataset ds, org.python.core.PySequence row) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
addRow
public static Dataset addRow(Dataset ds, int rowId, org.python.core.PySequence row) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
insertRow
public static Dataset insertRow(Dataset ds, org.python.core.PySequence row) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
insertRow
public static Dataset insertRow(Dataset ds, int rowId, org.python.core.PySequence row) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
addRows
public static Dataset addRows(Dataset ds, org.python.core.PySequence[] rows) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
appendDataset
- Throws:
org.python.core.PyException
-
addRows
public static Dataset addRows(Dataset ds, int rowId, org.python.core.PySequence[] rows) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
clearDataset
-
addColumn
public static Dataset addColumn(Dataset ds, org.python.core.PySequence col, String colName, org.python.core.PyType colType) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
addColumn
public static Dataset addColumn(Dataset ds, int colId, org.python.core.PySequence col, String colName, org.python.core.PyType colType) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
insertColumn
public static Dataset insertColumn(Dataset ds, org.python.core.PySequence row, String colName, org.python.core.PyType colType) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
insertColumn
public static Dataset insertColumn(Dataset ds, int colId, org.python.core.PySequence col, String colName, org.python.core.PyType colType) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
insertColumn
public static Dataset insertColumn(Dataset ds, int colId, Object[] col, String colName, Class colType) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
getColumnHeaders
public static org.python.core.PyList getColumnHeaders(Dataset ds) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
removeRow
- Throws:
org.python.core.PyException
-
deleteRow
- Throws:
org.python.core.PyException
-
deleteRows
- Throws:
org.python.core.PyException
-
updateRow
public static Dataset updateRow(Dataset ds, int row, org.python.core.PyDictionary changes) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
setValue
public static Dataset setValue(Dataset ds, int row, String col, org.python.core.PyObject value) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
setValue
public static Dataset setValue(Dataset ds, int row, int col, org.python.core.PyObject value) throws org.python.core.PyException - Throws:
org.python.core.PyException
-
setValue
public static Dataset setValue(Dataset ds, int row, int col, Object value) throws org.python.core.PyException - Throws:
org.python.core.PyException
-