Ejemplo n.º 1
0
 public void TestNoNormalization()
 {
     //a bunch of zero-index activities just to stave off normalization
     var sim1 = new Simulator(new Activity[] {
         new FoodActivity(new Data.FoodData { GlycemicIndex = 10 }, TimeSpan.FromHours(1)),
         new ExerciseActivity(new Data.ExerciseData { ExerciseIndex = 0 }, TimeSpan.FromHours(2)),
         new ExerciseActivity(new Data.ExerciseData { ExerciseIndex = 0 }, TimeSpan.FromHours(3)),
         new FoodActivity(new Data.FoodData { GlycemicIndex = 0 }, TimeSpan.FromHours(4)),
         new FoodActivity(new Data.FoodData { GlycemicIndex = 0 }, TimeSpan.FromHours(5)),
         new FoodActivity(new Data.FoodData { GlycemicIndex = 0 }, TimeSpan.FromHours(7) + TimeSpan.FromMinutes(5)),
     });
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(-1)), 0.00001);
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(0)), 0.00001);
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(1)), 0.00001);
     Assert.AreEqual(85, sim1.GetBloodSugar(TimeSpan.FromHours(2)), 0.00001);
     Assert.AreEqual(90, sim1.GetBloodSugar(TimeSpan.FromHours(3)), 0.00001);
     Assert.AreEqual(90, sim1.GetBloodSugar(TimeSpan.FromMinutes(181)), 0.00001);
     Assert.AreEqual(90, sim1.GetBloodSugar(TimeSpan.FromHours(4)), 0.00001);
     Assert.AreEqual(90, sim1.GetBloodSugar(TimeSpan.FromHours(5)), 0.00001);
     Assert.AreEqual(90, sim1.GetBloodSugar(TimeSpan.FromHours(6)), 0.00001);
     Assert.AreEqual(90, sim1.GetBloodSugar(TimeSpan.FromHours(7)), 0.00001);
     Assert.AreEqual(85, sim1.GetBloodSugar(TimeSpan.FromHours(8)), 0.00001);
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(99)), 0.00001);
     Assert.AreEqual(0, sim1.GetCumulativeGlycation(TimeSpan.FromHours(99)), 0.00001);
 }
Ejemplo n.º 2
0
 public void TestOneExercise()
 {
     var sim1 = new Simulator(new Activity[] {
         new ExerciseActivity(new Data.ExerciseData { ExerciseIndex = 10 }, TimeSpan.FromHours(1)),
     });
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(-1)), 0.00001);
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(0)), 0.00001);
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(1)), 0.00001);
     Assert.AreEqual(75, sim1.GetBloodSugar(TimeSpan.FromHours(1.5)), 0.00001);
     Assert.AreEqual(70, sim1.GetBloodSugar(TimeSpan.FromHours(2)), 0.00001);
     Assert.AreEqual(71, sim1.GetBloodSugar(TimeSpan.FromMinutes(121)), 0.00001);
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(99)), 0.00001);
     Assert.AreEqual(00, sim1.GetCumulativeGlycation(TimeSpan.FromHours(99)), 0.00001);
 }
Ejemplo n.º 3
0
 public void TestBasicGlycation()
 {
     var sim1 = new Simulator(new Activity[] {
         new FoodActivity(new Data.FoodData { GlycemicIndex = 140 }, TimeSpan.FromHours(1)),
     });
     Assert.AreEqual(0, sim1.GetCumulativeGlycation(TimeSpan.FromHours(0)), 0.00001);
     Assert.AreEqual(0, sim1.GetCumulativeGlycation(TimeSpan.FromHours(1)), 0.00001);
     Assert.AreEqual(0, sim1.GetCumulativeGlycation(TimeSpan.FromMinutes(120)), 0.00001); //blood sugar now exactly equal to 150, but not "above" so no glycation yet
     Assert.AreEqual(1, sim1.GetCumulativeGlycation(TimeSpan.FromMinutes(121)), 0.00001);
     Assert.AreEqual(2, sim1.GetCumulativeGlycation(TimeSpan.FromMinutes(122)), 0.00001);
     Assert.AreEqual(128, sim1.GetCumulativeGlycation(TimeSpan.FromMinutes(248)), 0.00001);
     Assert.AreEqual(129, sim1.GetCumulativeGlycation(TimeSpan.FromMinutes(249)), 0.00001);
     Assert.AreEqual(129, sim1.GetCumulativeGlycation(TimeSpan.FromMinutes(250)), 0.00001); //blood sugar now exactly equal to 150 again, but not "above" so no additional glycation
     Assert.AreEqual(129, sim1.GetCumulativeGlycation(TimeSpan.FromMinutes(999)), 0.00001);
 }
