コード例 #1
0
ファイル: survival.py プロジェクト: lynnmatrix/statistic
def get_index(start_date, group_window, time):
    index = 0
    if 1 == group_window:
        delta = time - start_date
        index = delta.days
    if 2 == group_window:
        start_date = week_start(start_date)
        time = week_start(time)

        delta = time - start_date
        index = delta.days / 7
    elif 3 == group_window:
        start_date = month_start(start_date)
        time = month_start(time)

        index = (time.year - start_date.year) * 12 + (time.month - start_date.month)

    return index, time
コード例 #2
0
ファイル: survival.py プロジェクト: lynnmatrix/statistic
def window_range(anchor_date, group_window):
    if 1 == group_window:
        start_time = day_start(anchor_date)
    elif 2 == group_window:
        start_time = week_start(anchor_date)
        end_time = start_time + timedelta(days=7)
    elif 3 == group_window:
        start_time = month_start(anchor_date)
        end_time = start_time + MonthDelta(months=1)

    return start_time, end_time
コード例 #3
0
ファイル: tests.py プロジェクト: lynnmatrix/statistic
    def setUp(self):
        self.day1 = month_start(timezone.now() - timedelta(days=60))

        self.day2 = self.day1 + timedelta(days=1)
        self.day_next_week_1 = self.day1 + timedelta(days=7)
        self.day_next_week_2 = self.day2 + timedelta(days=7)
        self.day_next_month_1 = self.day1 + relativedelta(months=1)
        self.day_next_month_2 = self.day2 + relativedelta(months=1)

        UserSurvival.objects.create(imei='imei1', firsttime=self.day1, lasttime=self.day1)
        UserSurvival.objects.create(imei='imei2', firsttime=self.day1, lasttime=self.day2)
        UserSurvival.objects.create(imei='imei3', firsttime=self.day2, lasttime=self.day_next_month_2)
        UserSurvival.objects.create(imei='imei4', firsttime=self.day2, lasttime=self.day_next_week_1)
コード例 #4
0
ファイル: tests.py プロジェクト: lynnmatrix/statistic
 def test_month_start(self):
     first_day = month_start(timezone.now())
     self.assertEqual(1, first_day.day)