{"id":19197335,"url":"https://github.com/versatica/trendcalculator","last_synced_at":"2025-09-07T03:33:10.564Z","repository":{"id":66081408,"uuid":"209120145","full_name":"versatica/TrendCalculator","owner":"versatica","description":"An algorithm to ease off decreasing values based on a constant factor, an elapsed time and (probably) also on currently highest value seen","archived":false,"fork":false,"pushed_at":"2019-09-18T09:12:17.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-23T04:45:51.576Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/versatica.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-09-17T17:45:56.000Z","updated_at":"2021-02-09T08:44:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"d8fc28fd-be1a-49b0-9430-244d19c0d18d","html_url":"https://github.com/versatica/TrendCalculator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/versatica/TrendCalculator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/versatica%2FTrendCalculator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/versatica%2FTrendCalculator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/versatica%2FTrendCalculator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/versatica%2FTrendCalculator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/versatica","download_url":"https://codeload.github.com/versatica/TrendCalculator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/versatica%2FTrendCalculator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273992714,"owners_count":25203790,"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","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-11-09T12:16:24.388Z","updated_at":"2025-09-07T03:33:10.536Z","avatar_url":"https://github.com/versatica.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TrendCalculator\n\nAn algorithm to ease off decreasing values based on a constant factor, an elapsed time and (probably) also on currently highest value seen.\n\n\n## Overview\n\nThe `TrendCalculator` is provided with input values (via the `update()` method). Upon updated values, the `TrendCalculator` computes its new \"current value\".\n\n* If the new given value is higher or equal than the current value, the current value must be set to it. This is, higher values must automatically update the current value.\n* Otherwise, if the new given value is less than the current value, the algorithm must ease it off to produce a value slightly lower than the current value. And such a relaxed value must depend on the given \"now\" (in ms).\n\n\n## Expected Results\n\nLet's assume we have `trendA`.\n\n* Initially it's provided with a value of 1000.\n* The current value of `trendA` must be 1000.\n* After 1 second, `trendA.Update()` is called with value 500.\n* The new current value (`trendA.GetValue()`) must be something lower than 1000. Let's say 950.\n* After another second, `trendA.Update()` is called with value 500 again.\n* The new current value (`trendA.GetValue()`) must be something lower than 950. Let's say 900.\n\nLet's assume we have `trendB`.\n\n* Initially it's provided with a value of 1000.\n* The current value of `trendB` must be 1000.\n* After 2 seconds, `trendB.Update()` is called with value 500.\n* The new current value (`trendB.GetValue()`) must be something lower than 1000. Let's say 980.\n\nThis is, in both cases the initial values were the same (1000) and we have then called `Update()` on both with value 500. In the former, twice in 2 seconds. In the latter, once in 2 seconds.\n\nThe algorithm is supposed to produce the same current value in both cases. This is, it should not matter that `Update()` is called multiple times with the same value or just once.\n\n**Important:** Those requirements may be wrong. And most probably this algorithm needs to keep a histogram of previous values and analyze its current trending in order to compute the new value.\n\n\n## Usage\n\nJust run:\n\n```bash\n$ ./run-tests.sh\n```\n\nIt will run some tests (see [src/main.cpp](./src/main.cpp) file) that, right now, produce the following results:\n\n```\n$ ./run-tests.sh\n\n\u003e\u003e\u003e test 1:\n    trend.Update(value:1000, now:0) [trend value: 1000]\n    trend.Update(value:500, now:500) [trend value: 975]\n    trend.Update(value:500, now:1000) [trend value: 950]\n    trend.Update(value:500, now:1500) [trend value: 925]\n    trend.Update(value:500, now:2000) [trend value: 900]\n    trend.Update(value:500, now:2500) [trend value: 875]\n    trend.Update(value:500, now:3000) [trend value: 850]\n    trend.Update(value:500, now:3500) [trend value: 825]\n    trend.Update(value:500, now:4000) [trend value: 800]\n    trend.Update(value:500, now:4500) [trend value: 775]\n    trend.Update(value:1000, now:5000) [trend value: 1000]\n\n\u003e\u003e\u003e test 2:\n    trend.Update(value:1000, now:0) [trend value: 1000]\n    trend.Update(value:500, now:1000) [trend value: 950]\n    trend.Update(value:500, now:2000) [trend value: 900]\n    trend.Update(value:500, now:3000) [trend value: 850]\n    trend.Update(value:500, now:4000) [trend value: 800]\n    trend.Update(value:1000, now:5000) [trend value: 1000]\n\n\u003e\u003e\u003e test 3:\n    trend.Update(value:1000, now:0) [trend value: 1000]\n    trend.Update(value:900, now:1000) [trend value: 950]\n    trend.Update(value:800, now:2000) [trend value: 900]\n    trend.Update(value:700, now:3000) [trend value: 850]\n    trend.Update(value:600, now:4000) [trend value: 800]\n    trend.Update(value:500, now:5000) [trend value: 750]\n    trend.Update(value:400, now:6000) [trend value: 700]\n    trend.Update(value:300, now:7000) [trend value: 650]\n    trend.Update(value:200, now:8000) [trend value: 600]\n    trend.Update(value:100, now:9000) [trend value: 550]\n    trend.Update(value:100, now:10000) [trend value: 500]\n    trend.Update(value:100, now:11000) [trend value: 450]\n    trend.Update(value:100, now:12000) [trend value: 400]\n    trend.Update(value:100, now:13000) [trend value: 350]\n    trend.Update(value:100, now:14000) [trend value: 300]\n    trend.Update(value:100, now:15000) [trend value: 250]\n    trend.Update(value:100, now:16000) [trend value: 200]\n    trend.Update(value:100, now:17000) [trend value: 150]\n    trend.Update(value:100, now:18000) [trend value: 100]\n    trend.Update(value:100, now:19000) [trend value: 100]\n    trend.Update(value:100, now:20000) [trend value: 100]\n\n\u003e\u003e\u003e done\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fversatica%2Ftrendcalculator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fversatica%2Ftrendcalculator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fversatica%2Ftrendcalculator/lists"}