Ejemplo n.º 1
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     if (string.IsNullOrEmpty(App.FacebookId))
         NavigationService.Navigate(new Uri("/FacebookLoginPage.xaml", UriKind.Relative));
     _flag = Guid.NewGuid().ToString();
     var fid = string.IsNullOrEmpty(App.FacebookId) ? "-1" : App.FacebookId;
     _bigCycle = new SleepData(_flag, fid);
     _cycle = new SleepData(_flag, fid);
     timePicker.Value = DateTime.Now.AddHours(7);
 }
Ejemplo n.º 2
0
        private void ThreadSafeAccelerometerChanged(AccelerometerReadingEventArgs e)
        {
            var move = AccelerometerToMovementParser.AnalyzeToMovement(
               e.X,
               e.Y,
               e.Z,
               _prevX,
               _prevY,
               _prevZ,
               _prevMovement
               );
            _prevX = e.X;
            _prevY = e.Y;
            _prevZ = e.Z;
            _prevMovement = move;
            if (_bigCycle.Sleepmeasures.Count < SleepBigCycles)
            {
                if (_cycle.Sleepmeasures.Count < SleepCycles)
                {
                  _cycle.Sleepmeasures.Add(new Sleepmeasure
                        {
                            MeasureDate = DateTime.Now,
                            Movement = move,
                            ActivityType = "1"
                        });
                }
                else
                {
                    var allTheRightMove =
                        AccelerometerToMovementParser.Analyze(_cycle.Sleepmeasures.Select(x => x.Movement).ToList());
                    var maxIndex = _bigCycle.Sleepmeasures.Count - 1;
                    var curr = allTheRightMove;
                    while (maxIndex > 0)
                    {
                        var prev = _bigCycle.Sleepmeasures[maxIndex];
                        if (prev.Movement < curr)
                            prev.Movement = curr - 1;
                        else
                            break;
                        maxIndex--;
                        curr = prev.Movement;
                    }

                    var r = new PostData
                    {
                        DataType = typeof(SleepData)
                    };
                                      r.SaveData(_cycle);

                    _bigCycle.Sleepmeasures.Add(
                        new Sleepmeasure { MeasureDate = DateTime.Now, Movement = allTheRightMove, ActivityType = "0"});
                    _cycle = new SleepData(_flag, App.FacebookId);
                }
            }
            else
            {
                _bigCycle.EndTime = DateTime.Now;
                var r = new PostData
                {
                    DataType = typeof(SleepData)
                };

                r.SaveData(_bigCycle);
                _bigCycle = new SleepData(_flag, App.FacebookId);
            }
        }