Exemple #1
0
 def get_most_used_room_week(self, query, week_start,
                             week_end):  # noqa: E501
     """ Get analytics for most used room per week
      :params
         - calendar_id
         - week_start, week_end(Time range)
     """
     week_start = CommonAnalytics.convert_date(self, week_start)
     week_end = CommonAnalytics.convert_date(self, week_end)
     rooms_available = CommonAnalytics.get_calendar_id_name(self, query)
     res = []
     number_of_most_events = 0
     for room in rooms_available:
         calendar_events = CommonAnalytics.get_all_events_in_a_room(
             self, room['calendar_id'], week_start, week_end)
         output = []
         if not calendar_events:
             output.append({'RoomName': room['name'], 'has_events': False})
             number_of_most_events = 0
         else:
             for event in calendar_events:
                 event_details = CommonAnalytics.get_event_details(
                     self, event, room['calendar_id'])
                 output.append(event_details)
             if len(output) > number_of_most_events:
                 number_of_most_events = len(output)
         res.append(output)
     analytics = CommonAnalytics.get_room_statistics(
         self, number_of_most_events, res)
     return analytics
Exemple #2
0
    def get_monthly_rooms_events(self, query, month, year):
        """ Get event stats for all rooms in a specified month
         :params
            - month, year
        """
        date = month + ' 1 ' + str(year)
        startdate = CommonAnalytics.convert_date(self, date)
        date_after_month = (
            datetime.strptime(date, '%b %d %Y') +
            relativedelta(months=1)).isoformat() + 'Z'  # noqa: E501

        rooms_available = CommonAnalytics.get_calendar_id_name(self, query)
        room_events_count = []
        events_in_all_rooms = []
        for room in rooms_available:
            calendar_events = CommonAnalytics.get_all_events_in_a_room(
                self, room['calendar_id'], startdate, date_after_month)
            output = []
            if not calendar_events:
                output.append({'RoomName': room['name'], 'has_events': False})
                room_with_no_events = 0
                room_events_count.append(room_with_no_events)

            else:
                for event in calendar_events:
                    if event.get('attendees'):
                        event_details = CommonAnalytics.get_event_details(
                            self, event, room['calendar_id'])
                        output.append(event_details)
                room_events_count.append(len(output))
            events_in_all_rooms.append(output)
        return dict(events_in_all_rooms=events_in_all_rooms,
                    room_events_count=room_events_count)
Exemple #3
0
    def meetings_duration_statistics(self, query, start_date,
                                     end_date):  # noqa: E501
        """
        Get meeting durations statistics
        """
        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
Exemple #4
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)
Exemple #5
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_calendar_id_name(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 #6
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
Exemple #7
0
 def get_least_used_room_day(self, query, day):
     """ Get event stats for all rooms in a specified day
         :params
             - day
     """
     day_start, day_end = CommonAnalytics.get_start_end_day_dates(self, day)
     rooms_available = CommonAnalytics.get_calendar_id_name(self, query)
     return RoomAnalytics.get_least_used_rooms(self, rooms_available,
                                               day_start,
                                               day_end)  # noqa: E501
Exemple #8
0
 def get_meetings_per_room(self, query, timeMin, timeMax):
     day_start = CommonAnalytics.convert_date(self, timeMin)
     day_end = CommonAnalytics.convert_date(self, timeMax)
     rooms_available = CommonAnalytics.get_calendar_id_name(self, query)
     res = []
     for room in rooms_available:
         calendar_events = CommonAnalytics.get_all_events_in_a_room(
             self, room['calendar_id'], day_start, day_end)
         room_details = RoomStatistics(
             room_name=room["name"],
             count=len(calendar_events))  # noqa: E501
         res.append(room_details)
     return res
Exemple #9
0
    def get_least_used_room_week(self, query, week_start,
                                 week_end):  # noqa: E501
        """ Get analytics for least used room per week
         :params
            - calendar_id
            - week_start, week_end(Time range)
        """
        week_start = CommonAnalytics.convert_date(self, week_start)
        week_end = CommonAnalytics.convert_date(self, week_end)

        rooms_available = CommonAnalytics.get_calendar_id_name(self, query)
        return RoomAnalytics.get_least_used_rooms(self, rooms_available,
                                                  week_start,
                                                  week_end)  # noqa: E501
Exemple #10
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_calendar_id_name(self, query)
     all_rooms_data_df = AnalyticsReport.get_dataframe(
         self, rooms_available, start_date, end_date)
     rooms_summary_df = all_rooms_data_df['roomName'].value_counts(
     ).rename_axis(  # noqa: E501
         'Room').reset_index(name='Meetings')
     rooms_summary_df['% Share of All Meetings'] = round(
         rooms_summary_df['Meetings'] / rooms_summary_df['Meetings'].sum() *
         100)  # noqa: E501
     return rooms_summary_df
Exemple #11
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_calendar_id_name(
         self, query)
     res = []
     for room in rooms_available:
         calendar_events = CommonAnalytics.get_all_events_in_a_room(
             self, room['calendar_id'], start_date, end_date)
         room_details = RoomStatistics(room_name=room["name"], count=len(calendar_events))  # noqa: E501
         res.append(room_details)
     return res
    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_calendar_id_name(self, query)
        service = Credentials.set_api_credentials(self)

        invalid_rooms = []
        message = "All rooms have valid calendar IDs"
        for cal in calendar_ids:
            try:
                service.events().list(calendarId=cal['calendar_id']).execute()
            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