Skip to content

Commit

Permalink
Merge pull request #155 from TrafficCop/main
Browse files Browse the repository at this point in the history
Made Nutrisense CGM Generator more reasonable
  • Loading branch information
TrafficCop committed Mar 1, 2024
2 parents 4e8caf0 + 1015997 commit cfc3e29
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions wearipedia/devices/nutrisense/cgm_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def gen_glucose(t, index, seed=0):
X.append(x)
Y.append(y)

added = local_rng.normal(scale=1) * 10 + 0.01 * (160 / y)
added = sorted([-1.1, local_rng.normal(scale=1), 1.1])[1] * 10 + 0.01 * (
160 / y
)
if y < 75:
added = abs(added)
elif y > 135:
Expand Down Expand Up @@ -160,17 +162,7 @@ def gen_stats(Y, weekly=False):
:rtype: dict
"""

# if weekly, statistics not based on synthetic data Y, generate randomly
if weekly:
low = randint(70, 110)
high = randint(low, 140)
median = randint(low, high)
std = randint(0, 10)
q1 = randint(low, median)
q3 = randint(median, high)
timeWithinRange = randint(0, 100)
avg = randint(low, high)
else:
low, high = min(Y), max(Y)
median = np.median(Y)
std = tstd(Y)
Expand All @@ -180,6 +172,15 @@ def gen_stats(Y, weekly=False):
condition = greater & less
timeWithinRange = float(len(np.extract(condition, Y)))
avg = np.average(Y)
else:
low = randint(min(Y), 110)
high = randint(low, max(Y))
median = randint(low, high)
std = randint(0, 10)
q1 = randint(low, median)
q3 = randint(median, high)
timeWithinRange = randint(0, 100)
avg = randint(low, high)

first = {"min": 70.0, "max": 140.0, "__typename": "Range"}
second = {"min": low, "max": high, "__typename": "Range"}
Expand Down

0 comments on commit cfc3e29

Please sign in to comment.