Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
pull-window
Advanced tools
Aggregate a pull-stream into windows.
Several helpers are provided for particular types of windows, sliding, tumbling, etc.
And also, a low level
sum every 10 items.
var pull = require('pull-stream')
var window = require('pull-window')
function everyTen () {
var i = 0
//window calls init with each data item,
//and a callback to close that window.
return window(function (data, cb) {
//if you don't want to start a window here,
//return undefined
if(i != 0) return
var sum = 0
//else return a function.
//this will be called all data
//until you callback.
return function (end, data) {
if(end) return cb(null, sum)
sum += data
if(++i >= 10) {
i = 0
cb(null, sum)
}
}
}
}
pull(
pull.count(1000),
everyTen(),
pull.log()
)
Each window doesn't have to be the same size...
var pull = require('pull-stream')
var window = require('pull-window')
function groupTo100 () {
var sum = null
return window(function (_, cb) {
if(sum != null) return
//sum stuff together until you have 100 or more
return function (end, data) {
if(end) return cb(null, sum)
sum += data
if(sum >= 100) {
//copy sum like this, incase the next item
//comes through sync
var _sum = sum; sum = null
cb(null, _sum)
}
}
})
}
pull(
pull.count(1000)
groupTo100(),
pull.log()
)
to make more over lapping windows just return the window function more often.
var pull = require('pull-stream')
var window = require('pull-window')
function sliding () {
return window(function (_, cb) {
var sum = 0, i = 0
//sum stuff together until you have 100 or more
return function (end, data) {
if(end) return cb(null, sum)
sum += data
if(++i >= 10) {
//in this example, each window gets it's own sum,
//so we don't need to copy it.
cb(null, sum)
}
}
})
}
pull(
pull.count(100)
sliding(),
pull.log()
)
window(function startWindow (data, cb) {
//called on each chunk
//including the first one
return function addToWindow (end, data) {
//cb(null, aggregate) when done.
}
}, function mapWindow (start, data) {
//(optional)
//map the window to something that tracks start, also
})
By default, windows are mapped to {start: firstData, data: aggregate}
.
unless you pass in an different mapWindow
function.
reduce every size
items into a single value, in a sliding window
tumbling window that groups items onto an array,
either every size
items, or within time
ms,
which ever occurs earliest.
MIT
FAQs
Aggregate a pull-stream into windows.
The npm package pull-window receives a total of 22,855 weekly downloads. As such, pull-window popularity was classified as popular.
We found that pull-window 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
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.