Beispiel #1
0
 def test_create_days_between__right_included(self):
     start = date(2010, 1, 20)
     end = date(2010, 1, 22)
     middle = start + timedelta(1)
     self.assert_(start < end)
     self.assertEquals([start, middle, end], create_days_between(start, end, include_start=True,  include_end=True))
     self.assertEquals([middle, end],        create_days_between(start, end, include_start=False, include_end=True))
Beispiel #2
0
 def test_create_days_between__one_day_mix_included(self):
     start = date(2010, 1, 20)
     end = date(2010, 1, 20)
     self.assert_(start <= end)
     self.assertEquals([start],
                       create_days_between(start,
                                           end,
                                           include_start=True,
                                           include_end=True))
     self.assertEquals([end],
                       create_days_between(start,
                                           end,
                                           include_start=True,
                                           include_end=True))
     self.assertEquals([start],
                       create_days_between(start,
                                           end,
                                           include_start=True,
                                           include_end=False))
     self.assertEquals([start],
                       create_days_between(start,
                                           end,
                                           include_start=False,
                                           include_end=True))
     self.assertEquals([],
                       create_days_between(start,
                                           end,
                                           include_start=False,
                                           include_end=False))
Beispiel #3
0
 def test_create_days_between__two_days_mixed_included(self):
     start = date(2010, 1, 20)
     end = date(2010, 1, 21)
     self.assert_(start < end)
     self.assertEquals([start,end], create_days_between(start, end, include_start=True,  include_end=True))
     self.assertEquals([start], create_days_between(start, end, include_start=True,  include_end=False))
     self.assertEquals([end], create_days_between(start, end, include_start=False, include_end=True))
     self.assertEquals([],      create_days_between(start, end, include_start=False, include_end=False))
Beispiel #4
0
 def test_create_days_between__empty_range(self):
     start = date(2010, 1, 20)
     end = date(2010, 1, 19)
     self.assert_(start > end)
     self.assertEquals([], create_days_between(start, end, include_start=True,  include_end=True))
     self.assertEquals([], create_days_between(start, end, include_start=True,  include_end=False))
     self.assertEquals([], create_days_between(start, end, include_start=False, include_end=False))
     self.assertEquals([], create_days_between(start, end, include_start=False, include_end=True))
Beispiel #5
0
 def test_create_days_between__right_included(self):
     start = date(2010, 1, 20)
     end = date(2010, 1, 22)
     middle = start + timedelta(1)
     self.assert_(start < end)
     self.assertEquals([start, middle, end],
                       create_days_between(start,
                                           end,
                                           include_start=True,
                                           include_end=True))
     self.assertEquals([middle, end],
                       create_days_between(start,
                                           end,
                                           include_start=False,
                                           include_end=True))
Beispiel #6
0
 def test_create_days_between__empty_range(self):
     start = date(2010, 1, 20)
     end = date(2010, 1, 19)
     self.assert_(start > end)
     self.assertEquals([],
                       create_days_between(start,
                                           end,
                                           include_start=True,
                                           include_end=True))
     self.assertEquals([],
                       create_days_between(start,
                                           end,
                                           include_start=True,
                                           include_end=False))
     self.assertEquals([],
                       create_days_between(start,
                                           end,
                                           include_start=False,
                                           include_end=False))
     self.assertEquals([],
                       create_days_between(start,
                                           end,
                                           include_start=False,
                                           include_end=True))
Beispiel #7
0
    def get_html_of_scale(self, groups):
        """
        Returns html for scale (podziałka).
        
        Args:
            groups -- groups of segments (list of list of Segment instances).
            
        Raises:
            If group is empty, then raises ValueError
        """
        if not groups:
            raise ValueError('Given groups is empty: %s' % (repr(groups)))

        max_days_to_display_days = self.config.get_int(
            'tb_max_days_to_display_days')
        max_days_to_display_weeks = self.config.get_int(
            'tb_max_days_to_display_weeks')
        max_days_to_display_days = max(
            1, max_days_to_display_days)  # at least one day
        max_days_to_display_weeks = max(
            1, max_days_to_display_weeks)  # at least one day
        if max_days_to_display_days >= max_days_to_display_weeks:  # _days should be < _weeks
            max_days_to_display_days = max_days_to_display_weeks - 1

        width = self.get_width_of_group(groups[0])
        display_days = width <= max_days_to_display_days
        display_weeks = (
            not display_days) and width <= max_days_to_display_weeks
        display_months = (not display_days) and (not display_weeks)

        first_day, last_day = groups[0][0].start, groups[0][-1].end
        days_in_range = create_days_between(first_day,
                                            last_day,
                                            include_start=True,
                                            include_end=True)
        html = ''
        if display_days:
            html = u'<div class="scaleWrapper">'
            for day in days_in_range:
                title = unicode(day)
                html += u'<div class="scale_part" style="width: %.3f%%" title="%s">' % (
                    100.0 / width, title)
                html += title
                html += u'</div>'
            html += u'</div>'
        elif display_weeks:
            week_to_first_day_map = {}
            for day in days_in_range:
                wfd = week_for_day(day)
                if wfd not in week_to_first_day_map:
                    week_to_first_day_map[wfd] = day

            weeks_in_range = [week_for_day(day) for day in days_in_range]
            grouped_weeks = [(key[0], key[1], len(list(group)))
                             for key, group in groupby(weeks_in_range)
                             ]  # [year, week_nr, len]
            display_year = len(set([y for y, n, c in grouped_weeks])) > 1
            html = u'<div class="scaleWrapper">'
            for year, week_nr, week_len in grouped_weeks:
                first_day = week_to_first_day_map[(year, week_nr)]
                period_name = u'%s, %d (%dw)' % (first_day.strftime('%B'),
                                                 first_day.day, week_nr)
                hover_title = period_name
                if display_year:
                    title = u'%d week of %d' % (week_nr, year)
                else:
                    title = u'%d week' % (week_nr, )
                html += u'<div class="scale_part" style="width: %.3f%%" title="%s">' % (
                    100.0 * week_len / width, hover_title)
                html += title
                html += u'</div>'
            html += u'</div>'
        elif display_months:
            months_in_range = [month_for_day(day) for day in days_in_range]
            grouped_months = [(key[0], key[1], len(list(group)))
                              for key, group in groupby(months_in_range)
                              ]  # [year, month_nr, len]
            display_year = len(set([y for y, m, c in grouped_months])) > 1
            html = u'<div class="scaleWrapper">'
            for year, month_nr, week_len in grouped_months:
                title = u'%d-%d' % (year, month_nr)
                html += u'<div class="scale_part" style="width: %.3f%%" title="%s">' % (
                    100.0 * week_len / width, title)
                html += title
                html += u'</div>'
            html += u'</div>'
        else:
            assert False, 'Unknown type of scale. Are values in configuration correct?'


