private async Task SyncNightscoutBg() { using var nsr = new NightscoutReader(Configuration); await foreach (var pd in nsr.BgValues(DateTimeOffset.MinValue, DateTimeOffset.MaxValue)) { //InfluxWriteApi.WritePoint(Configuration.InfluxBucket, Configuration.InfluxOrgId, pd); } }
private async Task SetModelData() { using var nsReader = new NightscoutReader(App.Configuration); var tsvReader = new TsvReader(App.Configuration); var s = Model1.Series.FirstOrDefault() as LineSeries; if (s == null) { s = new LineSeries() { YAxisKey = "bg", Title = "BG", Color = OxyColor.FromRgb(255, 0, 0) }; Model1.Series.Add(s); } s.Points.Clear(); //var last = 0d; await foreach (var gv in nsReader.BgValues(Start, End)) { s.Points.Add(new DataPoint(DateTimeAxis.ToDouble(gv.Time.LocalDateTime), 400 - gv.Value)); //if (last != 0d) // BgSeriesDiff.Points.Add(new DataPoint(DateTimeAxis.ToDouble(gv.Time.LocalDateTime), (last - gv.Value)*GvFactor)); //last = gv.Value; } while (Model1.Series.Count > 1) { Model1.Series.RemoveAt(1); } await foreach (var ps in tsvReader.PodSessions(Start, End)) { if (ps.Hormone == HormoneType.InsulinAspart) { var simulationSerie = new LineSeries() { YAxisKey = "insulin", Color = OxyColor.FromRgb(35, 215, 255) }; foreach (var iv in InsulinModel.Run(ps, TimeSpan.FromHours(12))) { simulationSerie.Points.Add(new DataPoint( DateTimeAxis.ToDouble(iv.To.AddMinutes(SimulationShift).LocalDateTime), Axis.ToDouble(iv.Value))); } Model1.Series.Add(simulationSerie); //var simulationSerie = new LineSeries() //{ // YAxisKey = "insulin", // Color = OxyColor.FromRgb(35, 215, 255) //}; //foreach (var iv in InsulinModel2.Run(ps, TimeSpan.FromMinutes(25))) //{ // simulationSerie.Points.Add(new DataPoint( // DateTimeAxis.ToDouble(iv.Date.AddMinutes(SimulationShift).LocalDateTime), // Axis.ToDouble(iv.Value))); //} //Model1.Series.Add(simulationSerie); //var deliverySeries = new LineSeries() //{ // YAxisKey = "insulin", // Color = OxyColor.FromRgb(0,128,255), // LineStyle = LineStyle.Dash //}; //decimal? previous = null; //TimeSpan tv = TimeSpan.FromMinutes(25); //foreach (var fv in ps.GetRates()) //{ // //Debug.WriteLine($"{fv.From}\t{fv.To}\t{fv.Value}"); // if (previous.HasValue) // deliverySeries.Points.Add(new DataPoint(DateTimeAxis.ToDouble(fv.Time.LocalDateTime + tv), // Axis.ToDouble(previous.Value))); // deliverySeries.Points.Add(new DataPoint(DateTimeAxis.ToDouble(fv.Time.LocalDateTime + tv), // Axis.ToDouble(fv.Value))); // previous = fv.Value; // //deliverySeries.Points.Add(new DataPoint(DateTimeAxis.ToDouble(fv.To.LocalDateTime), // // Axis.ToDouble(fv.Value))); //} //deliverySeries.Points.Add(new DataPoint(DateTimeAxis.ToDouble(End.LocalDateTime + tv), // Axis.ToDouble(previous.Value))); //Model1.Series.Add(deliverySeries); } } }