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.
arg
type
description
x
number
Number to format.
return
description
string
Number formatted with SI prefixes if valid, 'N/A' otherwise.
idfy
du.data.format.idfy(name)
Converts a name into a valid identifier.
arg
type
description
name
string
Name to convert.
return
description
string
The converted ID.
namify
du.data.format.namify(id)
Converts an identifier back into a name.
arg
type
description
id
string
Identifier to convert.
return
description
string
Converted 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.
arg
type
description
data
Array
Array of data to calculate sum for. Content of a CSV file.
column
numberstring
Column index or name of the column to sum.
segments
numberstringArray
Single index/name of the columns to group by or an array of column indices/names.
return
description
Array
Sorted 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.
arg
type
description
data
Array
Array to initialize histogram with.
set
du.data.structures.Histogram.set(data)
Assigns histogram data to the passed Array.
arg
type
description
data
Array
Array containing x: number, y: number objects.
return
description
du.data.structures.Histogram
Reference to the current histogram.
get
du.data.structures.Histogram.get()
Returns a copy of the underlying histogram data.
return
description
Array
The 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.
arg
type
description
x
number
Value of the data point.
y
number
Frequency of the data point.
return
description
du.data.structures.Histogram
Reference to the current histogram.
scale
du.data.structures.Histogram.scale(factor)
Multiplies all frequencies by the specified factor.
arg
type
description
factor
number
Multiplying factor.
return
description
du.data.structures.Histogram
Reference to the current histogram.
normalize
du.data.structures.Histogram.normalize()
Normalizes histogram to have a sum of frequencies equal to unit.
return
description
du.data.structures.Histogram
Reference to the current histogram.
sortByX
du.data.structures.Histogram.sortByX(descending)
Sorts histogram by its values.
arg
type
description
descending
boolean
Whether histogram should be sorted in descending instead of ascending order.
return
description
du.data.structures.Histogram
Reference to the current histogram.
sortByY
du.data.structures.Histogram.sortByY(descending)
Sorts histogram by its frequencies.
arg
type
description
descending
boolean
Whether histogram should be sorted in descending instead of ascending order.
return
description
du.data.structures.Histogram
Reference to the current histogram.
unsort
du.data.structures.Histogram.unsort()
Restores original order of the histogram data.
return
description
du.data.structures.Histogram
Reference 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.
arg
type
description
dimensions
Array
Array 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.
Returns a distribution of y values in the specified interval.
arg
type
description
length
number
Number of bins to calculate distribution over. If not specified, the entire history is considered. optional
offset
number
Offset measured from the end of the history. If not specified, 0 is used. optional
return
description
object
Object 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.
arg
type
description
data
Array
Array 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.
arg
type
description
x
string
Column for the X values.
y
stringArray
Column or array of columns for the Y values.
return
description
Array
Array 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.
arg
type
description
column
string
Column to segment table by.
value
stringnumber
Value to use for segmentation.
return
description
du.data.structures.Table
The segmented table.
sort
du.data.structures.Table.sort(column)
Sorts the table by a column.
arg
type
description
column
number
Column to sort table by.
return
description
du.data.structures.Table
The segmented table.
unsort
du.data.structures.Table.unsort()
Reverses any sorting previously performed on the table.