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;
public void StoreData(FocusData focusData) { _storedData = _storedData.Concat(new List <FocusData>() { focusData }); TrySendData(); }
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 })); }
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; }
public bool CanCombine(FocusData data) => data.ItemId == ItemId && (data.EndTime == StartTime || data.StartTime == EndTime);