/// <summary>
        /// Make groups go without gaps.
        /// </summary>
        private static void UnsparseGroups(IList <PeriodGroup> groups, GroupingPeriod groupBy)
        {
            // Just exit if empty collection
            if (groups.Count == 0)
            {
                return;
            }

            int prevInterval = groups.Count > 0 ? groups[0].Interval : -1;

            for (int i = 1; i < groups.Count; i++)
            {
                int interval = prevInterval + 1;
                // If gap is found
                if (groups[i].Interval > interval)
                {
                    // Insert new group
                    DateTime intervalStart, intervalEnd;
                    GetIntervalDates(groupBy, interval, out intervalStart, out intervalEnd);
                    PeriodGroup group = new PeriodGroup(interval, intervalStart, intervalEnd);
                    groups.Insert(i, group);
                }
                prevInterval = interval;
            }
        }
        /// <summary>
        /// Returns group for specified revision.
        /// </summary>
        /// <remarks>
        /// Each group has index of perid it covers.
        /// Duration of period is specified as enumerated value.
        /// This is because if specified in days it may vary
        /// because number of days isn't ecual for some periods, like months
        /// years and quaters.
        ///
        /// Reference point is Jan-1, 1990.
        /// </remarks>
        private static PeriodGroup GetGroup(List <PeriodGroup> groups, GroupingPeriod groupBy, Revision revision)
        {
            DateTime date    = revision.Date;
            DateTime refDate = new DateTime(1990, 1, 1);

            TimeSpan offset = revision.Date - refDate;

            int index = -1;

            // Day
            if (groupBy == GroupingPeriod.Day)
            {
                // For days it's just number of days
                // from reference point till revision date
                index = offset.Days;
            }
            else if (groupBy == GroupingPeriod.Week) // Week
            {
                // For weeks it's quotient of division days by 7
                index = offset.Days / 7;
            }
            else if (groupBy == GroupingPeriod.Month) // Month
            {
                // 01.1990 - 0  = (1990 - 1990)*12 + (01 - 01) = 0*12 + 0
                // 12.1990 - 11 = (1990 - 1990)*12 + (12 - 01) = 0*12 + 11
                // 01.1991 - 12 = (1991 - 1990)*12 + (01 - 01) = 1*12 + 0
                // 06.1991 - 17 = (1991 - 1990)*12 + (06 - 01) = 1*12 + 5
                // 06.1992 - 29 = (1992 - 1990)*12 + (06 - 01) = 2*12 + 5

                // Number of full years plus
                index = (date.Year - refDate.Year) * 12 + (date.Month - refDate.Month);
            }
            else if (groupBy == GroupingPeriod.Quater) // Quater
            {
                // Same as months but divided by 3
                index = ((date.Year - refDate.Year) * 12 + (date.Month - refDate.Month)) / 3;
            }
            else if (groupBy == GroupingPeriod.Year) // Year
            {
                // Offset of year
                index = date.Year - refDate.Year;
            }

            // Check that it's been caluclated
            Debug.Assert(index > 0);

            PeriodGroup group = groups.Find(item => item.Interval == index);

            if (group == null)
            {
                DateTime intervalStart, intervalEnd;
                // Get dates
                GetIntervalDates(groupBy, index, out intervalStart, out intervalEnd);
                // Create new group
                group = new PeriodGroup(index, intervalStart, intervalEnd);
                groups.Add(group);
            }

            return(group);
        }
        /// <summary>
        /// Creates balance report.
        /// </summary>
        public List <PeriodGroup> CreateReport(GroupingPeriod groupBy, bool ignorePostponed)
        {
            // Input data:
            // +) revisions (filter for bugs)
            // +) interval duration (by day, by week, by month, by quater, by year)
            // +) additional options (e.g. how to treat Postponed)


            // Resulting groups
            List <PeriodGroup> groups = new List <PeriodGroup>();

            // Get bugs for specified filter
            Bug[] bugs = m_provider.GetBugs();

            // Process all bugs
            foreach (Bug bug in bugs)
            {
                // Get all revisions for selected bugs (they should be sorted)
                Revision[] revisions = m_provider.GetRevisions(bug.Number);

                Revision prevRevision = null;
                // Go through revisions of one bug
                foreach (Revision revision in revisions)
                {
                    // Compare current and previous revision
                    StatusTransition trans = GetStatusTransition(prevRevision, revision);

                    // When combination of states corresponds to state transition
                    if (trans != StatusTransition.None)
                    {
                        // Get record for period correspondent to the date of current revision
                        PeriodGroup group = GetGroup(groups, groupBy, revision);

                        // Update correspondent values
                        group.Added       += trans == StatusTransition.Added ? 1 : 0;
                        group.Removed     += trans == StatusTransition.Removed ? 1 : 0;
                        group.Postponed   += trans == StatusTransition.Postponed ? 1 : 0;
                        group.Reactivated += trans == StatusTransition.Reactivated ? 1 : 0;
                    }

                    // Remember current revision
                    prevRevision = revision;
                }
            }

            // Sort groups by index because they go in arbitrary order
            groups.Sort((x, y) => x.Interval - y.Interval);

            // Make groups go without gaps
            UnsparseGroups(groups, groupBy);

            // Return report
            return(groups);
        }
