mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -1,50 +1,33 @@
|
||||
async function createStreamVisualizer(asyncIterable, {
|
||||
maxPoints,
|
||||
alpha,
|
||||
width,
|
||||
height,
|
||||
yDomain
|
||||
}) {
|
||||
const {
|
||||
scaleLinear,
|
||||
line
|
||||
} = await import('d3');
|
||||
|
||||
async function createStreamVisualizer(
|
||||
asyncIterable,
|
||||
{ maxPoints, alpha, width, height, yDomain }
|
||||
) {
|
||||
const { scaleLinear, line } = await import('d3');
|
||||
const data = [];
|
||||
let prevEma;
|
||||
let ema = null;
|
||||
|
||||
for await (const { value, timestamp } of asyncIterable) {
|
||||
prevEma = (prevEma === undefined) ?
|
||||
value :
|
||||
alpha * value + (1 - alpha) * prevEma;
|
||||
|
||||
data.push({
|
||||
timestamp,
|
||||
value,
|
||||
ema: prevEma
|
||||
});
|
||||
for await (const point of asyncIterable) {
|
||||
ema = ema === null ? point.value : alpha * point.value + (1 - alpha) * ema;
|
||||
data.push({ ...point, ema });
|
||||
if (data.length > maxPoints) {
|
||||
data.shift();
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.length) {
|
||||
return {
|
||||
data,
|
||||
path: ''
|
||||
};
|
||||
if (data.length < 2) {
|
||||
return { data, path: "" };
|
||||
}
|
||||
|
||||
const x = scaleLinear([data[0].timestamp, data.at(-1).timestamp], [0, width]);
|
||||
const x = scaleLinear(
|
||||
[data[0].timestamp, data.at(-1).timestamp],
|
||||
[0, width]
|
||||
);
|
||||
const y = scaleLinear(yDomain, [height, 0]);
|
||||
|
||||
const path = line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema))(data);
|
||||
.x(p => x(p.timestamp))
|
||||
.y(p => y(p.ema))(data);
|
||||
|
||||
return {
|
||||
data,
|
||||
path: path ?? ''
|
||||
};
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
Reference in New Issue
Block a user