A utility module to count/aggregate logs along time.
Project description
log-count-utils
Introduction & Usage
Suppose we have an action log data df
like
user_id | timestamp | expense |
---|---|---|
0 | 2021-02-18 10:00:00 | 100 |
0 | 2021-02-18 10:00:10 | 10 |
0 | 2021-02-18 10:00:21 | 1 |
0 | 2021-02-18 11:00:21 | 0.1 |
1 | 2020-02-18 10:00:10 | 100 |
1 | 2020-02-18 10:00:20 | 10 |
1 | 2020-02-18 10:00:20 | 1 |
1 | 2020-02-18 10:00:29 | 0 |
Suppose that you have to compute the following quantity for each row in this dataframe:
- the number of actions each user has taken within 10 seconds
- total amount of expenses of a user within 10 seconds
The following naive way is fine for this tiny example but becomes costly (O(N^2)) for large data frame.
from datetime import timedelta
import numpy as np
td = timedelta(seconds=10)
answers = []
for uid, time_point in zip(df.user_id, df.timestamp):
cnt = np.sum(
(df.user_id == uid) & (df.timestamp < time_point) & (df.timestamp >= (time_point - td))
)
answers.append(cnt)
If df
is sorted (by user_id
as the primary and timestamp
as the secondary key),
we can do this blazing fast (O(N)) using log_count_util
.
from log_count_util import find_n_records_within_interval
answers = find_n_records_within_interval(
df.user_id, df.timestamp, df_user_id, df.timestamp, td
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
log-count-util-0.1.0.tar.gz
(9.2 kB
view hashes)
Built Distributions
Close
Hashes for log_count_util-0.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2417d491fd4eb41716aa1f121940157157a13891d25cdc79bba74f2b30928b73 |
|
MD5 | a4fa83fc95bf5d04b600d195451d9f4d |
|
BLAKE2b-256 | e2325b54104aa929676027cd4febfb7783cae61de5e82a89d9f34e3f671377a5 |
Close
Hashes for log_count_util-0.1.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01df9b385f8433eebea33cc039233e020f93f0a79bf353e729b7ceaa0218c4dd |
|
MD5 | 6d597bcb2f9fc30712736d7ea021d306 |
|
BLAKE2b-256 | 72bd864b0f06306b5f1782ea455b37d116e506542f440ea3751754c508e9d3a8 |
Close
Hashes for log_count_util-0.1.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0416f117d61942f8de2ead92be5f70c0392349c05e02a3e3b00cc1c33c012bf |
|
MD5 | 4303c76d51b30ad81887548a467d7056 |
|
BLAKE2b-256 | ebb7617ba53974a5ecde1acd14a9f63990a67973383a6e4c040c2edc4d5c0e83 |
Close
Hashes for log_count_util-0.1.0-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89f747fa4d7ee4b30b3e646f474040ab0a44f4258d711682950abd4f4a3254b7 |
|
MD5 | 01f8501917506e897da1bacd8f56f157 |
|
BLAKE2b-256 | dcf1d39e4bb8f9726ba2882fd286bb5363826ae6549b84f1f308379ce3cdab02 |
Close
Hashes for log_count_util-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47b2903e3180240b7eed5983f0ff5ca0e23c9552325c71aff78e10ca288095cd |
|
MD5 | 6ec3b26946e02ed22f66e286dc978cfe |
|
BLAKE2b-256 | 930df2c69e8cd5141afb3f135e861be22e25bde1297d240a34a5c2a2595aa798 |
Close
Hashes for log_count_util-0.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bcc2a9164ba95288e2601c4e719acfcc6236bf1cbc324882e9ef48ed0236899 |
|
MD5 | 0f5959595ae57d902c8e53ff5fe0b08e |
|
BLAKE2b-256 | 2d38f867a36c7387c5be341614297e8a08ba05766676587cb168b1ef55b846cc |
Close
Hashes for log_count_util-0.1.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1ce2fb58421f2e6042293f5a8193dd512546c4963c68bd92000b6e0ba6280aa |
|
MD5 | 0dc5067f9a78e235652330f8e1dd273f |
|
BLAKE2b-256 | f45614710349adc075e77d20130eb30dfb704ca05c37a41254aea1d40250a504 |
Close
Hashes for log_count_util-0.1.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83afca16ac4f03129a84204af3c0a82ae7ba10d67f456e1cd45c7708b68cb015 |
|
MD5 | 91d7f13a21d16278add500499f126e79 |
|
BLAKE2b-256 | 69ac35bc17d798001908ad322a65ec135ee321946b01022d2c93997a48dbb518 |
Close
Hashes for log_count_util-0.1.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc02e0fc1c53f7375294487a4b8abfad43b0d88385de08420b56f36ccaf1e083 |
|
MD5 | 25c5268cce6508e71290f2803996692d |
|
BLAKE2b-256 | af0ce9be42f2aea7c6ec204daf6958848007433d37638e714999c0e1f4800362 |
Close
Hashes for log_count_util-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c71004f01ef2f51e980041d2726dfba4bac21db0884cf8897a882fd4e5f8a488 |
|
MD5 | 099bc987d234dae3e2f00bbb71a4a5e1 |
|
BLAKE2b-256 | f58332c078c7c069606513782d5c0d387e01e429174447c969cdc430a5cc66a5 |
Close
Hashes for log_count_util-0.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f41a3e260551607560f4e7e67b1e40aeeb90b720c51b4631429ab4ba7af6d68d |
|
MD5 | bc65b2e6708f36f6fb879dafe4b7f4d3 |
|
BLAKE2b-256 | cf1847ebf4d5aa83da69dcd5fc11809029ed0c2b4dade55edc3d1140ceb5dfc7 |
Close
Hashes for log_count_util-0.1.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 389789c0bb3a0bf8353b95b0df07e8be57793aad5c39df097c87a0fb4a5ab50f |
|
MD5 | e93d56d85db37fcd7f1d157d3f9e88a8 |
|
BLAKE2b-256 | deb69a7b69de95b8293554eab653b9977518192b87f1fd6357aa56ed6dfec19b |
Close
Hashes for log_count_util-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38bc9013bde76782fc553a2a7f66ce7a5416c9d31f6509b490cd769f956d82bf |
|
MD5 | c3c6dfae1ffaa129bfae9b86cda7b8eb |
|
BLAKE2b-256 | b2b07c824deda82fb0ef077b370dc0f2db1c9ecf05681e3533f50632d34a00d8 |
Close
Hashes for log_count_util-0.1.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30cdcfba566f18047a4c0506cefc5809c72a2cfed11023452a0339da38a50170 |
|
MD5 | be838a9d4c14e07c473b0b6bc7d8482b |
|
BLAKE2b-256 | 882fc3b4d3facc5c353e24c41dd46287e0327e89779b8d576abd8d43f3f4beef |
Close
Hashes for log_count_util-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fee0c67fb5f16e31f35ad2e624d5a7bb7fbe8c0e97c1856a14ceb271225199b0 |
|
MD5 | d3bf1a804f426b9af04932207d5e7b74 |
|
BLAKE2b-256 | c9a2eb52466905e52b3a2c655dcebd62c8d40e213741883e9d72c3cca043b27b |