Exemplo n.º 1
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)
Exemplo n.º 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_calendar_id_name(
         self, query)
     result, number_of_meetings = [], []
     for room in rooms_available:
         calendar_events = CommonAnalytics.get_all_events_in_a_room(
             self, room['calendar_id'], start_date, end_date)
         output = []
         if not calendar_events:
             output.append({'RoomName': room['name'], 'has_events': False})
             number_of_meetings.append(0)
         else:
             for event in calendar_events:
                 if event.get('attendees'):
                     event_details = CommonAnalytics.get_event_details(self, event, room['calendar_id'])  # noqa: E501
                     output.append(event_details)
             number_of_meetings.append(len(output))
         result.append(output)
     return (result, number_of_meetings)
Exemplo n.º 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
Exemplo n.º 4
0
    def get_analytics_ratios_per_room(self, query, start, end):
        """ Get ratios of checkings/cancellations to bookings per room.
         :params
            - start_date, end_date
        """
        start_date, day_after_end_date = CommonAnalytics.convert_dates(
            self, start, end)
        rooms = CommonAnalytics.get_calendar_id_name(self, query)

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

            checkins, cancellations, events_list = RoomAnalyticsRatios.retrieve_cancellations_and_checkins_for_room(
                self,  # noqa
                room['calendar_id'],
                start_date,
                day_after_end_date,
                checkins,
                cancellations,
                events_list)

            ratio_object = RoomAnalyticsRatios.map_results_to_ratio_class(
                self,  # noqa
                checkins,
                cancellations,
                events_list,
                room['name'])

            response.append(ratio_object)
        return response
Exemplo n.º 5
0
    def get_bookings_analytics_count(self, query, start, end, room_id=None):
        results = []
        start_date, day_after_end_date = CommonAnalytics.convert_dates(
            self, start, end)
        start_dt = dateutil.parser.parse(start_date)
        end_dt = dateutil.parser.parse(day_after_end_date)
        number_of_days = (end_dt - start_dt).days
        room_name = get_room_name(room_id)

        if number_of_days <= 30:
            dates = CommonAnalytics.get_list_of_dates(
                start, number_of_days)
            for date in dates:
                bookings = CommonAnalytics.get_total_bookings(
                    self, query, date[0], date[1], room_id=room_id)
                string_date = dateutil.parser.parse(
                    date[0]).strftime("%b %d %Y")
                output = BookingsAnalyticsCount(
                    period=string_date, bookings=bookings, room_name=room_name)
                results.append(output)

        else:
            dates = CommonAnalytics.get_list_of_month_dates(
                start_date, start_dt, day_after_end_date, end_dt)
            for date in dates:
                bookings = CommonAnalytics.get_total_bookings(
                    self, query, date[0], date[1], room_id=room_id)
                string_month = dateutil.parser.parse(date[0]).strftime("%B")
                output = BookingsAnalyticsCount(
                    period=string_month, bookings=bookings, room_name=room_name)
                results.append(output)

        return results
Exemplo n.º 6
0
 def validate_date(self, request_data):
     '''
     Validate date params
     '''
     if 'end_date' not in request_data:
         request_data['end_date'] = None
     try:
         start_date, end_date = CommonAnalytics.convert_dates(
             self, request_data['start_date'],
             request_data['end_date'])  # noqa: E501
         return (start_date, end_date)
     except ValueError as err:
         raise JsonError(error=str(err), example='Sep 15 2018')
Exemplo n.º 7
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
Exemplo n.º 8
0
    def get_bookings_analytics_count(self, query, start, end):
        results = []
        start_date, day_after_end_date = CommonAnalytics.convert_dates(
            self, start, end)  # noqa E501
        start_dt = dateutil.parser.parse(start_date)
        end_dt = dateutil.parser.parse(day_after_end_date)
        number_of_days = (end_dt - start_dt).days

        if number_of_days <= 15:
            dates = CommonAnalytics.get_list_of_dates(
                start, number_of_days)  # noqa E501
            for date in dates:
                bookings = CommonAnalytics.get_total_bookings(
                    self, query, date[0], date[1])  # noqa E501
                string_date = dateutil.parser.parse(date[0]).strftime(
                    "%b %d %Y")  # noqa E501
                output = BookingsAnalyticsCount(period=string_date,
                                                bookings=bookings)  # noqa E501
                results.append(output)

        elif number_of_days >= 90:
            dates = CommonAnalytics.get_list_of_month_dates(
                start_date, start_dt, day_after_end_date, end_dt)  # noqa E501
            for date in dates:
                bookings = CommonAnalytics.get_total_bookings(
                    self, query, date[0], date[1])  # noqa E501
                string_month = dateutil.parser.parse(date[0]).strftime("%B")
                output = BookingsAnalyticsCount(period=string_month,
                                                bookings=bookings)  # noqa E501
                results.append(output)

        else:
            raise GraphQLError(
                "Kindly enter a valid date range(less than 15 days or greater than 90 days"
            )  # noqa E501

        return results
Exemplo n.º 9
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.convert_dates(self, start_date, end_date)  # noqa: E501
        rooms = CommonAnalytics.get_calendar_id_name(
            self, query)
        result = []
        for room in rooms:
            events = CommonAnalytics.get_all_events_in_a_room(self, room['calendar_id'], start_date, end_date)  # noqa: E501
            events_duration = []
            for event in events:
                start = event['start'].get('dateTime', event['start'].get('date'))  # noqa: E501
                end = event['end'].get('dateTime', event['end'].get('date'))
                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