Exemplo n.º 1
0
    def changes_in_year(self, year, choice_tab=None):
        """
        Gets changes per "week" in an entire year.
        """
        if isleap(year):
            mdays[2] = 29
        else:
            mdays[2] = 28

        # get last amount of events in past year, or, better:
        # amount of events that occuried in (year - 1) at December, from
        # numberOfDaysInDecember / 2 + (numberOfDaysInDecember / 4) till
        # final of month.

        if year == self.calendar.year_range[0]:
            start_value = 0

        else:
            half = mdays[12] / 2
            quarter = half / 2
            start = datetime.datetime(year - 1, 12, quarter + half)
            end = datetime.datetime(year, 1, 1)

            start_value = self.timerange_changes_count_generic(start,end,choice_tab)

        # get events for year
        year_events = { }

        for m in range(12):
            half = (mdays[m + 1] / 2) + 1
            quarter = (half / 2)

            # months with 31 or 30 days:
            # half = (31/2) + 1 = 16
            # quarter = 8
            # will grab 1 -> 8, 8 -> 16, 16 -> 24, 24 -> end month
            # month with 28 or 29 days:
            # half = (29/2) + 1 = 15
            # quarter = 7
            # will grab 1 -> 7, 7 -> 15, 15 -> 22, 22 -> end month

            days = (1, quarter, half, half + quarter, 1)

            mcount = [ ]

            for i in range(len(days) - 1):
                start = datetime.datetime(year, m + 1, days[i])

                if i == len(days) - 2:
                    dyear = year
                    dmonth = m + 2
                    if m == 11:
                        dyear += 1
                        dmonth = 1

                    end = datetime.datetime(dyear, dmonth, days[i + 1])
                else:
                    end = datetime.datetime(year, m + 1, days[i + 1])

                count = self.timerange_changes_count_generic(start,end,choice_tab)

                mcount.append([count, ])

            year_events[m] = mcount

        
        #g_logger.debug("Year Events: %d, %s"%(start_value,year_events))       
        return self.standard_sum_filter(), (start_value, ), year_events
    def changes_in_year(self, year, choice_tab=None):
        """
        Gets changes per "week" in an entire year.
        """
        if isleap(year):
            mdays[2] = 29
        else:
            mdays[2] = 28

        # get last amount of events in past year, or, better:
        # amount of events that occuried in (year - 1) at December, from
        # numberOfDaysInDecember / 2 + (numberOfDaysInDecember / 4) till
        # final of month.

        if year == self.calendar.year_range[0]:
            start_value = 0

        else:
            half = mdays[12] / 2
            quarter = half / 2
            start = datetime.datetime(year - 1, 12, quarter + half)
            end = datetime.datetime(year, 1, 1)

            start_value = self.timerange_changes_count_generic(
                start, end, choice_tab)

        # get events for year
        year_events = {}

        for m in range(12):
            half = (mdays[m + 1] / 2) + 1
            quarter = (half / 2)

            # months with 31 or 30 days:
            # half = (31/2) + 1 = 16
            # quarter = 8
            # will grab 1 -> 8, 8 -> 16, 16 -> 24, 24 -> end month
            # month with 28 or 29 days:
            # half = (29/2) + 1 = 15
            # quarter = 7
            # will grab 1 -> 7, 7 -> 15, 15 -> 22, 22 -> end month

            days = (1, quarter, half, half + quarter, 1)

            mcount = []

            for i in range(len(days) - 1):
                start = datetime.datetime(year, m + 1, days[i])

                if i == len(days) - 2:
                    dyear = year
                    dmonth = m + 2
                    if m == 11:
                        dyear += 1
                        dmonth = 1

                    end = datetime.datetime(dyear, dmonth, days[i + 1])
                else:
                    end = datetime.datetime(year, m + 1, days[i + 1])

                count = self.timerange_changes_count_generic(
                    start, end, choice_tab)

                mcount.append([
                    count,
                ])

            year_events[m] = mcount

        #g_logger.debug("Year Events: %d, %s"%(start_value,year_events))
        return self.standard_sum_filter(), (start_value, ), year_events
