Exemple #1
0
    def get_all_rooms_summary(self, query, start_date, end_date):
        '''
        Get a summarry data for all rooms in a dataframe
        '''
        rooms_available = CommonAnalytics.get_room_details(self, query)
        all_rooms_data_df = AnalyticsReport.get_dataframe(
            self, rooms_available, start_date, end_date)

        rooms_no_meetings_df = all_rooms_data_df.loc[
            lambda all_rooms_data_df: all_rooms_data_df[
                'minutes'] == 0].rename(columns={
                    'roomName': 'Room'
                }).assign(Meetings=0)

        rooms_no_meetings_df = rooms_no_meetings_df[['Room', 'Meetings']]

        rooms_with_meeting_df = all_rooms_data_df[
            all_rooms_data_df['minutes'] != 0]['roomName'].value_counts(
            ).rename_axis('Room').reset_index(name='Meetings')
        rooms_summary_df = pd.concat(
            [rooms_no_meetings_df, rooms_with_meeting_df])
        rooms_summary_df['% Share of All Meetings'] = round(
            rooms_summary_df['Meetings'] / rooms_summary_df['Meetings'].sum() *
            100)
        return rooms_summary_df
Exemple #2
0
 def get_events_number_meetings_room_analytics(self, query, start_date, end_date):  # noqa: E501
     """ Get events in rooms and number of meetings per room
      :params
         - query
         - start_date, end_date(Time range)
     """
     start_date, end_date = CommonAnalytics.convert_dates(
         self, start_date, end_date)
     rooms_available = CommonAnalytics.get_room_details(
         self, query)
     result, number_of_meetings = [], []
     for room in rooms_available:
         all_events = CommonAnalytics.get_all_events_in_a_room(
             self, room['room_id'], start_date, end_date)
         output = []
         if not all_events:
             output.append({'roomName': room['name']})
             number_of_meetings.append(0)
         else:
             for event in all_events:
                 if event['participants']:
                     event_details = CommonAnalytics.get_event_details(
                         self, query, event, room['room_id'])
                     output.append(event_details)
             number_of_meetings.append(len(output))
         result.append(output)
     return (result, number_of_meetings)
Exemple #3
0
    def get_booked_rooms(self, query, start_date, end_date):  # noqa: E501
        """ Get booked room per given period of time and their percentages
         :params
            - query
            - start_date, end_date(Time range)
        """
        start_date, end_date = CommonAnalytics.convert_dates(
            self, start_date, end_date)
        rooms_available = CommonAnalytics.get_room_details(
            self, query)
        result = []
        bookings = 0
        for room in rooms_available:
            all_events_in_all_rooms = CommonAnalytics.get_all_events_in_a_room(
                self, room['room_id'], start_date, end_date)
            if all_events_in_all_rooms:
                bookings += len(all_events_in_all_rooms)

        for room in rooms_available:
            all_events = CommonAnalytics.get_all_events_in_a_room(
                self, room['room_id'], start_date, end_date)
            if all_events:
                room_details = RoomStatistics(
                    room_name=room["name"],
                    meetings=len(all_events),
                    percentage=(len(all_events))/bookings*100)

                result.append(room_details)
                result.sort(key=lambda x: x.meetings, reverse=True)
            else:
                return result
        return result
Exemple #4
0
    def get_analytics_ratios(self, query, start, end):
        """ Get ratios of checkings/cancellations to bookings for all rooms.
         :params
            - start_date, end_date
        """
        start_date, day_after_end_date = CommonAnalytics.validate_current_date(
            self, start, end)
        rooms = CommonAnalytics.get_room_details(
            self, query)

        checkins = 0
        cancellations = 0
        calendar_events_list = []
        app_events_list = []

        for room in rooms:
            checkins, cancellations, calendar_events_list, app_events_list = RoomAnalyticsRatios().retrieve_cancellations_and_checkins_for_room(room['room_id'],  # noqa
                                                        start_date,
                                                        day_after_end_date,
                                                        checkins,
                                                        cancellations,
                                                        calendar_events_list,
                                                        app_events_list)

        ratio_object = RoomAnalyticsRatios().map_results_to_ratio_class(
            checkins=checkins,
            cancellations=cancellations,
            calendar_events_list=calendar_events_list,
            app_events_list=app_events_list)

        return ratio_object
