Skip to content

Commit 154db59

Browse files
authored
Merge pull request #3 from staskh/fix_auc
Fix auc and clarify CGMS2DayByDay issues
2 parents 94614ef + 96f9c5e commit 154db59

11 files changed

Lines changed: 371 additions & 84 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Unless noted, iglu-r test is considered successful if it achieves precision of 0
3333
| cv_glu ||
3434
| cv_measures ||
3535
| ea1c ||
36-
| episode_calculation || || no match in lv1_hypo_excl and lv1_hyper_excl|
36+
| episode_calculation || || |
3737
| gmi ||
3838
| grade_eugly ||
3939
| grade_hyper ||
@@ -49,7 +49,7 @@ Unless noted, iglu-r test is considered successful if it achieves precision of 0
4949
| lbgi ||
5050
| mad_glu ||
5151
| mag || || IMHO, Original R implementation has an error |
52-
| mage || || See algorithm at [MAGE](https://github.com/irinagain/iglu/blob/master/vignettes/MAGE.Rmd) |
52+
| mage || || See algorithm at [MAGE](https://irinagain.github.io/iglu/articles/MAGE.html) |
5353
| mean_glu ||
5454
| median_glu ||
5555
| modd ||

R_REVIEW.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
(length(na.omit(diffs))*n/60)
88
```
99

10+
## AUC
11+
12+
```
13+
day = rep(data_ip[[2]], 1440/dt0),
14+
```
15+
Generate sequence of days repeated 1440/dt0, while it has to have each day repeated by 1440/dt0 and followed by the next
16+
1017
## CGMS2DayByDay
1118

1219
[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")))`

iglu_python/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from .sd_measures import sd_measures
3838
from .sd_roc import sd_roc
3939
from .summary_glu import summary_glu
40-
from .utils import IGLU_R_COMPATIBLE, CGMS2DayByDay, check_data_columns, gd2d_to_df
40+
from .utils import set_iglu_r_compatible, is_iglu_r_compatible, CGMS2DayByDay, check_data_columns, gd2d_to_df
4141

4242
__all__ = [
4343
"above_percent",
@@ -62,7 +62,8 @@
6262
"hyper_index",
6363
"hypo_index",
6464
"igc",
65-
"IGLU_R_COMPATIBLE",
65+
"set_iglu_r_compatible",
66+
"is_iglu_r_compatible",
6667
"in_range_percent",
6768
"iqr_glu",
6869
"j_index",

iglu_python/auc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import numpy as np
33
import pandas as pd
44

5-
from .utils import CGMS2DayByDay, check_data_columns, gd2d_to_df, IGLU_R_COMPATIBLE
5+
from .utils import CGMS2DayByDay, check_data_columns, gd2d_to_df, is_iglu_r_compatible
6+
67

78

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

6667
# Convert gd2d to DataFrame
6768
input_data = gd2d_to_df(gd2d, actual_dates, dt0)
68-
if IGLU_R_COMPATIBLE:
69+
if is_iglu_r_compatible():
6970
input_data['day'] = input_data['time'].dt.floor('d')
7071
input_data['gl_next'] = input_data['gl'].shift(-1)
7172
each_day_area = input_data.groupby("day").apply(

iglu_python/episode_calculation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
import pandas as pd
55

6-
from .utils import IGLU_R_COMPATIBLE, CGMS2DayByDay, check_data_columns, gd2d_to_df, get_local_tz
6+
from .utils import CGMS2DayByDay, check_data_columns, gd2d_to_df, get_local_tz, is_iglu_r_compatible
77

88

99
def episode_calculation(
@@ -235,7 +235,7 @@ def episode_single(
235235
if dt0 is None:
236236
dt0 = gd2d_tuple[2]
237237

238-
if IGLU_R_COMPATIBLE:
238+
if is_iglu_r_compatible():
239239
day_one = pd.to_datetime(gd2d_tuple[1][0]).tz_localize(None) # make in naive-timezone
240240
day_one = day_one.tz_localize('UTC') # this is how IGLU_R works
241241
if tz and tz!="":

iglu_python/mag.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import numpy as np
44
import pandas as pd
55

6-
from .utils import CGMS2DayByDay, check_data_columns, IGLU_R_COMPATIBLE
6+
from .utils import CGMS2DayByDay, check_data_columns, is_iglu_r_compatible
7+
78

89

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

96-
if IGLU_R_COMPATIBLE:
97+
if is_iglu_r_compatible():
9798
idx = np.arange(0,len(gl_values),lag)
9899
gl_values_idx = gl_values[idx]
99100
diffs = gl_values_idx[1:] - gl_values_idx[:-1]

iglu_python/utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99

1010
local_tz = get_localzone() # get the local timezone
1111

12-
IGLU_R_COMPATIBLE = True
12+
_IGLU_R_COMPATIBLE = True
13+
14+
def set_iglu_r_compatible(value: bool) -> None:
15+
global _IGLU_R_COMPATIBLE
16+
_IGLU_R_COMPATIBLE = value
17+
18+
def is_iglu_r_compatible() -> bool:
19+
global _IGLU_R_COMPATIBLE
20+
return _IGLU_R_COMPATIBLE
1321

1422
def localize_naive_timestamp(timestamp: datetime) -> datetime:
1523
"""
@@ -180,7 +188,7 @@ def CGMS2DayByDay(
180188
time_grid = pd.date_range(
181189
start=start_time, end=end_time, freq=f"{dt0}min"
182190
)
183-
if IGLU_R_COMPATIBLE:
191+
if is_iglu_r_compatible():
184192
# remove the first time point
185193
time_grid = time_grid[1:]
186194
else:
@@ -234,7 +242,7 @@ def CGMS2DayByDay(
234242
interp_data = interp_data.reshape(n_days, n_points_per_day)
235243

236244
# Get actual dates
237-
if IGLU_R_COMPATIBLE:
245+
if is_iglu_r_compatible():
238246
# convert start_time into naive datetime
239247
start_time = start_time.tz_localize(None)
240248

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

256264
df = pd.DataFrame({
257-
"time": pd.Series(time, dtype='datetime64[ns]'),
265+
"time": pd.Series(time),
258266
"gl": pd.Series(gl, dtype='float64')
259267
})
260268

0 commit comments

Comments
 (0)