Namespace: DataModel

DataModel

Natural join is a special kind of joining where filtering of rows are performed internally by resolving common fields are from both table and the rows with common value are included.
Source:

Example

//@preamble_start
 Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
     const data = params[0];
     const schema = params[1];
     const DataModel = muze.DataModel;
     const dm = new DataModel(data, schema);
 //@preamble_end
 // DataModel instance is created from https://www.charts.com/static/cars.json data,
 // https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
 // muze namespace and assigned to the variable DataModel.

 // Creates two small DataModel instance from the original DataModel instance, which will be joined. Used chained
 // operator for conciseness.
 const makerDM = dm.groupBy(['Origin', 'Maker']).project(['Origin', 'Maker']);
 const nameDM = dm.project(['Name','Miles_per_Gallon'])

 const naturalJoin = DataModel.Operators.naturalJoin;
 const outputDM = naturalJoin(makerDM, nameDM);
 //@preamble_start
 printDM(outputDM);
 });
 //@preamble_end

Methods

handlePropagation(payload, identifiers)

This method is used to invoke the method associated with propagation.
Parameters:
Name Type Description
payload Object The interaction payload.
identifiers DataModel The propagated DataModel.
Source:

DataModel

Reducer is just a simple function which takes an array of real numbers and returns a representative number by reducing the array. A reducer can only be applied on a measure. When `groupBy` is applied on a DataModel, it performs aggregation on all measures with a reducer function. Reducer function for a measure can be set from schema or it can be overridden when `groupBy` is called. DataModel provides reducers which can be used out of the box
Reducer Name Description
sum returns the sum of all the number
avg returns the avg of all the number
min returns the minimum of all the number
max returns the maximum of all the number
first returns the first number in an array
last returns the last number in an array
count returns number of elements in the array
variance returns the variance of the numbers from the mean
std returns the standard deviation of the numbers
``` // An function to calculate mean squared value of an array. function (arr) { const squaredVal = arr.map(item => item * item); let sum = 0; for (let i = 0, l = squaredVal.length; i < l; i++) { sum += squaredVal[i]; } return sum; } ```
Source:

Methods

handlePropagation(payload, identifiers)

This method is used to invoke the method associated with propagation.
Parameters:
Name Type Description
payload Object The interaction payload.
identifiers DataModel The propagated DataModel.
Source:

DataModel

A page level storage which stores, registers, unregisters reducers for all the datamodel instances. There is only one reducer store available in a page. All the datamodel instances receive same instance of reducer store. DataModel out of the box provides handful of reducers which can be used as reducer function.
Source:

Methods

handlePropagation(payload, identifiers)

This method is used to invoke the method associated with propagation.
Parameters:
Name Type Description
payload Object The interaction payload.
identifiers DataModel The propagated DataModel.
Source: