Published
Edited
Oct 17, 2020
Insert cell
Insert cell
Insert cell
c1 = df.count();
Insert cell
c2 = df.count();
Insert cell
c3 = df.count();
Insert cell
m1 = df.max(row => row.value);
Insert cell
Insert cell
p1 = df.pipe(
df.sensor(c1), // Keep running count of input
df.filter(n => n < 50), // Filter out numbers >= 50
df.sensor(c2), // Keep running count of filtered rows
df.map((n, idx) => ({ index: idx, value: n })), // Convert to JSON Object
df.filter(row => row.index % 2 === 0), // Filter even row indecies
df.sensor(c3), // Keep running count of final rows
df.sensor(m1), // Track largest value
);
Insert cell
Insert cell
{
return {
result: [...p1([10,20,30,40,50,60])], // ... is a quick way to expand an iterable into an array
inputCount: c1.peek(),
postFilterCount: c2.peek(),
outputCount: c3.peek(),
maxValueOut: m1.peek()
};
}
Insert cell
Insert cell
{
const retVal = [];
for (const resultRow of p1([10,20,30,40,50,60])) {
retVal.push({
row:resultRow,
c1: c1.peek(),
c2: c2.peek(),
c3: c3.peek(),
m1: m1.peek()
});
}
return retVal;
}
Insert cell
Insert cell
{
const bigData = df.generate(Math.random, 99999999999);
const mean1 = df.mean();
const mean2 = df.mean();
const mean3 = df.mean(row=>row.value);
const p2 = df.pipe(
df.sensor(mean1),
df.map(row => Math.round(row * 100)), // Convert inputs to integers
df.sensor(mean2),
p1, // Pipes can be combined!!!
df.skip(100), // Skip some rows
df.sensor(mean3),
df.first(117) // Process first 117 rows
);
return {
results:[...p2(bigData)],
c1: c1.peek(),
c2: c2.peek(),
c3: c3.peek(),
m1: m1.peek(),
averages:[mean1.peek(), mean2.peek(), mean3.peek()]
};
}
Insert cell
Insert cell
df = require("@hpcc-js/dataflow");
Insert cell
faker = require('https://bundle.run/faker@4.1.0')
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more