{"id":15593252,"url":"https://github.com/derhuerst/live-moving-average","last_synced_at":"2025-04-15T05:17:28.707Z","repository":{"id":57290395,"uuid":"103034752","full_name":"derhuerst/live-moving-average","owner":"derhuerst","description":"An ever updating average of the last n values.","archived":false,"fork":false,"pushed_at":"2022-02-13T16:35:14.000Z","size":15,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T05:17:22.705Z","etag":null,"topics":["average","mean","moving","rolling","window"],"latest_commit_sha":null,"homepage":"https://github.com/derhuerst/live-moving-average","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/derhuerst.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-10T14:14:16.000Z","updated_at":"2022-07-24T00:05:43.000Z","dependencies_parsed_at":"2022-09-02T06:22:30.428Z","dependency_job_id":null,"html_url":"https://github.com/derhuerst/live-moving-average","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Flive-moving-average","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Flive-moving-average/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Flive-moving-average/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Flive-moving-average/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/derhuerst","download_url":"https://codeload.github.com/derhuerst/live-moving-average/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249010222,"owners_count":21197796,"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":["average","mean","moving","rolling","window"],"created_at":"2024-10-03T00:05:56.212Z","updated_at":"2025-04-15T05:17:28.687Z","avatar_url":"https://github.com/derhuerst.png","language":"JavaScript","funding_links":["https://github.com/sponsors/derhuerst"],"categories":[],"sub_categories":[],"readme":"# live-moving-average\n\n**An ever updating average of the last n values.** See [Moving Average](https://en.wikipedia.org/wiki/Moving_average).\n\n[![npm version](https://img.shields.io/npm/v/live-moving-average.svg)](https://www.npmjs.com/package/live-moving-average)\n[![build status](https://api.travis-ci.org/derhuerst/live-moving-average.svg?branch=master)](https://travis-ci.org/derhuerst/live-moving-average)\n![ISC-licensed](https://img.shields.io/github/license/derhuerst/live-moving-average.svg)\n![minimum Node.js version](https://img.shields.io/node/v/live-moving-average.svg)\n[![chat with me on Gitter](https://img.shields.io/badge/chat%20with%20me-on%20gitter-512e92.svg)](https://gitter.im/derhuerst)\n[![support me via GitHub Sponsors](https://img.shields.io/badge/support%20me-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)\n\nReuses the values array to prevent GC-thrashing. Does not slow down with an increasing window size:\n\n```window size 10, 1 push, 1 get x 65,514,574 ops/sec ±0.62% (90 runs sampled)\nwindow size 10, 1 push, 10 get x 49,988,485 ops/sec ±0.28% (93 runs sampled)\nwindow size 1000, 1 push, 1 get x 64,048,288 ops/sec ±0.42% (93 runs sampled)\nwindow size 100, 1 push, 10 get x 49,012,149 ops/sec ±0.40% (95 runs sampled)\n```\n\n\n## Installing\n\n```shell\nnpm install live-moving-average\n```\n\n\n## Usage\n\n```js\nconst createWindow = require('live-moving-average')\n\nconst avg = createWindow(3, 0) // size of 3, fill with 0\n\n// using api fluently\navg\n    .push(2)\n    .push(3)\n    .push(4)\n    .get() // 3, because (2 + 3 + 4) / 3\n\navg.push(5)\navg.push(6)\navg.get() // 5, because (4 + 5 + 6) / 3\n\navg.push(7)\navg.get() // 6, because (5 + 6 + 7) / 3\n```\n\n\n## API\n\n### `const w = createWindow(size, fill = 0)`\n\n`size` and `fill` must be a number.\n\n### `w.push(val)`\n\n`val` must be a number.    \nReturns `w`.\n\n### `w.get()`\n\nReturns the moving average.\n\n\n## Contributing\n\nIf you have a question or need support using `live-moving-average`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use [the issues page](https://github.com/derhuerst/live-moving-average/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderhuerst%2Flive-moving-average","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderhuerst%2Flive-moving-average","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderhuerst%2Flive-moving-average/lists"}