Example #1
0
 public Maybe <FocusData> Combine(FocusData data) =>
 CanCombine(data) ?
 new FocusData(
     new DateTime(Math.Min(data.StartTime.Ticks, StartTime.Ticks)),
     new DateTime(Math.Max(data.EndTime.Ticks, EndTime.Ticks)),
     ItemId)
         : null;
Example #2
0
 public void StoreData(FocusData focusData)
 {
     _storedData = _storedData.Concat(new List <FocusData>()
     {
         focusData
     });
     TrySendData();
 }
Example #3
0
        public static IEnumerable <FocusData> AddOrCombine(
            this IEnumerable <FocusData> list, FocusData focusData)
        {
            var combineable = list.FirstOrDefault(x => x.CanCombine(focusData));

            return(combineable != null
                ? list.Except(new List <FocusData>() { combineable })
                   .Concat(new List <FocusData>()
            {
                combineable.Combine(focusData).Value
            })
                : list.Concat(new List <FocusData>()
            {
                focusData
            }));
        }
Example #4
0
        public void ProcessData(int itemId)
        {
            var currentTime = _timeService.GetTime();

            if (_previousTime == default)
            {
                _previousTime = currentTime;
                _previousId   = itemId;
                return;
            }

            if (itemId == _previousId &&
                (currentTime - _previousTime) < TimeSpan.FromSeconds(5))
            {
                return;
            }

            var focusData = new FocusData(_previousTime, currentTime, _previousId);

            _uploadService.StoreData(focusData);

            _previousTime = currentTime;
            _previousId   = itemId;
        }
Example #5
0
 public bool CanCombine(FocusData data) =>
 data.ItemId == ItemId &&
 (data.EndTime == StartTime || data.StartTime == EndTime);