{"id":46679032,"url":"https://github.com/go-bumbu/timeseries","last_synced_at":"2026-03-08T23:37:08.308Z","repository":{"id":341477255,"uuid":"1158450993","full_name":"go-bumbu/timeseries","owner":"go-bumbu","description":"simple time series library on RDB persistence ","archived":false,"fork":false,"pushed_at":"2026-03-01T23:12:07.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-02T01:57:07.431Z","etag":null,"topics":["golang","golang-library","gorm","gorm-orm","rdb","time-series"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-bumbu.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-15T11:52:00.000Z","updated_at":"2026-03-01T23:11:02.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/go-bumbu/timeseries","commit_stats":null,"previous_names":["go-bumbu/timeseries"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/go-bumbu/timeseries","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-bumbu%2Ftimeseries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-bumbu%2Ftimeseries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-bumbu%2Ftimeseries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-bumbu%2Ftimeseries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-bumbu","download_url":"https://codeload.github.com/go-bumbu/timeseries/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-bumbu%2Ftimeseries/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30277133,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T20:45:49.896Z","status":"ssl_error","status_checked_at":"2026-03-08T20:45:49.525Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["golang","golang-library","gorm","gorm-orm","rdb","time-series"],"created_at":"2026-03-08T23:37:07.303Z","updated_at":"2026-03-08T23:37:08.296Z","avatar_url":"https://github.com/go-bumbu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Timeseries\n\nTimeseries is a lightweight time series storage library for Go. It provides a simple API to store and query \n(time, value) data with configurable retention, precision, and optional bucket aggregation. \nIt uses [GORM](https://gorm.io) and works with any supported database (SQLite, PostgreSQL, MySQL).\n\n## Features\n\n- **Multiple time series** – Register and manage many independent series in one registry\n- **Per-series precision and retention** – Each series has its own precision (time bucket) and retention period\n- **Bulk ingestion for backfilling** – Ingest many points at once with `IngestBulk` for historical data\n- **Custom aggregation** – Use a custom function to aggregate values within each precision bucket (e.g. avg, sum)\n\n## Installation\n\n```bash\ngo get github.com/go-bumbu/timeseries\n```\n\n## Quick Start\n\n```go\n\n\tdb, _ := gorm.Open(sqlite.Open(\":memory:\"), \u0026gorm.Config{})\n\tregistry, err := timeseries.NewRegistry(db)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Register a series: 1-hour precision, 30-day retention, avg for bucket reduction\n\tseries := timeseries.TimeSeries{\n\t\tName: \"btc_price\",\n\t\tRetention: timeseries.SamplingPolicy{\n\t\t\tPrecision:   time.Hour,\n\t\t\tRetention:   30 * 24 * time.Hour,\n\t\t\tAggregateFn: timeseries.AggregateAVG,\n\t\t},\n\t}\n\tif err := registry.RegisterSeries(series); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Ingest data\n\tif _, err := registry.Ingest(\"btc_price\", time.Now(), 42000.0); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Value at a specific time (latest at or before that time)\n\tvalue, err := registry.ValueAt(\"btc_price\", t.Add(30*time.Minute))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t_ = value\n\n\t// Run maintenance (retention cleanup + bucket reduction)\n\tif err := registry.Maintenance(context.Background()); err != nil {\n\t\tpanic(err)\n\t}\n\n```\n\n## Configuration\n\nEach series has a single policy that defines how data is stored and reduced:\n\n```go\ntimeseries.SamplingPolicy{\n\tPrecision:   time.Hour,           // Time bucket size (min 1 second)\n\tRetention:   30 * 24 * time.Hour, // How long to keep data\n\tAggregateFn: timeseries.AggregateAVG, // \"avg\", or \"\" for no reduction; register custom with RegisterAggregateFn\n}\n```\n\n## How To\n\n### Register a custom aggregate\n\nUse a name (e.g. `\"sum\"`, `\"max\"`) in `SamplingPolicy.AggregateFn` and register the function with the registry:\n\n```go\nregistry.RegisterAggregateFn(\"sum\", func(values []float64) float64 {\n\tvar s float64\n\tfor _, v := range values {\n\t\ts += v\n\t}\n\treturn s\n})\n\n// Then use in a series\nseries := timeseries.TimeSeries{\n\tName: \"events\",\n\tRetention: timeseries.SamplingPolicy{\n\t\tPrecision:   time.Hour,\n\t\tRetention:   7 * 24 * time.Hour,\n\t\tAggregateFn: \"sum\",\n\t},\n}\n```\n\n### Run maintenance periodically\n\nMaintenance deletes data older than retention and reduces buckets (when `AggregateFn` is set). Run it on a schedule (e.g. cron or a ticker):\n\n```go\nctx := context.Background()\nif err := registry.Maintenance(ctx); err != nil {\n\tlog.Printf(\"Maintenance failed: %v\", err)\n}\n```\n\nErrors from each series are combined and returned; maintenance does not stop on the first failure.\n\n### Query by time range\n\nUse zero times for no bound:\n\n```go\n// All records for the series\nall, err := registry.ListRecords(\"btc_price\", time.Time{}, time.Time{})\n```\n\n### Get value or record at a specific time\n\n`ValueAt` returns the latest value at or before the given time; `RecordAt` returns the full record:\n\n```go\nqueryTime := time.Date(2025, 1, 1, 14, 30, 0, 0, time.UTC)\nvalue, err := registry.ValueAt(\"btc_price\", queryTime)\n\nrecord, err := registry.RecordAt(\"btc_price\", queryTime)\nif record != nil {\n\t// record.Time, record.Value, record.Id\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-bumbu%2Ftimeseries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-bumbu%2Ftimeseries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-bumbu%2Ftimeseries/lists"}