private TimelineLiveElement getBaseDiff(LiveElementBase curr)
    {
        var diff = new TimelineLiveElement()
        {
            id = curr.id
        };

        var diffExplains = new List <Explain>();

        foreach (var explain in curr.explain)
        {
            var diffExplain = new Explain()
            {
                fixture = explain.fixture
            };
            diff.explain.Add(diffExplain);
            var diffStats = new List <ExplainElement>();
            foreach (var stat in explain.stats)
            {
                if (stat.points != 0 || stat.value != 0)
                {
                    diffStats.Add(stat);
                }
            }
            if (diffStats.Count > 0)
            {
                diffExplain.stats = diffStats;
            }
        }
        diff.CalcScore();
        var anyStats = diff.explain.Any(ex => ex.stats.Count > 0);

        return(anyStats ? diff : null);
    }
 public LiveElementBase(LiveElementBase other)
 {
     id      = other.id;
     explain = new List <Explain>();
     foreach (var otherExplain in other.explain)
     {
         explain.Add(new Explain(otherExplain));
     }
 }
    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);
    }
Beispiel #4
0
 public TimelineLiveElement(LiveElementBase other)
     : base(other)
 {
     CalcScore();
 }