#        # count gcd
#        the_gcd = self.gcd_for_group(groups[0])
#        for group in groups:
#            the_gcd = gcd(the_gcd, self.gcd_for_group(group))

        return html
Beispiel #8
0
    def get_html_of_scale(self, groups):
        """
        Returns html for scale (podziałka).
        
        Args:
            groups -- groups of segments (list of list of Segment instances).
            
        Raises:
            If group is empty, then raises ValueError
        """
        if not groups:
            raise ValueError('Given groups is empty: %s' % (repr(groups)))
        
        max_days_to_display_days = self.config.get_int('tb_max_days_to_display_days')
        max_days_to_display_weeks = self.config.get_int('tb_max_days_to_display_weeks')
        max_days_to_display_days  = max(1, max_days_to_display_days)    # at least one day
        max_days_to_display_weeks = max(1, max_days_to_display_weeks)   # at least one day 
        if max_days_to_display_days >= max_days_to_display_weeks:        # _days should be < _weeks
            max_days_to_display_days = max_days_to_display_weeks - 1
        
        width = self.get_width_of_group(groups[0])
        display_days = width <= max_days_to_display_days
        display_weeks = (not display_days) and width <= max_days_to_display_weeks
        display_months = (not display_days) and (not display_weeks)
        
        first_day, last_day = groups[0][0].start, groups[0][-1].end
        days_in_range = create_days_between(first_day, last_day, include_start=True, include_end=True)
        html = ''
        if display_days:
            html = u'<div class="scaleWrapper">'
            for day in days_in_range:
                title = unicode(day)
                html += u'<div class="scale_part" style="width: %.3f%%" title="%s">' % (100.0 / width, title)
                html += title
                html += u'</div>'
            html += u'</div>'            
        elif display_weeks:
            week_to_first_day_map = {}
            for day in days_in_range:
                wfd = week_for_day(day) 
                if wfd not in week_to_first_day_map:
                    week_to_first_day_map[wfd] = day
            
            weeks_in_range = [week_for_day(day) for day in days_in_range]
            grouped_weeks = [(key[0],key[1],len(list(group))) for key,group in groupby(weeks_in_range)]  # [year, week_nr, len]
            display_year = len(set([y for y,n,c in grouped_weeks])) > 1
            html = u'<div class="scaleWrapper">'
            for year,week_nr,week_len in grouped_weeks:
                first_day = week_to_first_day_map[(year,week_nr)]
                period_name = u'%s, %d (%dw)' % (first_day.strftime('%B'), first_day.day, week_nr)
                hover_title = period_name
                if display_year:
                    title = u'%d week of %d' % (week_nr, year)
                else:
                    title = u'%d week' % (week_nr,)
                html += u'<div class="scale_part" style="width: %.3f%%" title="%s">' % (100.0 * week_len / width, hover_title)
                html += title
                html += u'</div>'
            html += u'</div>'
        elif display_months:
            months_in_range = [month_for_day(day) for day in days_in_range]
            grouped_months = [(key[0],key[1],len(list(group))) for key,group in groupby(months_in_range)]  # [year, month_nr, len]
            display_year = len(set([y for y,m,c in grouped_months])) > 1
            html = u'<div class="scaleWrapper">'
            for year,month_nr,week_len in grouped_months:
                title = u'%d-%d' % (year, month_nr)
                html += u'<div class="scale_part" style="width: %.3f%%" title="%s">' % (100.0 * week_len / width, title)
                html += title
                html += u'</div>'
            html += u'</div>'
        else:
            assert False, 'Unknown type of scale. Are values in configuration correct?'

#        # count gcd
#        the_gcd = self.gcd_for_group(groups[0])
#        for group in groups:
#            the_gcd = gcd(the_gcd, self.gcd_for_group(group))
        
        return html