Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
fluent-data
Advanced tools
Readme
See the Video Series Here
This library allows you to work with data structured as a table or as a matrix and provides you with many of the methods you would expect when working with such things. It also provides various convenience and statistical functions.
A dataset
represents a collection of object-rows. Among other capacities, here you have the
ability to map, filter, sort, group, reduce, and join. These methods can seem similar to
those found on Array
. However, they are designed to work with objects as rows. Furthermore,
some SQL-like capacity (e.g. left join, exists) and deeper statistics (e.g. multiple regression)
are available that you just cannot get in vanilla javacript.
A matrix
is a rectangular collection of numbers on which particular mathematical operations
are defined. This library offers many of the expected operations of matrix algebra. This
includes matrix multiplication, addition, various methods of 'apply' functionality, varous
decompositions, pseudoinvering, and production of eigen values and vectors.
Click on the links below to see more information in each area:
npm install fluent-data
// client
import $$ from './node_modules/fluent-data/dist/fluent-data.client.js';
// server
let $$ = require('fluent-data');
// but the examples in this documentation will use
let $$ = require('./dist/fluent-data.server.js');
Consider the following arrays:
let customers = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Benny' }
];
let purchases = [
{ customer: 2, speed: 15, rating: 50, storeId: 1 },
{ customer: 1, speed: 5, rating: 90, storeId: 1 },
{ customer: 1, speed: 7, rating: 55, storeId: 1 },
{ customer: 2, speed: 6, rating: 88, storeId: 1 },
{ customer: 1, speed: 25, rating: 35, storeId: 1 },
{ customer: 1, speed: 40, rating: 2, storeId: 3, closed: true },
{ customer: 2, speed: 4, rating: 88, storeId: 1 },
{ customer: 1, speed: 1, rating: 96, storeId: 2 },
{ customer: 1, speed: 2, rating: 94, storeId: 2 },
{ customer: 1, speed: 1, rating: 94, storeId: 2 }
];
The following example converts the to dataset and uses many of the methods available.
let $$ = require('./dist/fluent-data.server.js');
$$(purchases)
.filter(p => !p.closed)
.joinLeft(customers, (p,c) => p.customer == c.id)
.group(p => [p.customer, p.storeId])
.reduce({
customer: $$.first(p => p.name),
store: $$.first(p => p.storeId),
orders: $$.count(p => p.id),
speed: $$.avg(p => p.speed),
rating: $$.avg(p => p.rating),
correlation: $$.cor(p => [p.speed, p.rating])
// other reducers, such as multiple regression, are built in!
})
.sort(p => [p.customer, -p.rating])
.log(null, 'purchases:',
p => $$.round({ ...p, orders: undefined}, 1e-3)
);
// use 'get' as opposed to 'log' to assign to a variable
This results in three rows for analysis:
purchases:
┌──────────┬───────┬────────┬────────┬─────────────┐
│ customer │ store │ speed │ rating │ correlation │
├──────────┼───────┼────────┼────────┼─────────────┤
│ Alice │ 2 │ 1.333 │ 94.667 │ -0.5 │
│ Alice │ 1 │ 12.333 │ 60 │ -0.832 │
│ Benny │ 1 │ 8.333 │ 75.333 │ -0.985 │
└──────────┴───────┴────────┴────────┴─────────────┘
Consider the following arrays, converted to matricies:
let $$ = require('./dist/fluent-data.server.js');
let community = $$([
{ marker: 'Applewood Park', x: 0, y: 0 },
{ marker: 'Orangewood School', x: 10, y: 0},
{ marker: 'Kiwitown Market', x: 1, y: 10 },
{ marker: `The Millers`, x: -5, y: 0 },
{ marker: 'The Romeros', x: 0, y: -5 },
{ marker: 'The Lees', x: 5, y: 5 },
{ marker: 'The Keitas', x: 5, y: 0 },
{ marker: 'The Lebedevs', x: 15, y: 5 }
]).matrix('x, y', 'marker');
let transformer = new $$.matrix([
[ 1, 0.4 ],
[ 0, Math.pow(3,0.5) / 2 ]
]);
The following exmaple transforms the community data so that the new positions of the park, school, and market form an equilateral triangle. Then it analyzes the eigen properties of the transformer matrix.
let eigen = transformer.eigen();
community
.transform(transformer)
.log(null, 'Equilateralized Community:', 1e-8);
console.log('\nTransformer Eigenvalues:', eigen.values);
eigen.vectors.log(null, '\nTransformer Eigenvectors:', 1e-8);
Equilateralized Community:
┌───────────────────┬────┬─────────────┐
│ │ x │ y │
├───────────────────┼────┼─────────────┤
│ Applewood Park │ 0 │ 0 │
│ Orangewood School │ 10 │ 0 │
│ Kiwitown Market │ 5 │ 8.66025404 │
│ The Millers │ -5 │ 0 │
│ The Romeros │ -2 │ -4.33012702 │
│ The Lees │ 7 │ 4.33012702 │
│ The Keitas │ 5 │ 0 │
│ The Lebedevs │ 17 │ 4.33012702 │
└───────────────────┴────┴─────────────┘
Transformer Eigenvalues: [ 1, 0.8660254 ]
Transformer Eigenvectors:
┌────┬────┬─────────────┐
│ │ c0 │ c1 │
├────┼────┼─────────────┤
│ r0 │ 1 │ -0.94822626 │
│ r1 │ 0 │ 0.31759558 │
└────┴────┴─────────────┘
FAQs
Work with tables and matricies in fluent fashion within javascript.
The npm package fluent-data receives a total of 37 weekly downloads. As such, fluent-data popularity was classified as not popular.
We found that fluent-data demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.