void UpdateRelativeAcceleration(float currentFrameDistance)
        {
            var currentDistance = new DistanceHistory();

            currentDistance.time     = Time.time;
            currentDistance.distance = currentFrameDistance;

            histories.Push(currentDistance);


            var beforeFrameTime     = 0f;
            var beforeFrameDistance = 0f;

            var accelarations = new List <float>(referenceFrameLimit);

            foreach (var history in  histories)
            {
                if (beforeFrameTime != 0f)
                {
                    var timeDistance = history.time - beforeFrameTime;
                    // 空間距離。+の値なら遠ざかっている
                    var spaceDistance = history.distance - beforeFrameDistance;
                    // フレームごとの加速度
                    var accelaration = spaceDistance / timeDistance;

                    accelarations.Add(accelaration);
                }
                beforeFrameTime     = history.time;
                beforeFrameDistance = history.distance;
            }

            this.beforeFrameAccelaration = this.currentFrameAccelaration;
            if (accelarations.Count() >= 2)
            {
                this.currentFrameAccelaration = accelarations.Aggregate <float>((total, item) => total + item) / referenceFrameLimit;
            }

            float accelarationDiff = this.currentFrameAccelaration - this.beforeFrameAccelaration;

            int currentPistonDirection = accelarationDiff < 0 ? -1 : 1;

            // 加速度が別方向になった場合のみ
            if (currentPistonDirection != this.beforePistonDirection)
            {
                this.directionChangeInterval = this.beforePistonDirectionChanged == 0 ? 0 : Time.time - this.beforePistonDirectionChanged;

                this.beforePistonDirectionChanged = Time.time;
                this.beforePistonDirection        = currentPistonDirection;
            }
        }
Exemple #2
0
        public async Task PutAsync(Int32 id, DistanceHistory _distanceHistory)
        {
            var entity = _unitOfWork.GetRepoInstance <DistanceHistory>().GetById(id);

            if (entity == null)
            {
                return;
            }

            entity.date     = _distanceHistory.date;
            entity.distance = _distanceHistory.distance;
            entity.Event    = _distanceHistory.Event;
            entity.order    = _distanceHistory.order;

            _unitOfWork.GetRepoInstance <DistanceHistory>().Update(entity);
            await _unitOfWork.saveAsync();
        }
Exemple #3
0
        public void Delete(int distanceHistoryID)
        {
            DistanceHistory distanceHistory = _context.DistancesHistoryContext.Find(distanceHistoryID);

            _context.DistancesHistoryContext.Remove(distanceHistory);
        }
Exemple #4
0
 public void Update(DistanceHistory distanceHistory)
 {
     _context.Entry(distanceHistory).State = EntityState.Modified;
 }
Exemple #5
0
 public void Insert(DistanceHistory distanceHistory)
 {
     _context.DistancesHistoryContext.Add(distanceHistory);
 }
Exemple #6
0
 public async Task PostAsync(DistanceHistory _distanceHistory)
 {
     _unitOfWork.GetRepoInstance <DistanceHistory>().Insert(_distanceHistory);
     await _unitOfWork.saveAsync();
 }