< Summary - ReFlex - Library

Information
Class: ReFlex.Core.Common.Components.InteractionHistory
Assembly: ReFlex.Core.Common
File(s): D:\a\reflex\reflex\library\src\Core\Common\Components\InteractionHistory.cs
Line coverage
100%
Covered lines: 25
Uncovered lines: 0
Coverable lines: 25
Total lines: 62
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_TouchId()100%11100%
get_Items()100%11100%
.ctor(...)100%11100%
RetrieveHistoryFromInteractionFrames(...)100%44100%

File(s)

D:\a\reflex\reflex\library\src\Core\Common\Components\InteractionHistory.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3
 4namespace ReFlex.Core.Common.Components
 5{
 6    /// <summary>
 7    /// Data class containing a List of <see cref="Interaction"/> associated with a specific <see cref="TouchId"/>
 8    /// </summary>
 9    public class InteractionHistory
 10    {
 11        /// <summary>
 12        /// The TouchId associated with the Interactions of past <see cref="InteractionFrame"/>s
 13        /// </summary>
 1314        public int TouchId { get; }
 15
 16        /// <summary>
 17        /// A List of past Interactions associated with the provided <see cref="TouchId"/>
 18        /// Contains one Element for each frame in which a touch with the associated <see cref="TouchId"/> was registere
 19        /// </summary>
 4220        public List<InteractionHistoryElement> Items { get; }
 21
 22        /// <summary>
 23        /// Initializes the data class.
 24        /// </summary>
 25        /// <param name="touchId">The TouchId associated with the Interactions of past <see cref="InteractionFrame"/>s <
 26        /// <param name="items">List of past Interactions associated with the provided touchId</param>
 727        public InteractionHistory(int touchId, List<InteractionHistoryElement> items)
 728        {
 729            Items = items;
 730            TouchId = touchId;
 731        }
 32
 33        /// <summary>
 34        /// Converts Interaction Data mapped by <see cref="InteractionFrame"/>(and associated <see cref="InteractionFram
 35        /// </summary>
 36        /// <param name="frames">List of <see cref="InteractionFrame"/> with (calibrated) interaction data</param>
 37        /// <returns>History for each identified touch id.</returns>
 38        public static IOrderedEnumerable<InteractionHistory> RetrieveHistoryFromInteractionFrames(
 39            IEnumerable<InteractionFrame> frames)
 140        {
 141            var interactionFrames = frames.ToList();
 142            var ids = interactionFrames
 2043                .SelectMany(frame => frame.Interactions.Select(interaction => interaction.TouchId)).Distinct().ToList();
 44
 145            var result = new List<InteractionHistory>();
 46
 147            ids.ForEach(id =>
 648            {
 4249                var elements = interactionFrames.OrderByDescending(frame => frame.FrameId)
 3650                    .Select(frame => new InteractionHistoryElement(frame.FrameId,
 10551                        frame.Interactions.FirstOrDefault(interaction => Equals(interaction.TouchId, id))))
 4252                    .Where(elem => elem.Interaction != null).ToList();
 653                if (elements.Count > 0)
 654                {
 655                    result.Add(new InteractionHistory(id, elements));
 656                }
 757            });
 58
 759            return result.OrderBy(history => history.TouchId);
 160        }
 61    }
 62}