示例#1
0
 private void StoreResult(string zip, InteractionStatistics stats)
 {
     lock (Lock)
     {
         _results[zip] = stats;
     }
 }
 protected bool Equals(InteractionStatistics other)
 {
     return(DayFirst.Equals(other.DayFirst) && DayLast.Equals(other.DayLast) && NumDays == other.NumDays &&
            NumMonth == other.NumMonth && NumEventsTotal == other.NumEventsTotal &&
            EqualityUtils.Equals(NumEventsDetailed, other.NumEventsDetailed) && Education == other.Education &&
            Position == other.Position && NumCodeCompletion == other.NumCodeCompletion &&
            NumTestRuns == other.NumTestRuns && ActiveTime.Equals(other.ActiveTime));
 }
示例#3
0
        public InteractionStatistics CreateStatistics(IEnumerable <IIDEEvent> events)
        {
            var stats  = new InteractionStatistics();
            var days   = new HashSet <DateTimeOffset>();
            var months = new HashSet <DateTimeOffset>();

            var lastTriggeredAt = DateTimeOffset.MinValue;

            DateTimeOffset?curStart = null;
            DateTimeOffset?curEnd   = null;

            foreach (var t in AllEventTypes)
            {
                stats.NumEventsDetailed[t] = 0;
            }

            foreach (var e in events)
            {
                if (e.TriggeredAt.HasValue && e.TerminatedAt.HasValue)
                {
                    // make sure it is ordered!
                    Asserts.IsLessOrEqual(lastTriggeredAt, e.TriggeredAt.Value);
                    lastTriggeredAt = e.TriggeredAt.Value;

                    // if timeout
                    if (curStart.HasValue && curEnd.Value.AddSeconds(TimeOutInS) < e.TriggeredAt.Value)
                    {
                        stats.ActiveTime += curEnd.Value - curStart.Value;
                        curStart          = null;
                        curEnd            = null;
                    }

                    // start new interva, if required
                    if (curStart.HasValue)
                    {
                        curEnd = curEnd > e.TerminatedAt ? curEnd : e.TerminatedAt;
                    }
                    else
                    {
                        curStart = e.TriggeredAt;
                        curEnd   = e.TerminatedAt;
                    }
                }

                if (stats.NumEventsDetailed.ContainsKey(e.GetType()))
                {
                    stats.NumEventsDetailed[e.GetType()]++;
                }
                else
                {
                    stats.NumEventsDetailed[e.GetType()] = 1;
                }

                if (!e.TriggeredAt.HasValue)
                {
                    e.TriggeredAt = DateTimeOffset.MinValue;
                }

                var date = new DateTimeOffset(e.TriggeredAt.Value.Date, e.TriggeredAt.Value.Offset);

                days.Add(date);
                var firstDayOfMonth = date.AddDays(-(date.Day - 1));
                months.Add(firstDayOfMonth);

                if (stats.DayFirst == DateTimeOffset.MinValue || date < stats.DayFirst)
                {
                    stats.DayFirst = date;
                }

                if (stats.DayLast == DateTimeOffset.MinValue || date > stats.DayLast)
                {
                    stats.DayLast = date;
                }

                var upe = e as UserProfileEvent;
                if (upe != null)
                {
                    if (upe.Education != Educations.Unknown)
                    {
                        stats.Education = upe.Education;
                    }
                    if (upe.Position != Positions.Unknown)
                    {
                        stats.Position = upe.Position;
                    }
                }

                var cce = e as CompletionEvent;
                if (cce != null)
                {
                    stats.NumCodeCompletion++;
                }

                var tre = e as TestRunEvent;
                if (tre != null)
                {
                    stats.NumTestRuns++;
                }
            }

            if (curStart.HasValue)
            {
                stats.ActiveTime += curEnd.Value - curStart.Value;
            }

            stats.NumDays  = days.Count;
            stats.NumMonth = months.Count;
            return(stats);
        }