def prediction_page(date, location, direction='Southbound', lane='Car'): # Get chart data start = datetime.datetime.strptime(date, '%Y-%m-%d') predict = get_prediction(start, location, direction, lane) baseline = get_baseline(start, location, direction, lane) actual = get_actual(start, location, direction, lane) # Create labels by hour labels = [] time = datetime.datetime(2008, 4, 11) # Actual date is immaterial end = time + datetime.timedelta(hours=24) while time < end: if time.minute == 0 and time.hour % 2 == 0: labels.append(str(time.time())[:-3]) else: labels.append("") time += datetime.timedelta(minutes=30) # Date formatting for calendar control date_formatted = datetime.datetime \ .strptime(date, '%Y-%m-%d').strftime('%m/%d/%Y') # Dates for arrow buttons next_week = start + datetime.timedelta(days=7) next_week = next_week.strftime('%Y-%m-%d') last_week = start - datetime.timedelta(days=7) last_week = last_week.strftime('%Y-%m-%d') tomorrow = start + datetime.timedelta(days=1) tomorrow = tomorrow.strftime('%Y-%m-%d') yesterday = start - datetime.timedelta(days=1) yesterday = yesterday.strftime('%Y-%m-%d') return render_template('chart.html', date=date, default_date=date_formatted, dow=start.strftime("%A"), location=location, direction=direction, lane=lane, predict=list(predict.waittime), baseline=list(baseline.waittime), actual=list(actual.waittime), labels=labels, next_week=next_week, last_week=last_week, tomorrow=tomorrow, yesterday=yesterday )
def test_get_baseline(self): ''' Verify that minimum number of points have been predicted on each day ''' minimum_points = 8 begin = dt.date(2014, 1, 1) end = dt.date(2017, 1, 1) lane = 'Car' errorcount = 0 for location in ['Peace Arch', 'Pacific Highway']: for direction in ['Southbound', 'Northbound']: start = begin while start <= end: df = get_baseline(start, location, direction, lane) if pd.isnull(df.waittime).sum() > minimum_points: print '{0},{1},{2}'.format(start, location, direction) errorcount += 1 start += dt.timedelta(1) self.assertEqual(errorcount, 0)