コード例 #1
0
    def add_calendar(self, attrs):
        service_id = attrs['FootnoteId']
        first = attrs['Firstdate']
        first_date = get_date(first)
        vector = attrs['Vector']

        if not len(vector):
            null = ["0",] * 7
            empty_date = first.replace("-", "")
            self._store_data("all", "calendar", [service_id,] + null +
                    [empty_date, empty_date])
            return

        end_date = first_date + timedelta(days=len(vector))

        days = to_ints(list(vector))
        overlaps = true_for_all(days)
        sub = true_for_some(days)
        week_overlaps = true_for_weeks(overlaps, first_date)[:7]

        fd = str(first_date).replace("-", "")
        ed = str(end_date).replace("-", "")
        self._store_data("all", "calendar", [service_id,] + map(str, week_overlaps) +
                [fd, ed])

        # add irregular dates
        for d in get_dates(sub, first_date):
            self._store_data("all", "calendar_dates", [service_id, str(d).replace("-", ""), '1'])
コード例 #2
0
ファイル: kalkati2gtfs.py プロジェクト: tapiohaa/kalkati2gtfs
    def add_calendar(self, attrs):
        service_id = attrs['FootnoteId']
        first = attrs['Firstdate']
        first_date = get_date(first)
        vector = attrs['Vector']

        if not len(vector):
            null = [
                "0",
            ] * 7
            empty_date = first.replace("-", "")
            self._store_data("all", "calendar", [
                service_id,
            ] + null + [empty_date, empty_date])
            return

        end_date = first_date + timedelta(days=len(vector))

        days = to_ints(list(vector))
        overlaps = true_for_all(days)
        sub = true_for_some(days)
        week_overlaps = true_for_weeks(overlaps, first_date)[:7]

        fd = str(first_date).replace("-", "")
        ed = str(end_date).replace("-", "")
        self._store_data("all", "calendar", [
            service_id,
        ] + map(str, week_overlaps) + [fd, ed])

        # add irregular dates
        for d in get_dates(sub, first_date):
            self._store_data(
                "all", "calendar_dates",
                [service_id, str(d).replace("-", ""), '1'])
コード例 #3
0
 def test_to_ints(self):
     self.assertEqual(to_ints(list('101')), [1, 0, 1])
コード例 #4
0
 def test_to_ints(self):
     self.assertEqual(to_ints(list('101')), [1, 0, 1])