Ejemplo n.º 4
0
        private void GenerateGraph()
        {
            zedGraphControl.GraphPane.CurveList.Clear();
            var sim = new Simulator(Activities);
            //figure out any points where the graph potentially changes slope:
            var xValues = sim.GetActivitiesAndNormalizations()
                .SelectMany(x => new[] {x.ActivityTime, x.ActivityTime + x.Onset})
                .Union(new[] {TimeSpan.FromHours(0), TimeSpan.FromHours(24)})
                .Distinct()
                .OrderBy(x => x)
                .ToList();

            //Add any starting or ending points for glycation, when blood sugar crosses 150:
            var crossovers = new List<TimeSpan>();
            for (int i = 0; i + 1 < xValues.Count; i++) {
                if (Math.Sign(sim.GetBloodSugar(xValues[i]) - 150) != Math.Sign(sim.GetBloodSugar(xValues[i + 1]) - 150)) {
                    var fractionOfTime = (150 - sim.GetBloodSugar(xValues[i])) / (sim.GetBloodSugar(xValues[i + 1]) - sim.GetBloodSugar(xValues[i]));
                    crossovers.Add(xValues[i] + TimeSpan.FromMinutes(fractionOfTime * (xValues[i + 1] - xValues[i]).TotalMinutes));
                }
            }
            xValues = xValues.Union(crossovers).Distinct().OrderBy(x => x).ToList();

            var bloodSugar = new ZedGraph.PointPairList();
            foreach (var time in xValues) {
                double sugar = sim.GetBloodSugar(time);
                bloodSugar.Add(new ZedGraph.PointPair(time.TotalHours, sugar));
            }

            var glycation = new ZedGraph.PointPairList();
            foreach (var time in xValues) {
                double gly = sim.GetCumulativeGlycation(time);
                glycation.Add(new ZedGraph.PointPair(time.TotalHours, gly));
            }

            var foodEvents = new ZedGraph.PointPairList();
            foreach (var time in Activities.OfType<FoodActivity>().Select(x => x.ActivityTime)) {
                double point = sim.GetBloodSugar(time);
                foodEvents.Add(new ZedGraph.PointPair(time.TotalHours, point));
            }

            var exerciseEvents = new ZedGraph.PointPairList();
            foreach (var time in Activities.OfType<ExerciseActivity>().Select(x => x.ActivityTime)) {
                double point = sim.GetBloodSugar(time);
                exerciseEvents.Add(new ZedGraph.PointPair(time.TotalHours, point));
            }

            var threshold = new ZedGraph.PointPairList(new[] {0.0, 24.0}, new[] {150.0, 150.0});

            zedGraphControl.GraphPane.AddCurve("Blood Sugar", bloodSugar, Color.Green, ZedGraph.SymbolType.None);
            zedGraphControl.GraphPane.AddCurve("Cumulative Glycation", glycation, Color.Red, ZedGraph.SymbolType.None);
            var line = zedGraphControl.GraphPane.AddCurve("Glycation threshold", threshold, Color.Red,
                ZedGraph.SymbolType.HDash);
            line.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
            var food = zedGraphControl.GraphPane.AddCurve("", foodEvents, Color.Red, ZedGraph.SymbolType.Triangle);
            food.Line.IsVisible = false;
            food.Symbol.Fill.Type = ZedGraph.FillType.Solid;
            var exercise = zedGraphControl.GraphPane.AddCurve("", exerciseEvents, Color.Green,
                ZedGraph.SymbolType.TriangleDown);
            exercise.Line.IsVisible = false;
            exercise.Symbol.Fill.Type = ZedGraph.FillType.Solid;
            zedGraphControl.RestoreScale(zedGraphControl.GraphPane);
        }
Ejemplo n.º 5
0
 public void TestOneFood()
 {
     var sim1 = new Simulator(new Activity[] {
         new FoodActivity(new Data.FoodData { GlycemicIndex = 10 }, TimeSpan.FromHours(1)),
     });
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(-1)), 0.00001);
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(0)), 0.00001);
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(1)), 0.00001);
     Assert.AreEqual(85, sim1.GetBloodSugar(TimeSpan.FromHours(2)), 0.00001);
     Assert.AreEqual(90, sim1.GetBloodSugar(TimeSpan.FromHours(3)), 0.00001);
     Assert.AreEqual(89, sim1.GetBloodSugar(TimeSpan.FromMinutes(181)), 0.00001);
     Assert.AreEqual(80, sim1.GetBloodSugar(TimeSpan.FromHours(99)), 0.00001);
     Assert.AreEqual(0, sim1.GetCumulativeGlycation(TimeSpan.FromHours(99)), 0.00001);
 }