Skip to content

Commit

Permalink
Fix Risk Index calculation and add data sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuicai committed Jul 25, 2023
1 parent 3053386 commit 547b227
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions simglucose/analysis/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ 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)]

if len(chunk_BG[-1]) != 20: # Remove the last chunk which is not full
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]).mean() ** 1.084 - 5.381) for BG in chunk_BG
]

fBG_df = pd.concat(fBG, axis=1).transpose()
Expand Down

0 comments on commit 547b227

Please sign in to comment.