private static async Task <(Bolus?, ExtendedBolus?)> ParseExtendedBolus(NsTreatment treatment) { ExtendedBolus?extendedBolus = null; Bolus? bolus = null; var duration = treatment.duration ?? 0; var amount = treatment.enteredinsulin?.Round(0.05m) ?? 0; var splitExt = treatment.splitExt ?? 0; var splitNow = treatment.splitNow ?? 0; var amountExt = (amount * splitExt / 100.0).Round(0.05m); if (amountExt > 0) { extendedBolus = new ExtendedBolus { Time = treatment.EventDate.Value, Duration = (int)duration, Amount = amount } } ; var amountNow = (amount * splitNow / 100.0).Round(0.05m); if (amountNow > 0) { bolus = new Bolus { Time = treatment.EventDate.Value, Amount = amount } } ; return(bolus, extendedBolus); }
private static async Task <TempBasal?> ParseTempBasal(NsTreatment treatment) { var duration = treatment.duration ?? 0; double?absoluteRate = treatment.absolute?.Round(0.05m); var percentage = treatment.percent ?? 0; return(new TempBasal { Time = treatment.EventDate.Value, Duration = (int)duration, AbsoluteRate = absoluteRate, Percentage = percentage }); }
private static async Task <Carb?> ParseCarbs(NsTreatment treatment) { var amount = treatment.carbs?.Round(0.1m) ?? 0; if (amount <= 0) { return(null); } return(new Carb { Time = treatment.EventDate.Value, Amount = amount }); }
private async Task <BasalProfile?> ParseProfileSwitch(NsTreatment treatment) { BasalProfile?ret = null; var profileSwitchTime = treatment.EventDate.Value; var joProfile = JObject.Parse(treatment.profileJson); try { int percentage = treatment.percentage ?? 100; int timeShift = treatment.timeshift ?? 0; int duration = (int)(treatment.duration ?? 0); int utcOffset; if (joProfile.ContainsKey("timezone")) { var tzString = joProfile["timezone"].ToString(); var tzi = TZConvert.GetTimeZoneInfo(tzString); // including dst at the time of profile switch // as the pod does not switch timezones or dst, // there has to be an explicit profile switch entry for each change in local time utcOffset = (int)tzi.GetUtcOffset(profileSwitchTime).TotalMinutes; } else { utcOffset = treatment.utcOffset ?? 0; } var rates = await GetBasalRates(joProfile, percentage); if (rates != null) { ret = new BasalProfile() { Time = profileSwitchTime, BasalRates = rates, UtcOffsetInMinutes = utcOffset + timeShift, Duration = duration }; } } catch { } return(ret); }