Exemplo n.º 3
0
    def changes_in_month(self, year, month, choice_tab=None):
        """
        Get changes in a month.
        """
        month_events = { }

        if isleap(year) and month == 2: # month range from 1 to 12
            mdays[2] = 29
        else:
            mdays[2] = 28

        # get last amount of events in past month, or, better:
        # amount of events that occuried in (month - 1) at last day, from
        # 12 PM to 23:59 PM
        self.calendar.dryrun = True
        self.calendar.dec_date(1) # 1 indicates it is a month decrement
        prev_date = self.calendar.temp # what changes were needed to decrement
        self.calendar.dryrun = False

        prev_year = year
        prev_month = month

        for key, value in prev_date.items():
            if key == "year":
                prev_year = value
            elif key == "month":
                prev_month = value

        month_range = self.calendar.get_monthrange(prev_year, prev_month)[1]
        start = datetime.datetime(prev_year, prev_month, month_range, 12)
        end = datetime.datetime(year, month, 1)

        start_value = self.timerange_changes_count_generic(start,end,choice_tab)

        for day in range(mdays[month]):
            day_count = [ ]

            # for each day, grab data for 0 AM .. 11:59 AM, 12 PM .. 23:59 PM
            start = datetime.datetime(year, month, day + 1)
            end = datetime.datetime(year, month, day + 1, 12)

            count1 = self.timerange_changes_count_generic(start,end,choice_tab)

            start = datetime.datetime(year, month, day + 1, 12)

            dyear = year
            dmonth = month
            dday = day

            if day == mdays[month] - 1:
                self.calendar.dryrun = True
                self.calendar.inc_date(1)
                next_date = self.calendar.temp
                self.calendar.dryrun = False

                dday = 1
                for key, value in next_date.items():
                    if key == "year":
                        dyear = value
                    elif key == "month":
                        dmonth = value

            else:
                dday += 2

            end = datetime.datetime(dyear, dmonth, dday)

            count2 = self.timerange_changes_count_generic(start,end,choice_tab)

            day_count.append([count1, ])
            day_count.append([count2, ])
            month_events[day] = day_count

        #g_logger.debug("Month Events: %d, %s"%(start_value,month_events)) 
        return self.standard_sum_filter(), (start_value, ), month_events
    def changes_in_month(self, year, month, choice_tab=None):
        """
        Get changes in a month.
        """
        month_events = {}

        if isleap(year) and month == 2:  # month range from 1 to 12
            mdays[2] = 29
        else:
            mdays[2] = 28

        # get last amount of events in past month, or, better:
        # amount of events that occuried in (month - 1) at last day, from
        # 12 PM to 23:59 PM
        self.calendar.dryrun = True
        self.calendar.dec_date(1)  # 1 indicates it is a month decrement
        prev_date = self.calendar.temp  # what changes were needed to decrement
        self.calendar.dryrun = False

        prev_year = year
        prev_month = month

        for key, value in prev_date.items():
            if key == "year":
                prev_year = value
            elif key == "month":
                prev_month = value

        month_range = self.calendar.get_monthrange(prev_year, prev_month)[1]
        start = datetime.datetime(prev_year, prev_month, month_range, 12)
        end = datetime.datetime(year, month, 1)

        start_value = self.timerange_changes_count_generic(
            start, end, choice_tab)

        for day in range(mdays[month]):
            day_count = []

            # for each day, grab data for 0 AM .. 11:59 AM, 12 PM .. 23:59 PM
            start = datetime.datetime(year, month, day + 1)
            end = datetime.datetime(year, month, day + 1, 12)

            count1 = self.timerange_changes_count_generic(
                start, end, choice_tab)

            start = datetime.datetime(year, month, day + 1, 12)

            dyear = year
            dmonth = month
            dday = day

            if day == mdays[month] - 1:
                self.calendar.dryrun = True
                self.calendar.inc_date(1)
                next_date = self.calendar.temp
                self.calendar.dryrun = False

                dday = 1
                for key, value in next_date.items():
                    if key == "year":
                        dyear = value
                    elif key == "month":
                        dmonth = value

            else:
                dday += 2

            end = datetime.datetime(dyear, dmonth, dday)

            count2 = self.timerange_changes_count_generic(
                start, end, choice_tab)

            day_count.append([
                count1,
            ])
            day_count.append([
                count2,
            ])
            month_events[day] = day_count

        #g_logger.debug("Month Events: %d, %s"%(start_value,month_events))
        return self.standard_sum_filter(), (start_value, ), month_events