improvements

- De limits zijn nu smooth in de tijd (linear interpolation)
- De slopes zijn nu strakker voor de comp grafiek
- De melding toont nu ook de hours_since_last_bolus
This commit is contained in:
gjkoolen 2025-02-24 23:04:51 +01:00
parent 2fe11e857a
commit 153ce6b02e

View file

@ -33,18 +33,20 @@ headers = {
limits_table = [
[ [20, 99], # hour 0 constants after compensating /c [max_level, max_pos_slope, max_neg_slope]
[16, 99], # hour 1
[12, 6], # hour 2
[10, 6], # hour 3
[10, 6] ], # hour 4
[ [20, 99], # hour 0 constants after eating /e [max_level, max_pos_slope, max_neg_slope]
[12, 3], # hour 2
[10, 3], # hour 3
[10, 4], # hour 4
[10, 4] ], # extra dunplicate
[ [22, 99], # hour 0 constants after eating /e [max_level, max_pos_slope, max_neg_slope]
[18, 99], # hour 1
[14, 6], # hour 2
[15, 6], # hour 2
[12, 6], # hour 3
[10, 6] ] # hour 4
[10, 4], # hour 4
[10, 4] ] # extra dunplicate
]
limits_max_hours = 4 # nr of hours in the above lists
last_bolus_time = time.time()-7200
last_bolus_time = time.time()-3600
last_bolus_type = 0
GLUC_READOUT_PERIOD = 5 # in minutes
@ -90,13 +92,16 @@ def main(url_main, headers_main):
print(f"time.time: {time.time()}")
print(f"last_bolus_time: {last_bolus_time}")
seconds_since_last_bolus = time.time() - last_bolus_time
hours_since_last_bolus = int(min((seconds_since_last_bolus / 3600) , limits_max_hours))
print(f"hrs after last bolus: {hours_since_last_bolus}")
hours_since_last_bolus = min((seconds_since_last_bolus / 3600) , limits_max_hours)
print(f"hrs after last bolus: {round(hours_since_last_bolus, 1)}")
if ((gluc_value > limits_table[last_bolus_type][hours_since_last_bolus][0]) or
# linear interpolation of gluc_upper_limit = a[int] + (a[int+1]-a[n]) * frac_part
gluc_upper_limit = limits_table[last_bolus_type][int(hours_since_last_bolus)][0] +
(limits_table[last_bolus_type][int(hours_since_last_bolus+1)][0] - limits_table[last_bolus_type][int(hours_since_last_bolus)][0]) * (hours_since_last_bolus-int(hours_since_last_bolus))
if ((gluc_value > gluc_upper_limit) or
(gluc_slope > limits_table[last_bolus_type][hours_since_last_bolus][1])):
print("Hey joh check je glucosepeil !")
Mqtt.publish(send_topic, "Hey joh check je glucosepeil !")
Mqtt.publish(send_topic, f"Hey joh check peil ! (lastbolus -{round(hours_since_last_bolus, 1)})")
else: # Request has failed