{"id":25701443,"url":"https://github.com/mengstr/troll-avg","last_synced_at":"2025-10-15T23:11:27.208Z","repository":{"id":17743484,"uuid":"20586495","full_name":"mengstr/troll-avg","owner":"mengstr","description":"Time based rolling average calculations for node.js","archived":false,"fork":false,"pushed_at":"2014-06-12T08:36:36.000Z","size":192,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-11T09:19:03.598Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mengstr.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":"2014-06-07T05:40:01.000Z","updated_at":"2021-05-03T12:12:58.000Z","dependencies_parsed_at":"2022-09-26T21:31:43.146Z","dependency_job_id":null,"html_url":"https://github.com/mengstr/troll-avg","commit_stats":null,"previous_names":["smallroomlabs/troll-avg"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mengstr%2Ftroll-avg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mengstr%2Ftroll-avg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mengstr%2Ftroll-avg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mengstr%2Ftroll-avg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mengstr","download_url":"https://codeload.github.com/mengstr/troll-avg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240599174,"owners_count":19826959,"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":"2025-02-25T04:17:28.460Z","updated_at":"2025-10-15T23:11:22.147Z","avatar_url":"https://github.com/mengstr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# troll-avg [![Build Status](https://travis-ci.org/SmallRoomLabs/troll-avg.svg?branch=master)](https://travis-ci.org/SmallRoomLabs/troll-avg)\n\nTime-based rolling average calculations for node.js\n\n## Installation\nVia [npm][]:\n\n    $npm install --save troll-avg\n\n## Quick Start\n\n```javascript\nvar Troll=require('troll-avg');\n\n// Setup 5 counting slots collecting updates for 1 second each \n// for three different keys. This will give the average values\n// over the last 5 seconds.\nvar ravg=new Troll(['foo','bar','bletch'], 1, 5);\n\n// Increment a random key by 1 every 250 mS\nsetInterval(function() {\n\tvar r=Math.random();\n\tif (r\u003c0.1) {            // 10% goes to boo\n\t\travg.update('foo');\n\t} else if (r\u003c0.4) {     // 30% goes to bar\n\t\travg.update('bar');\n\t} else {                // 60% goes to bletch\n\t\travg.update('bletch');\n\t}\n},250);\n\n// Show all averages every second\nsetInterval(function() {\n\tconsole.log(ravg.averages());\n}, 1000);\n```\n\n## Methods\n\n### Constructor (allowedKeys, period, binCount)\nThe constructor expects three arguments.\n 1. An array of the keys that are being averaged.\n 2. How many seconds the data for each key is collected into one bins.\n 3. How many bins that the average is calculated over.\n\n### .update(key, cnt) \nAdd then *cnt* value into the current bin. If *cnt* is not specified it defaults to 1.\n\n### .average(key)\nReturn the rolling average value for the specified key.\n\n### .averages()\nReturn the rolling average values for all keys as an object.\n\n## Notes\nSince the collection of the values for the current time period is made into a separate set of bins calling .average() or .averages() before the first time period have elapsed the returned average(s) will be zero(s).\n\n## Testing\nUnit tests are done with mocha/chai.  They can be run with ```npm test```\n\n## License\nReleased under the MIT License\n\nCopyright (c) 2014 Mats Engstrom - SmallRoomLabs\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n[npm]: https://npmjs.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmengstr%2Ftroll-avg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmengstr%2Ftroll-avg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmengstr%2Ftroll-avg/lists"}