Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Aggregation of bookings, in a given time interval, aggregated per
- #1 -> weekday
- #2 -> pre holiday
- #3 -> holiday
- #4 -> weekend
- '''
- def query_time_filter_day_type(self, provider, city, start, end, day_type):
- books_df = self.get_books("car2go", "torino", start, end)
- books_df['b_day'] = books_df['start'].apply(isbday)
- cal = Italy()
- holidays=[]
- #holidays collection creation
- if start.year == end.year :
- for h in cal.holidays(start.year):
- holidays.append(h[0])
- else :
- for year in range (start.year, end.year+1):
- for h in cal.holidays(year):
- holidays.append(h[0])
- if day_type == 1: #return business days
- business_books_df = books_df[books_df['b_day'] == True]
- return business_books_df
- elif day_type == 2 : #only the day BEFORE the holiday. WEEKends are not considered
- pre_holidays = []
- for d in holidays:
- pre_holidays.append(d - datetime.timedelta(days = 1))
- pre_holidays.pop()
- #ph_day = pre hoiday day
- books_df['ph_day'] = books_df['start'].apply(lambda x: x.date())
- books_df['ph_day'] = books_df[books_df['ph_day'].isin(pre_holidays)]
- pre_holidays_books_df = books_df.dropna(subset=['ph_day'],how='all')
- del pre_holidays_books_df['b_day']
- del pre_holidays_books_df['ph_day']
- return pre_holidays_books_df
- elif day_type == 3 : # holidays WEEKEND EXCLUDED
- books_df['h_day'] = books_df['start'].apply(lambda x: x.date())
- books_df['h_day'] = books_df[books_df['h_day'].isin(holidays)]
- holidays_books_df = books_df.dropna(subset=['h_day'],how='all')
- del holidays_books_df['b_day']
- del holidays_books_df['h_day']
- return holidays_books_df
- elif day_type == 4:#returns WEEKENDS
- weekend_books_df = books_df[books_df['b_day'] == False]
- return weekend_books_df
- else:
- print "day_type error"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement