-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parameterized sample rate for risk index caculation; Added UT
- Loading branch information
Showing
3 changed files
with
59 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from simglucose.analysis.report import risk_index_trace | ||
from simglucose.sensor.cgm import CGMSensor | ||
from simglucose.simulation.rendering import Viewer | ||
from datetime import datetime | ||
import pandas as pd | ||
import unittest | ||
import logging | ||
import os | ||
|
||
logger = logging.getLogger(__name__) | ||
TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), 'sim_results.csv') | ||
|
||
|
||
class TestReport(unittest.TestCase): | ||
def setUp(self): | ||
self.df = pd.concat([pd.read_csv(TESTDATA_FILENAME, index_col=0)], keys=['test']) | ||
|
||
def test_risk_index_trace(self): | ||
BG = self.df.unstack(level=0).BG | ||
sample_time = CGMSensor.withName("Dexcom").sample_time | ||
sample_rate = int(60 / sample_time) | ||
ri_per_hour, ri_mean, fig, axes = risk_index_trace(BG, sample_rate) | ||
|
||
LBGI = ri_per_hour.transpose().LBGI | ||
HBGI = ri_per_hour.transpose().HBGI | ||
RI = ri_per_hour.transpose()["Risk Index"] | ||
|
||
self.assertEqual(LBGI.size, 48) | ||
self.assertEqual(LBGI.iloc[-1].test, 0.8429957158900777) | ||
self.assertEqual(LBGI.iloc[0].test, 0.0) | ||
|
||
self.assertEqual(HBGI.size, 48) | ||
self.assertEqual(HBGI.iloc[-1].test, 0.0) | ||
self.assertEqual(HBGI.iloc[0].test, 2.755277346918188) | ||
|
||
self.assertEqual(RI.size, 48) | ||
self.assertEqual(RI.iloc[-1].test, 0.8429957158900777) | ||
self.assertEqual(RI.iloc[0].test, 2.755277346918188) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |