Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Unless noted, iglu-r test is considered successful if it achieves precision of 0
| cv_glu | ✅ |
| cv_measures | ✅ |
| ea1c | ✅ |
| episode_calculation | ✅| || no match in lv1_hypo_excl and lv1_hyper_excl|
| episode_calculation | ✅| || |
| gmi | ✅ |
| grade_eugly | ✅ |
| grade_hyper | ✅ |
Expand All @@ -49,7 +49,7 @@ Unless noted, iglu-r test is considered successful if it achieves precision of 0
| lbgi | ✅ |
| mad_glu | ✅ |
| mag | ✅ | || IMHO, Original R implementation has an error |
| mage | ✅ | || See algorithm at [MAGE](https://github.com/irinagain/iglu/blob/master/vignettes/MAGE.Rmd) |
| mage | ✅ | || See algorithm at [MAGE](https://irinagain.github.io/iglu/articles/MAGE.html) |
| mean_glu | ✅ |
| median_glu | ✅ |
| modd | ✅ |
Expand Down
7 changes: 7 additions & 0 deletions R_REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
(length(na.omit(diffs))*n/60)
```

## AUC

```
day = rep(data_ip[[2]], 1440/dt0),
```
Generate sequence of days repeated 1440/dt0, while it has to have each day repeated by 1440/dt0 and followed by the next

## CGMS2DayByDay

[ndays = ceiling(as.double(difftime(max(tr), min(tr), units = "days")) + 1)](https://github.com/irinagain/iglu/blob/82e4d1a39901847881d5402d1ac61b3e678d2a5e/R/utils.R#L208) has to be ndays = ceiling(as.double(difftime(max(tr), min(tr), units = "days")))`
Expand Down
5 changes: 3 additions & 2 deletions iglu_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from .sd_measures import sd_measures
from .sd_roc import sd_roc
from .summary_glu import summary_glu
from .utils import IGLU_R_COMPATIBLE, CGMS2DayByDay, check_data_columns, gd2d_to_df
from .utils import set_iglu_r_compatible, is_iglu_r_compatible, CGMS2DayByDay, check_data_columns, gd2d_to_df

__all__ = [
"above_percent",
Expand All @@ -62,7 +62,8 @@
"hyper_index",
"hypo_index",
"igc",
"IGLU_R_COMPATIBLE",
"set_iglu_r_compatible",
"is_iglu_r_compatible",
"in_range_percent",
"iqr_glu",
"j_index",
Expand Down
5 changes: 3 additions & 2 deletions iglu_python/auc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import numpy as np
import pandas as pd

from .utils import CGMS2DayByDay, check_data_columns, gd2d_to_df, IGLU_R_COMPATIBLE
from .utils import CGMS2DayByDay, check_data_columns, gd2d_to_df, is_iglu_r_compatible



def auc(data: pd.DataFrame, tz: str = "") -> pd.DataFrame:
Expand Down Expand Up @@ -65,7 +66,7 @@ def auc_single(subject_data: pd.DataFrame) -> float:

# Convert gd2d to DataFrame
input_data = gd2d_to_df(gd2d, actual_dates, dt0)
if IGLU_R_COMPATIBLE:
if is_iglu_r_compatible():
input_data['day'] = input_data['time'].dt.floor('d')
input_data['gl_next'] = input_data['gl'].shift(-1)
each_day_area = input_data.groupby("day").apply(
Expand Down
4 changes: 2 additions & 2 deletions iglu_python/episode_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pandas as pd

from .utils import IGLU_R_COMPATIBLE, CGMS2DayByDay, check_data_columns, gd2d_to_df, get_local_tz
from .utils import CGMS2DayByDay, check_data_columns, gd2d_to_df, get_local_tz, is_iglu_r_compatible


def episode_calculation(
Expand Down Expand Up @@ -235,7 +235,7 @@ def episode_single(
if dt0 is None:
dt0 = gd2d_tuple[2]

if IGLU_R_COMPATIBLE:
if is_iglu_r_compatible():
day_one = pd.to_datetime(gd2d_tuple[1][0]).tz_localize(None) # make in naive-timezone
day_one = day_one.tz_localize('UTC') # this is how IGLU_R works
if tz and tz!="":
Expand Down
5 changes: 3 additions & 2 deletions iglu_python/mag.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import numpy as np
import pandas as pd

from .utils import CGMS2DayByDay, check_data_columns, IGLU_R_COMPATIBLE
from .utils import CGMS2DayByDay, check_data_columns, is_iglu_r_compatible



def mag(
Expand Down Expand Up @@ -93,7 +94,7 @@ def mag_single(data: pd.DataFrame, n: int) -> float:
# Calculate absolute differences between readings n minutes apart
lag = readings_per_interval

if IGLU_R_COMPATIBLE:
if is_iglu_r_compatible():
idx = np.arange(0,len(gl_values),lag)
gl_values_idx = gl_values[idx]
diffs = gl_values_idx[1:] - gl_values_idx[:-1]
Expand Down
16 changes: 12 additions & 4 deletions iglu_python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@

local_tz = get_localzone() # get the local timezone

IGLU_R_COMPATIBLE = True
_IGLU_R_COMPATIBLE = True

def set_iglu_r_compatible(value: bool) -> None:
global _IGLU_R_COMPATIBLE
_IGLU_R_COMPATIBLE = value

def is_iglu_r_compatible() -> bool:
global _IGLU_R_COMPATIBLE
return _IGLU_R_COMPATIBLE

def localize_naive_timestamp(timestamp: datetime) -> datetime:
"""
Expand Down Expand Up @@ -180,7 +188,7 @@ def CGMS2DayByDay(
time_grid = pd.date_range(
start=start_time, end=end_time, freq=f"{dt0}min"
)
if IGLU_R_COMPATIBLE:
if is_iglu_r_compatible():
# remove the first time point
time_grid = time_grid[1:]
else:
Expand Down Expand Up @@ -234,7 +242,7 @@ def CGMS2DayByDay(
interp_data = interp_data.reshape(n_days, n_points_per_day)

# Get actual dates
if IGLU_R_COMPATIBLE:
if is_iglu_r_compatible():
# convert start_time into naive datetime
start_time = start_time.tz_localize(None)

Expand All @@ -254,7 +262,7 @@ def gd2d_to_df(gd2d, actual_dates, dt0):
time.extend(day_time)

df = pd.DataFrame({
"time": pd.Series(time, dtype='datetime64[ns]'),
"time": pd.Series(time),
"gl": pd.Series(gl, dtype='float64')
})

Expand Down
Loading
Loading