Beispiel #4
0
 public bool Equals(PeriodGroup other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(other.Interval == Interval);
 }
        /// <summary>
        /// Returns group for specified revision.
        /// </summary>
        /// <remarks>
        /// Each group has index of perid it covers.
        /// Duration of period is specified as enumerated value.
        /// This is because if specified in days it may vary
        /// because number of days isn't ecual for some periods, like months
        /// years and quaters.
        /// 
        /// Reference point is Jan-1, 1990.
        /// </remarks>
        private static PeriodGroup GetGroup(GroupingPeriod groupBy, Revision revision)
        {
            DateTime date = revision.Date;
              DateTime refDate = new DateTime(1990, 1, 1);

              TimeSpan offset = revision.Date - refDate;

              int index = -1;
              // Day
              if( groupBy == GroupingPeriod.Day )
              {
            // For days it's just number of days
            // from reference point till revision date
            index = offset.Days;
              }
              else if( groupBy == GroupingPeriod.Week ) // Week
              {
            // For weeks it's quotient of division days by 7
            index = offset.Days/7;
              }
              else if( groupBy == GroupingPeriod.Month ) // Month
              {
            // 01.1990 - 0  = (1990 - 1990)*12 + (01 - 01) = 0*12 + 0
            // 12.1990 - 11 = (1990 - 1990)*12 + (12 - 01) = 0*12 + 11
            // 01.1991 - 12 = (1991 - 1990)*12 + (01 - 01) = 1*12 + 0
            // 06.1991 - 17 = (1991 - 1990)*12 + (06 - 01) = 1*12 + 5
            // 06.1992 - 29 = (1992 - 1990)*12 + (06 - 01) = 2*12 + 5

            // Number of full years plus
            index = (date.Year - refDate.Year)*12 + (date.Month - refDate.Month);
              }
              else if( groupBy == GroupingPeriod.Quater ) // Quater
              {
            // Same as months but divided by 3
            index = ((date.Year - refDate.Year)*12 + (date.Month - refDate.Month))/3;
              }
              else if( groupBy == GroupingPeriod.Year ) // Year
              {
            // Offset of year
            index = date.Year - refDate.Year;
              }

              // Check that it's been calculated
              Debug.Assert( index > 0 );

              DateTime intervalStart, intervalEnd;
              // Get dates
              GetIntervalDates(groupBy, index, out intervalStart, out intervalEnd);
              // Create new group
              PeriodGroup group = new PeriodGroup(index, intervalStart, intervalEnd);

              return group;
        }
 public bool Equals(PeriodGroup other)
 {
     if( ReferenceEquals(null, other) )
       {
     return false;
       }
       if( ReferenceEquals(this, other) )
       {
     return true;
       }
       return other.Interval == Interval;
 }