{"id":21995689,"url":"https://github.com/tohtsky/log_count_util","last_synced_at":"2025-03-23T04:22:06.779Z","repository":{"id":46519181,"uuid":"339952030","full_name":"tohtsky/log_count_util","owner":"tohtsky","description":"A utility module to count/aggregate logs within a time interval","archived":false,"fork":false,"pushed_at":"2021-10-06T21:47:11.000Z","size":33,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-28T10:45:40.645Z","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/tohtsky.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}},"created_at":"2021-02-18T06:03:18.000Z","updated_at":"2022-03-10T04:45:55.000Z","dependencies_parsed_at":"2022-09-23T02:50:50.211Z","dependency_job_id":null,"html_url":"https://github.com/tohtsky/log_count_util","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tohtsky%2Flog_count_util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tohtsky%2Flog_count_util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tohtsky%2Flog_count_util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tohtsky%2Flog_count_util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tohtsky","download_url":"https://codeload.github.com/tohtsky/log_count_util/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245053700,"owners_count":20553379,"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":"2024-11-29T21:18:10.401Z","updated_at":"2025-03-23T04:22:06.736Z","avatar_url":"https://github.com/tohtsky.png","language":"C++","readme":"# log-count-utils\n\n## Introduction \u0026 Usage\n\nSuppose we have an action log data `df` like\n\n| user_id | timestamp           | expense |\n| ------: | :------------------ | ------: |\n|       0 | 2021-02-18 10:00:00 |     100 |\n|       0 | 2021-02-18 10:00:10 |      10 |\n|       0 | 2021-02-18 10:00:21 |       1 |\n|       0 | 2021-02-18 11:00:21 |     0.1 |\n|       1 | 2020-02-18 10:00:10 |     100 |\n|       1 | 2020-02-18 10:00:20 |      10 |\n|       1 | 2020-02-18 10:00:20 |       1 |\n|       1 | 2020-02-18 10:00:29 |       0 |\n\nSuppose that you have to compute the following quantity **for each row in this dataframe**:\n\n- the number of actions each user has taken within 10 seconds\n- total amount of expenses of a user within 10 seconds\n\nThe following naive way is fine for this tiny example but becomes costly (O(N^2)) for large data frame.\n\n```python\nfrom datetime import timedelta\nimport numpy as np\n\ntd = timedelta(seconds=10)\n\nanswers = []\nfor uid, time_point in zip(df.user_id, df.timestamp):\n    cnt = np.sum(\n        (df.user_id == uid) \u0026 (df.timestamp \u003c time_point) \u0026 (df.timestamp \u003e= (time_point - td))\n    )\n    answers.append(cnt)\n```\n\nIf `df` is sorted (by `user_id` as the primary and `timestamp` as the secondary key),\nwe can do this blazing fast (O(N)) using `log_count_util`.\n\n```python\nfrom log_count_util import find_n_records_within_interval\n\nanswers = find_n_records_within_interval(\n    df.user_id, df.timestamp, df_user_id, df.timestamp, td\n)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftohtsky%2Flog_count_util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftohtsky%2Flog_count_util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftohtsky%2Flog_count_util/lists"}