{"id":18295107,"url":"https://github.com/codesuki/go-time-series","last_synced_at":"2025-06-29T13:32:53.957Z","repository":{"id":83119949,"uuid":"69930052","full_name":"codesuki/go-time-series","owner":"codesuki","description":"Time series implementation in Go","archived":false,"fork":false,"pushed_at":"2021-04-30T05:53:41.000Z","size":24,"stargazers_count":39,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T12:33:20.857Z","etag":null,"topics":["data-structure","go","in-memory","time-series"],"latest_commit_sha":null,"homepage":null,"language":"Go","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/codesuki.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-04T02:59:59.000Z","updated_at":"2025-02-08T16:03:16.000Z","dependencies_parsed_at":"2024-06-19T00:04:22.697Z","dependency_job_id":"c7cb0621-7fe1-4d6f-86e2-24c2193fa369","html_url":"https://github.com/codesuki/go-time-series","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codesuki/go-time-series","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesuki%2Fgo-time-series","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesuki%2Fgo-time-series/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesuki%2Fgo-time-series/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesuki%2Fgo-time-series/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codesuki","download_url":"https://codeload.github.com/codesuki/go-time-series/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesuki%2Fgo-time-series/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262600647,"owners_count":23335108,"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":["data-structure","go","in-memory","time-series"],"created_at":"2024-11-05T14:33:26.979Z","updated_at":"2025-06-29T13:32:53.899Z","avatar_url":"https://github.com/codesuki.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-time-series\n\n\n[![License](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](./LICENSE)\n[![GoDoc](https://godoc.org/github.com/codesuki/go-time-series?status.svg)](https://godoc.org/github.com/codesuki/go-time-series)\n[![Build Status](http://img.shields.io/travis/codesuki/go-time-series.svg?style=flat)](https://travis-ci.org/codesuki/go-time-series)\n[![codecov](https://codecov.io/gh/codesuki/go-time-series/branch/master/graph/badge.svg)](https://codecov.io/gh/codesuki/go-time-series)\n\nTime series implementation in Go.\n\nIt is used in [go-trending](https://www.github.com/codesuki/go-trending) as a backend for a trending algorithm.\nThe time series supports storing counts at different granularities, e.g. seconds, minutes, hours, ....\u003cbr /\u003e\nIn case of go-trending the time series is configured to have recent data available at small granularity, i.e. the recent 60 seconds, and historical data available at large granularity, i.e. the last few hours, days of data.\n\nA redis backend is planned.\n\n* Simple interface\n* Store time series data at different granularities\n* Use your own clock implementation, e.g. for testing or similar\n\n## Examples\n\n### Creating a time series with default settings\nThe default settings use `time.Now()` as clock and `time.Second * 60`, `time.Minute * 60` and `time.Hour * 24` as granularities.\n\n```go\nimport \"github.com/codesuki/go-time-series\"\n\n...\n\nts, err := timeseries.NewTimeSeries()\nif err != nil {\n    // handle error\n}\n```\n\n### Creating a customized time series\nYou can specify the clock and/or granularities to use. A clock must implement the `timeseries.Clock` interface.\n\n```go\nimport \"github.com/codesuki/go-time-series\"\n\n...\ntype clock struct {}\nfunc (c *clock) Now() {\n    return time.Time{} // always returns the zero time\n}\nvar myClock clock\n...\n\nts, err := timeseries.NewTimeSeries(\n    timeseries.WithGranularities(\n        []timeseries.Granularity{\n            {Granularity: time.Second, Count: 60},\n            {Granularity: time.Minute, Count: 60},\n            {Granularity: time.Hour, Count: 24},\n            {Granularity: time.Hour * 24, Count: 7},\n        }),\n    timeseries.WithClock(\u0026myClock),\n)\nif err != nil {\n    // handle error\n}\n```\n\n### Filling the time series\nTo fill the time series with counts, e.g. events, you can use two different functions.\n\n```go\nimport \"github.com/codesuki/go-time-series\"\n\n...\n\nts, err := timeseries.NewTimeSeries()\nif err != nil {\n    // handle error\n}\n\nts.Increase(2) // adds 2 to the counter at the current time\nts.IncreaseAtTime(3, time.Now().Add(-2 * time.Minute)) // adds 3 to the counter 2 minutes ago\n```\n\n### Querying the time series\nThe `Range()` function takes 2 arguments, i.e. the start and end of a time span.\n`Recent()` is a small helper function that just uses `clock.Now()` as `end` in `Range`.\nPlease refer to the [documentation](https://godoc.org/github.com/codesuki/go-time-series) for how `Range()` works exactly. There are some details depending on what range you query and what range is available.\n\n```go\nimport \"github.com/codesuki/go-time-series\"\n\n...\n\nts, err := timeseries.NewTimeSeries()\nif err != nil {\n    // handle error\n}\n\nts.Increase(2) // adds 2 to the counter at the current time\n// 1s passes\nts.Increase(3)\n// 1s passes\n\nts.Recent(5 * time.Second) // returns 5\n\nts.Range(time.Now().Add(-5 * time.Second), time.Now()) // returns 5\n```\n\n## Documentation\nGoDoc is located [here](https://godoc.org/github.com/codesuki/go-time-series)\n\n## License\ngo-time-series is [MIT licensed](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodesuki%2Fgo-time-series","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodesuki%2Fgo-time-series","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodesuki%2Fgo-time-series/lists"}