du.data

Module implementing various data structures and data manipulation methods.

Requires: lodash.cloneDeep

du.data.format

Collection of string and number formatting methods.

si

du.data.format.si(x)

Formats a number using SI prefixes.
argtypedescription
xnumberNumber to format.
returndescription
stringNumber formatted with SI prefixes if valid, 'N/A' otherwise.

idfy

du.data.format.idfy(name)

Converts a name into a valid identifier.
argtypedescription
namestringName to convert.
returndescription
stringThe converted ID.

namify

du.data.format.namify(id)

Converts an identifier back into a name.
argtypedescription
idstringIdentifier to convert.
returndescription
stringConverted name.

du.data.explore

Namespace for manipulating the content of a CSV file .

sum

du.data.explore.sum(data, column, segments)

Calculates the sum of a column grouped by some segments. Returns the sorted rows in descending order.
argtypedescription
dataArrayArray of data to calculate sum for. Content of a CSV file.
columnnumber stringColumn index or name of the column to sum.
segmentsnumber string ArraySingle index/name of the columns to group by or an array of column indices/names.
returndescription
ArraySorted rows of sums with keys of the unique segment column names/ids separated by '.'.

du.data.structures

Collection of smart data structures.

Histogram

du.data.structures.Histogram(data)

Class representing a histogram. A histogram is an array of (value, frequency) pairs.
argtypedescription
dataArrayArray to initialize histogram with.

set

du.data.structures.Histogram.set(data)

Assigns histogram data to the passed Array.
argtypedescription
dataArrayArray containing x: number, y: number objects.
returndescription
du.data.structures.HistogramReference to the current histogram.

get

du.data.structures.Histogram.get()

Returns a copy of the underlying histogram data.
returndescription
ArrayThe histogram data.

add

du.data.structures.Histogram.add(x, y)

Adds an (x, y) pair to the histogram. The new data point is added to the tail of the histogram.
argtypedescription
xnumberValue of the data point.
ynumberFrequency of the data point.
returndescription
du.data.structures.HistogramReference to the current histogram.

scale

du.data.structures.Histogram.scale(factor)

Multiplies all frequencies by the specified factor.
argtypedescription
factornumberMultiplying factor.
returndescription
du.data.structures.HistogramReference to the current histogram.

normalize

du.data.structures.Histogram.normalize()

Normalizes histogram to have a sum of frequencies equal to unit.
returndescription
du.data.structures.HistogramReference to the current histogram.

sortByX

du.data.structures.Histogram.sortByX(descending)

Sorts histogram by its values.
argtypedescription
descendingbooleanWhether histogram should be sorted in descending instead of ascending order.
returndescription
du.data.structures.HistogramReference to the current histogram.

sortByY

du.data.structures.Histogram.sortByY(descending)

Sorts histogram by its frequencies.
argtypedescription
descendingbooleanWhether histogram should be sorted in descending instead of ascending order.
returndescription
du.data.structures.HistogramReference to the current histogram.

unsort

du.data.structures.Histogram.unsort()

Restores original order of the histogram data.
returndescription
du.data.structures.HistogramReference to the current histogram.

TimeSeries

du.data.structures.TimeSeries(dimensions)

Data structure representing historical data. Each data point is a (x, y) pair where y values are dates, y values are objects containing multiple dimensions.
argtypedescription
dimensionsArrayArray of keys for the different y values.

clear

du.data.structures.TimeSeries.clear(start)

Clears history and re-allocates it based on the starting time.
argtypedescription
startDateStart time of the history.
returndescription
du.data.structures.TimeSeriesReference to the current history.

update

du.data.structures.TimeSeries.update(idx, x, idy, y)

Updates history at a specific point.
argtypedescription
idxnumberTemporal id of the data.
xDateTemporal value of the data.
idystringY id of the data.
ynumberY value of the data.
returndescription
du.data.structures.TimeSeriesReference to the current history.

sub

du.data.structures.TimeSeries.sub([length[, offset]])

Returns a sub history cut from the end.
argtypedescription
lengthnumberLength of the sub history to cut. If not specified, the total history is returned. optional
offsetnumberOffset measured from the end of the history. If not specified, 0 is used. optional
returndescription
ArrayThe sliced history array.

sum

du.data.structures.TimeSeries.sum([length[, offset]])

Returns the sum of the last several bins.
argtypedescription
lengthnumberNumber of bins to take sum over. If not specified, the last element is returned. optional
offsetnumberOffset measured from the end of the history. If not specified, 0 is used. optional
returndescription
objectObject containing the sum for each y dimension.

peak

du.data.structures.TimeSeries.peak([length[, offset]])

Calculates the peak level in the specified slice of history.
argtypedescription
lengthnumberNumber of bins to calculate peak over. If not specified, the entire history is considered. optional
offsetnumberOffset measured from the end of the history. If not specified, 0 is used. optional
returndescription
numberPeak level in the last n bins.

trend

du.data.structures.TimeSeries.trend()

Calculates the trend in the last two bins. The trend is simply the change from the bin before last and the last one.
returndescription
objectObject containing the relative changes for each y dimensions.

yDist

du.data.structures.TimeSeries.yDist([length[, offset]])

Returns a distribution of y values in the specified interval.
argtypedescription
lengthnumberNumber of bins to calculate distribution over. If not specified, the entire history is considered. optional
offsetnumberOffset measured from the end of the history. If not specified, 0 is used. optional
returndescription
objectObject containing the relative frequency of y dimensions.

Table

du.data.structures.Table([data])

Data structure representing a data in a tabular form. Tables can be segmented, grouped, etc.
argtypedescription
dataArrayArray of objects to initialize table with. Each element in the array is a row, and each column must be present in every row as a property. optional

slice

du.data.structures.Table.slice(x, y)

Creates a low dimension data set by slicing the table. The result is an array that can be used by the chart widgets.
argtypedescription
xstringColumn for the X values.
ystring ArrayColumn or array of columns for the Y values.
returndescription
ArrayArray of {x, y} data points for using in charts.

segment

du.data.structures.Table.segment(column, value)

Segments the table by a column value. If value is a number, all rows are included within a 10% of error of the distance between the closest row and the specified value.
argtypedescription
columnstringColumn to segment table by.
valuestring numberValue to use for segmentation.
returndescription
du.data.structures.TableThe segmented table.

sort

du.data.structures.Table.sort(column)

Sorts the table by a column.
argtypedescription
columnnumberColumn to sort table by.
returndescription
du.data.structures.TableThe segmented table.

unsort

du.data.structures.Table.unsort()

Reverses any sorting previously performed on the table.