def resolve_all_events(self, info, **kwargs): page = kwargs.get('page') per_page = kwargs.get('per_page') if page is not None and page < 1: raise GraphQLError("page must be at least 1") if per_page is not None and per_page < 1: raise GraphQLError("perPage must be at least 1") if page and not per_page: raise GraphQLError("perPage argument missing") if per_page and not page: raise GraphQLError("page argument missing") user = get_user_from_db() start_date, end_date = CommonAnalytics.all_analytics_date_validation( self, kwargs['start_date'], kwargs['end_date'] ) query = Events.get_query(info) all_events, all_dates = CommonAnalytics.get_all_events_and_dates( query, start_date, end_date ) events_in_location = CalendarEvents().get_events_in_location( user, all_events) all_days_events = [] for date in set(all_dates): daily_events = [] for event in events_in_location: CommonAnalytics.format_date(event.start_time) event_start_date = parser.parse( event.start_time).astimezone(pytz.utc) day_of_event = event_start_date.strftime("%a %b %d %Y") if date == day_of_event: daily_events.append(event) all_days_events.append( DailyRoomEvents( day=date, events=daily_events ) ) all_days_events.sort(key=lambda x: datetime.strptime(x.day, "%a %b %d %Y"), reverse=True) # noqa if page and per_page: paginated_events = ListPaginate( iterable=all_days_events, per_page=per_page, page=page) has_previous = paginated_events.has_previous has_next = paginated_events.has_next current_page = paginated_events.current_page pages = paginated_events.pages query_total = paginated_events.query_total return PaginatedDailyRoomEvents( DailyRoomEvents=current_page, has_previous=has_previous, has_next=has_next, query_total=query_total, pages=pages) return PaginatedDailyRoomEvents(DailyRoomEvents=all_days_events)
def write_analytics_to_html(self, query, start_date, end_date): report_data_frame = AnalyticsReport.generate_combined_analytics_report( self, query, start_date, end_date) start_date_formatted = CommonAnalytics.format_date(start_date) end_date_formatted = CommonAnalytics.format_date(end_date) WriteFile.write_to_html_file( report_data_frame['Most Used Rooms'], report_data_frame['Least Used Rooms'], '<h1>Room Analytics Report Summary</h1><p> <h2>Report Period: From ' + start_date_formatted + ' to ' + end_date_formatted + '</h2>', # noqa 'templates/analytics_report.html' ) rendered = render_template('analytics_report.html') return rendered