Example #1
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
Example #2
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
Example #3
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