Skip to content

Commit

Permalink
Added sum_within_interval
Browse files Browse the repository at this point in the history
  • Loading branch information
tohtsky committed Feb 18, 2021
1 parent 8284319 commit e39ebd8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ stubs
**.pyc
**settings.json
.python-version
.eggs
59 changes: 29 additions & 30 deletions log_count_util/_core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,49 @@ n: int
from numpy import float64, int64

import log_count_util._core
from typing import *
from typing import Iterable as iterable
from typing import Iterator as iterator
from numpy import float64

_Shape = Tuple[int, ...]
import typing
import numpy

_Shape = typing.Tuple[int, ...]

__all__ = [
"find_last_record_index",
"find_last_record_index_f",
"find_n_record_before",
"find_records_within_interval",
"sum_records_within_interval",
]

def find_last_record_index(
query_ids: numpy.ndarray[int64],
query_datetime: numpy.ndarray[int64],
target_id: numpy.ndarray[int64],
target_datetime: numpy.ndarray[int64],
) -> numpy.ndarray[int64]:
pass

def find_last_record_index_f(
query_ids: numpy.ndarray[int64],
query_datetime: numpy.ndarray[int64],
target_id: numpy.ndarray[int64],
target_datetime: numpy.ndarray[int64],
) -> numpy.ndarray[int64]:
query_ids: numpy.ndarray[numpy.int64],
query_datetime: numpy.ndarray[numpy.int64],
target_id: numpy.ndarray[numpy.int64],
target_datetime: numpy.ndarray[numpy.int64],
) -> numpy.ndarray[numpy.int64]:
pass

def find_n_record_before(
query_ids: numpy.ndarray[int64],
query_datetime: numpy.ndarray[int64],
target_id: numpy.ndarray[int64],
target_datetime: numpy.ndarray[int64],
) -> numpy.ndarray[int64]:
query_ids: numpy.ndarray[numpy.int64],
query_datetime: numpy.ndarray[numpy.int64],
target_id: numpy.ndarray[numpy.int64],
target_datetime: numpy.ndarray[numpy.int64],
) -> numpy.ndarray[numpy.int64]:
pass

def find_records_within_interval(
query_ids: numpy.ndarray[int64],
query_datetime: numpy.ndarray[int64],
target_id: numpy.ndarray[int64],
target_datetime: numpy.ndarray[int64],
query_ids: numpy.ndarray[numpy.int64],
query_datetime: numpy.ndarray[numpy.int64],
target_id: numpy.ndarray[numpy.int64],
target_datetime: numpy.ndarray[numpy.int64],
days: int,
) -> numpy.ndarray[numpy.int64]:
pass

def sum_records_within_interval(
query_ids: numpy.ndarray[numpy.int64],
query_datetime: numpy.ndarray[numpy.int64],
target_id: numpy.ndarray[numpy.int64],
target_datetime: numpy.ndarray[numpy.int64],
target_values: numpy.ndarray[numpy.int64],
days: int,
) -> numpy.ndarray[int64]:
) -> numpy.ndarray[numpy.int64]:
pass
32 changes: 25 additions & 7 deletions log_count_util/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import numpy as np
from numpy import typing as npt

from ._core import (
find_last_record_index,
find_last_record_index_f,
find_n_record_before,
find_records_within_interval,
)
from ._core import find_last_record_index, find_n_record_before
from ._core import find_records_within_interval as find_records_within_interval_core
from ._core import sum_records_within_interval as sum_records_within_interval_core


def datetime_array_to_int(arr: np.ndarray) -> np.ndarray:
Expand All @@ -25,6 +22,27 @@ def find_n_records_within_interval(
query_datetime_ns = datetime_array_to_int(query_datetime)
target_datetime_ns = datetime_array_to_int(target_datetime)
interval_in_ns = int(interval.total_seconds() * 10 ** 9)
return find_records_within_interval(
return find_records_within_interval_core(
query_ids, query_datetime_ns, target_ids, target_datetime_ns, interval_in_ns
)


def sum_records_within_interval(
query_ids: np.ndarray,
query_datetime: np.ndarray,
target_ids: np.ndarray,
target_datetime: np.ndarray,
target_values: np.ndarray,
interval: timedelta,
) -> np.ndarray:
query_datetime_ns = datetime_array_to_int(query_datetime)
target_datetime_ns = datetime_array_to_int(target_datetime)
interval_in_ns = int(interval.total_seconds() * 10 ** 9)
return sum_records_within_interval_core(
query_ids,
query_datetime_ns,
target_ids,
target_datetime_ns,
target_values.astype(np.float64),
interval_in_ns,
)
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[mypy]
python_version=3.8
platform=linux

show_column_numbers=True

follow_imports=normal

# suppress errors about unsatisfied imports
Expand Down

0 comments on commit e39ebd8

Please sign in to comment.