コード例 #1
0
 def setUp(self):
     self.engine = create_engine('sqlite:///:memory:')
     Session = sessionmaker()
     Session.configure(bind=self.engine)
     self.session = Session()
     models.Base.metadata.create_all(self.engine)
     # creating 3 routes, 9 daily and 9 service hour models per route
     for number in range(1, 4):
         route = models.Route(id=number,
                              route_number=number,
                              route_name='TEST ROUTE {0}'.format(number),
                              service_type='LOCAL')
         self.session.add(route)
         self.session.commit()
         year = 2010
         for day in ['weekday', 'sunday', 'saturday']:
             for season in ['summer', 'spring', 'winter']:
                 ridership = int(1000 / number) + (10 * number)
                 productivity = (10 * number) - (number + 3)
                 timestamp = utils.get_period_timestamp(day, season, year)
                 daily = models.DailyRidership(
                     created_on=datetime.utcnow(),
                     is_current=True,
                     day_of_week=day,
                     season=season,
                     calendar_year=year,
                     ridership=ridership,
                     route_id=route.id,
                     measurement_timestamp=timestamp)
                 productivity = models.ServiceHourRidership(
                     created_on=datetime.utcnow(),
                     is_current=True,
                     day_of_week=day,
                     season=season,
                     calendar_year=year,
                     ridership=productivity,
                     route_id=route.id,
                     measurement_timestamp=timestamp)
                 self.session.add(daily)
                 self.session.add(productivity)
     self.session.commit()
     etl.update_weekly_performance(self.session)
     perfdocs.update_productivity_document(self.session)
     pd = self.session.query(
         models.PerformanceDocument).filter_by(name='productivity').one()
     self.document = json.loads(pd.document)
コード例 #2
0
 def setUp(self):
     self.engine = create_engine('sqlite:///:memory:')
     Session = sessionmaker()
     Session.configure(bind=self.engine)
     self.session = Session()
     models.Base.metadata.create_all(self.engine)
     # creating 3 routes, 9 daily and 9 service hour models per route
     for number in range(1, 4):
         route = models.Route(id=number,
                              route_number=number,
                              route_name='TEST ROUTE {0}'.format(number),
                              service_type='LOCAL')
         self.session.add(route)
         self.session.commit()
         year = 2010
         for day in ['weekday', 'sunday', 'saturday']:
             for season in ['summer', 'spring', 'winter']:
                 ridership = int(1000 / number) + (10 * number)
                 productivity = (10 * number) - (number + 3)
                 timestamp = utils.get_period_timestamp(day, season, year)
                 daily = models.DailyRidership(created_on=datetime.utcnow(),
                                               is_current=True,
                                               day_of_week=day,
                                               season=season,
                                               calendar_year=year,
                                               ridership=ridership,
                                               route_id=route.id,
                                               measurement_timestamp=timestamp)
                 productivity = models.ServiceHourRidership(created_on=datetime.utcnow(),
                                                            is_current=True,
                                                            day_of_week=day,
                                                            season=season,
                                                            calendar_year=year,
                                                            ridership=productivity,
                                                            route_id=route.id,
                                                            measurement_timestamp=timestamp)
                 self.session.add(daily)
                 self.session.add(productivity)
     self.session.commit()
     etl.update_weekly_performance(self.session)
     perfdocs.update_productivity_document(self.session)
     pd = self.session.query(models.PerformanceDocument).filter_by(name='productivity').one()
     self.document = json.loads(pd.document)
コード例 #3
0
 def test_winter_sunday(self):
     timestamp = utils.get_period_timestamp('sunday', 'winter', 2016)
     self.assertEqual(timestamp.isoweekday(), 7)
     self.assertEqual(timestamp.month, 1)
     self.assertEqual(timestamp.day, 3)
     self.assertEqual(timestamp.year, 2016)
コード例 #4
0
 def test_fall_sunday(self):
     timestamp = utils.get_period_timestamp('sunday', 'fall', 2016)
     self.assertEqual(timestamp.isoweekday(), 7)
     self.assertEqual(timestamp.month, 10)
     self.assertEqual(timestamp.day, 2)
     self.assertEqual(timestamp.year, 2016)
コード例 #5
0
 def test_fall_weekday(self):
     timestamp = utils.get_period_timestamp('weekday', 'fall', 2016)
     self.assertEqual(timestamp.isoweekday(), 1)
     self.assertEqual(timestamp.month, 9)
     self.assertEqual(timestamp.day, 26)
     self.assertEqual(timestamp.year, 2016)
コード例 #6
0
 def test_summer_saturday(self):
     timestamp = utils.get_period_timestamp('saturday', 'summer', 2016)
     self.assertEqual(timestamp.isoweekday(), 6)
     self.assertEqual(timestamp.month, 7)
     self.assertEqual(timestamp.day, 2)
     self.assertEqual(timestamp.year, 2016)
コード例 #7
0
 def test_spring_sunday(self):
     timestamp = utils.get_period_timestamp('sunday', 'spring', 2016)
     self.assertEqual(timestamp.isoweekday(), 7)
     self.assertEqual(timestamp.month, 4)
     self.assertEqual(timestamp.day, 3)
     self.assertEqual(timestamp.year, 2016)
コード例 #8
0
ファイル: test_utils.py プロジェクト: jga/capmetrics-etl
 def test_winter_sunday(self):
     timestamp = utils.get_period_timestamp('sunday', 'winter', 2016)
     self.assertEqual(timestamp.isoweekday(), 7)
     self.assertEqual(timestamp.month, 1)
     self.assertEqual(timestamp.day, 3)
     self.assertEqual(timestamp.year, 2016)
コード例 #9
0
ファイル: test_utils.py プロジェクト: jga/capmetrics-etl
 def test_fall_sunday(self):
     timestamp = utils.get_period_timestamp('sunday', 'fall', 2016)
     self.assertEqual(timestamp.isoweekday(), 7)
     self.assertEqual(timestamp.month, 10)
     self.assertEqual(timestamp.day, 2)
     self.assertEqual(timestamp.year, 2016)
コード例 #10
0
ファイル: test_utils.py プロジェクト: jga/capmetrics-etl
 def test_fall_weekday(self):
     timestamp = utils.get_period_timestamp('weekday', 'fall', 2016)
     self.assertEqual(timestamp.isoweekday(), 1)
     self.assertEqual(timestamp.month, 9)
     self.assertEqual(timestamp.day, 26)
     self.assertEqual(timestamp.year, 2016)
コード例 #11
0
ファイル: test_utils.py プロジェクト: jga/capmetrics-etl
 def test_summer_saturday(self):
     timestamp = utils.get_period_timestamp('saturday', 'summer', 2016)
     self.assertEqual(timestamp.isoweekday(), 6)
     self.assertEqual(timestamp.month, 7)
     self.assertEqual(timestamp.day, 2)
     self.assertEqual(timestamp.year, 2016)
コード例 #12
0
ファイル: test_utils.py プロジェクト: jga/capmetrics-etl
 def test_spring_sunday(self):
     timestamp = utils.get_period_timestamp('sunday', 'spring', 2016)
     self.assertEqual(timestamp.isoweekday(), 7)
     self.assertEqual(timestamp.month, 4)
     self.assertEqual(timestamp.day, 3)
     self.assertEqual(timestamp.year, 2016)