Exemplo n.º 1
0
        /// <summary>
        ///     Explains a list of elements
        /// </summary>
        /// <param name="elements"></param>
        /// <param name="explainSubElements"></param>
        /// <param name="separator"></param>
        /// <param name="explainElement">The action used to explain a single element</param>
        public void ExplainList <T>(IEnumerable <T> elements, bool explainSubElements, string separator,
                                    ExplainElement <T> explainElement)
        {
            bool first = true;

            foreach (T element in elements)
            {
                if (!first)
                {
                    Write(separator);
                }
                first = false;
                explainElement(element);
            }
        }
    private ExplainElement GetExplainDiff(ExplainElement curr, ExplainElement prev)
    {
        // Ignore value, only get diff is points have changed
        if (curr.points == prev.points)
        {
            return(null);
        }

        var diff = new ExplainElement()
        {
            identifier = curr.identifier
        };

        diff.points = curr.points - prev.points;
        diff.value  = curr.value - prev.value;
        return(diff);
    }
    private TimelineLiveElement Compare(LiveElementBase prev, LiveElementBase curr)
    {
        var diff = new TimelineLiveElement()
        {
            id = curr.id
        };

        for (var i = 0; i < curr.explain.Count; i++)
        {
            var allExplainIdentifiers = new HashSet <string>(curr.explain[i].stats.Select(s => s.identifier).ToHashSet());
            if (prev != null && prev.explain != null && prev.explain.Count > i)
            {
                foreach (var stat in prev.explain[i].stats)
                {
                    allExplainIdentifiers.Add(stat.identifier);
                }
            }

            var currFixtureExplain = curr.explain[i];
            var prevFixtureExplain = prev != null && prev.explain != null && prev.explain.Count > i ? prev.explain[i] : null;
            var diffExplain        = new Explain()
            {
                fixture = currFixtureExplain.fixture,
                stats   = new List <ExplainElement>()
            };
            diff.explain.Add(diffExplain);

            foreach (var explainIdentifier in allExplainIdentifiers)
            {
                var currStat = currFixtureExplain.stats.FirstOrDefault(e => e.identifier.Equals(explainIdentifier));
                var prevStat = prevFixtureExplain != null?prevFixtureExplain.stats.FirstOrDefault(s => s.identifier.Equals(explainIdentifier)) : null;

                if (prevStat == null)
                {
                    prevStat = new ExplainElement()
                    {
                        identifier = explainIdentifier
                    };
                }
                if (currStat == null)
                {
                    currStat = new ExplainElement()
                    {
                        identifier = explainIdentifier
                    };
                }
                var statDiff = GetExplainDiff(currStat, prevStat);
                if (statDiff != null)
                {
                    diffExplain.stats.Add(statDiff);
                }
            }
        }

        var saveDiff = diff.explain.Any(ex => ex.stats.Count > 0);

        if (saveDiff)
        {
            diff.CalcScore();
            return(diff);
        }

        return(null);
    }
Exemplo n.º 4
0
 public ExplainElement(ExplainElement other)
 {
     identifier = other.identifier;
     points     = other.points;
     value      = other.value;
 }