Exemple #5
0
 def get_meetings_per_room_analytics(self, query, start_date, end_date):
     """ Get analytics for meetings per room
      :params
         - query
         - start_date, end_date(Time range)
     """
     start_date, end_date = CommonAnalytics.convert_dates(
         self, start_date, end_date)
     rooms_available = CommonAnalytics.get_room_details(
         self, query)
     res = []
     for room in rooms_available:
         all_events = CommonAnalytics.get_all_events_in_a_room(
             self, room['room_id'], start_date, end_date)
         room_details = RoomStatistics(room_name=room["name"], count=len(all_events))  # noqa: E501
         res.append(room_details)
     return res
Exemple #6
0
    def get_analytics_ratios_per_room(self, query, start, end, **kwargs):
        """ Get ratios of checkings/cancellations to bookings per room.
         :params
            - start_date, end_date, room_id
        """
        room_id = kwargs.get('room_id')
        start_date, day_after_end_date = CommonAnalytics.validate_current_date(
            self, start, end)
        rooms = CommonAnalytics.get_room_details(
            self, query)

        response = []
        for room in rooms:
            checkins = 0
            cancellations = 0
            calendar_events_list = []
            app_events_list = []

            checkins, cancellations, calendar_events_list, app_events_list = RoomAnalyticsRatios().retrieve_cancellations_and_checkins_for_room(room['room_id'],  # noqa
                                                        start_date,
                                                        day_after_end_date,
                                                        checkins,
                                                        cancellations,
                                                        calendar_events_list,
                                                        app_events_list)

            ratio_object = RoomAnalyticsRatios().map_results_to_ratio_class(
                checkins=checkins,
                cancellations=cancellations,
                calendar_events_list=calendar_events_list,
                app_events_list=app_events_list,
                room_name=room['name'],
                room_id=room['room_id'])

            if room_id == ratio_object.room_id:
                return ratio_object

            response.append(ratio_object)

        return response
Exemple #7
0
    def get_meetings_duration_analytics(self, query, start_date, end_date):  # noqa: E501
        """ Get analytics for meetings durations in rooms
         :params
            - query
            - start_date, end_date(Time range)
        """
        start_date, end_date = CommonAnalytics.validate_current_date(
            self, start_date, end_date)
        rooms = CommonAnalytics.get_room_details(
            self, query)
        result = []
        for room in rooms:
            events = CommonAnalytics.get_all_events_in_a_room(
                self, room['room_id'], start_date, end_date)
            events_duration = []
            for event in events:
                start = event['event_start_time']
                end = event['event_end_time']
                duration = CommonAnalytics.get_time_duration_for_event(self, start, end)  # noqa: E501
                events_duration.append(duration)

            events_count = Counter(events_duration)

            events_in_minutes = [
                EventsDuration(
                    duration_in_minutes=events_duration,
                    number_of_meetings=events_count[events_duration])
                for index, events_duration in enumerate(events_count)
            ]

            output = RoomStatistics(
                room_name=room["name"],
                count=len(events_duration),
                total_duration=sum(events_duration),
                events=events_in_minutes
            )
            result.append(output)
        return result
Exemple #8
0
    def resolve_validate_rooms_calendar_ids(self, info):
        '''
        Validates the calendar IDs of all rooms in the database.
        Deletes all rooms with invalid calendar IDs.
        '''
        query = RoomModel.query
        calendar_ids = CommonAnalytics.get_room_details(self, query)

        invalid_rooms = []
        message = "All rooms have valid calendar IDs"
        for cal in calendar_ids:
            try:
                get_google_calendar_events(
                    calendarId=cal['calendar_id'])
            except Exception:
                exact_room = query.filter(
                    RoomModel.calendar_id == cal['calendar_id']).first()
                exact_room.delete()
                invalid_rooms.append(cal['name'])
                message = "All rooms with invalid calendar IDs have been deleted"  # noqa E501
        response = DeleteResponse(
            response=message,
            rooms=invalid_rooms)
        return response