Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Risk Index calculation and add data sanitization #62

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Changes from 1 commit
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
14 changes: 9 additions & 5 deletions simglucose/analysis/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,20 @@ def percent_stats(BG, ax=None):


def risk_index_trace(df_BG, visualize=False):
chunk_BG = [df_BG.iloc[i:i + 60, :] for i in range(0, len(df_BG), 60)]
chunk_BG = [df_BG.iloc[i:i + 20, :] for i in range(0, len(df_BG), 20)]
yihuicai marked this conversation as resolved.
Show resolved Hide resolved

if len(chunk_BG[-1]) != 20: # Remove the last chunk which is not full
yihuicai marked this conversation as resolved.
Show resolved Hide resolved
chunk_BG.pop()

fBG = [
np.mean(1.509 * (np.log(BG[BG > 0])**1.084 - 5.381)) for BG in chunk_BG
1.509 * (np.log(BG[BG > 0]) ** 1.084 - 5.381) for BG in chunk_BG
]

fBG_df = pd.concat(fBG, axis=1).transpose()
rl = [(10 * (fbg * (fbg < 0))**2).mean() for fbg in fBG]
rh = [(10 * (fbg * (fbg > 0))**2).mean() for fbg in fBG]

LBGI = 10 * (fBG_df * (fBG_df < 0))**2
HBGI = 10 * (fBG_df * (fBG_df > 0))**2
LBGI = pd.concat(rl, axis=1).transpose()
HBGI = pd.concat(rh, axis=1).transpose()
RI = LBGI + HBGI

ri_per_hour = pd.concat(
Expand Down