{"id":18428100,"url":"https://github.com/airtoxin/sandglass","last_synced_at":"2025-04-13T20:54:16.632Z","repository":{"id":27947261,"uuid":"31439921","full_name":"airtoxin/sandglass","owner":"airtoxin","description":"Time windowed stream aggregation","archived":false,"fork":false,"pushed_at":"2015-04-30T23:58:18.000Z","size":888,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T00:44:04.822Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/airtoxin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-27T21:27:28.000Z","updated_at":"2015-04-30T23:58:18.000Z","dependencies_parsed_at":"2022-09-26T16:21:26.865Z","dependency_job_id":null,"html_url":"https://github.com/airtoxin/sandglass","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airtoxin%2Fsandglass","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airtoxin%2Fsandglass/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airtoxin%2Fsandglass/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airtoxin%2Fsandglass/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/airtoxin","download_url":"https://codeload.github.com/airtoxin/sandglass/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480435,"owners_count":21110936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T05:12:48.037Z","updated_at":"2025-04-13T20:54:16.614Z","avatar_url":"https://github.com/airtoxin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#sandglass [![npm version](https://badge.fury.io/js/sandglass.svg)](http://badge.fury.io/js/sandglass) [![Build Status](https://travis-ci.org/airtoxin/sandglass.svg?branch=master)](https://travis-ci.org/airtoxin/sandglass)\n\nAggregates data stream timeline as time window.\n\n\n\n#Install\n\n[![NPM](https://nodei.co/npm/sandglass.png)](https://npmjs.org/package/sandglass)\n\n\n\n#Usage\n\n```javascript\nvar Sandglass = require( 'sandglass' );\nvar sandglass = new Sandglass();\n```\n\n\n\n#Sandglass Instance Methods\n\n##emit( data );\n\nSend data to all SandStreams.\n\n\n##absoluteSlice( timespan );\n\nSlices data stream timeline with timespan and aggregates each slice of data stream. Next aggregation starts after one aggregation ends, and another one starts again and again.\n\n![absoluteSlice](doc/img/absoluteSlice.jpg)\n\n__Arguments__\n\n1. timespan(Number): slice size (millisecond).\n\n__Returns__\n\n(sandStream): Fires `aggregate` event after stream aggregation.\n`emitter.on( 'aggregate', callback );` \n`callback` gets an array of streaming data.\n\n__Example__\n\n```javascript\nvar sandStream = sandglass.absoluteSlice( 1000 );\n\nsetTimeout( function() { sandglass.emit( 1 ) }, 500 );\nsetTimeout( function() { sandglass.emit( 2 ) }, 800 );\nsetTimeout( function() { sandglass.emit( 3 ) }, 1700 );\nsetTimeout( function() { sandglass.emit( 4 ) }, 2100 );\nsetTimeout( function() { sandglass.emit( 5 ) }, 2300 );\nsetTimeout( function() { sandglass.emit( 6 ) }, 5000 );\n\nsandStream.on( 'aggregate', function ( agg ) {\n    console.log( '@agg:', agg );\n    // =\u003e [ 1, 2, 3 ] (1 second later)\n    // =\u003e [ 4, 5 ] (2 second later)\n    // =\u003e [ 6 ] (3 second later)\n    // =\u003e [] (6 second later)\n    // ...\n} );\n```\n\n\n##relativeSlice( timespan );\n\nSlices data stream timeline with timespan and aggregates each slice of data stream. The aggregation starts at each incoming data, and it ends after it takes the timespan. \n(Same as delayedCount)\n\n![relativeSlice](doc/img/relativeSlice.jpg)\n\n__Arguments__\n\n1. timespan(Number): slice size (millisecond).\n\n__Returns__\n\n(sandStream): Fires `aggregate` event after stream aggregation.\n`emitter.on( 'aggregate', callback );` \n`callback` gets an array of streaming data.\n\n__Example__\n\n```javascript\nvar sandStream = sandglass.absoluteSlice( 1000 );\n\nsetTimeout( function() { sandglass.emit( 1 ) }, 500 );\nsetTimeout( function() { sandglass.emit( 2 ) }, 800 );\nsetTimeout( function() { sandglass.emit( 3 ) }, 1700 );\nsetTimeout( function() { sandglass.emit( 4 ) }, 2100 );\nsetTimeout( function() { sandglass.emit( 5 ) }, 2300 );\nsetTimeout( function() { sandglass.emit( 6 ) }, 5000 );\n\nsandStream.on( 'aggregate', function ( agg ) {\n    console.log( '@agg:', agg );\n    // =\u003e [ 1, 2 ] ( 1.5 second later )\n    // =\u003e [ 2, 3 ] ( 1.8 second later )\n    // =\u003e [ 3, 4, 5 ] ( 2.7 second later )\n    // =\u003e [ 4, 5 ] ( 3.1 second later )\n    // =\u003e [ 5 ] ( 3.3 second later )\n    // =\u003e [ 6 ] ( 6 second later )\n} );\n```\n\n\n##liveCount( timespan );\n\nWhen data incomes, 'liveCount' reserve the data.\nAt the same time 'liveCount' sends data as aggregation which was reserved untill at that time.\nEach data is disposed after it takes timespan.\n\n![liveCount](doc/img/liveCount.jpg)\n\n__Arguments__\n\n1. timespan(Number): slice size (millisecond).\n\n__Returns__\n\n(sandStream): Fires `aggregate` event after stream aggregation.\n`emitter.on( 'aggregate', callback );`\n`callback` gets an array of reserved streaming data.\n\n##delayedCount( timespan );\n\nAliase of relativeSlice (Same as relativeSlice).\nWhen data incomes, 'delayedCount' reserve the data.\nAfter it takes timespan, 'delayedCount' sends data as aggregation which was reserved untill at that time,\nand then the data is disposed.\n\n\n\n#SandStream Instance Methods\n\n##on( event, listener );\n\nSet event listener.\n`sandStream.on( 'aggregate', function( agg ) {...} )`\n\n##off( event, listener );\n\nRemove event listener.\n\n##stop();\nStop aggregation. GC works.\n\n##other methods\nsee [EventEmitter2](https://github.com/asyncly/EventEmitter2)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fairtoxin%2Fsandglass","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fairtoxin%2Fsandglass","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fairtoxin%2Fsandglass/lists"}