Exemplo n.º 1
0
    def collect(self):
        """Collect grabs and returns a set of DataPoints."""
        service = build_service('fitness', 'v1')
        data = []
        now = time.time()
        utcnow = datetime.datetime.utcnow()

        for time_window, suffix in zip(self._parameters['time_windows'],
                                       self._parameters['suffixes']):
            ndays = utcnow - datetime.timedelta(hours=time_window)
            start_time = ndays.isoformat("T") + "Z"
            response = service.users().sessions().list(
                userId='me', startTime=start_time).execute()

            num_workout = len(response['session'])
            long_workout_count = 0
            time_workout = 0
            for session in response['session']:
                delta_workout = ((int(session['endTimeMillis']) -
                                  int(session['startTimeMillis'])) / 1000)
                time_workout += delta_workout
                if delta_workout >= 30 * 60:
                    long_workout_count += 1

            data.append(
                DataPoint(now, self._base_name + 'num_workout.' + suffix,
                          num_workout))
            data.append(
                DataPoint(now, self._base_name + 'num_long_workout.' + suffix,
                          long_workout_count))
            data.append(
                DataPoint(now, self._base_name + 'time_workout.' + suffix,
                          time_workout))
        return data
Exemplo n.º 2
0
 def collect(self):
     """Collect grabs and returns a set of DataPoints."""
     service = build_service('gmail', 'v1')
     data_points = []
     for query, suffix in zip(self._parameters['queries'], self._parameters['suffixes']):
         metric_name = self._base_name + suffix
         mails = list_mails_matching_query(service, query)
         data_points.append(DataPoint(time.time(), metric_name, len(mails)))
     return data_points
Exemplo n.º 3
0
    def collect(self):
        """Collect grabs and returns a set of DataPoints."""
        service = build_service('calendar', 'v3')
        data = []

        for time_window, suffix in zip(self._parameters['time_windows'],
                                       self._parameters['suffixes']):
            # TODO: Get Search prefix and calendar from configs
            events = get_calendar_entries_by_query(service, "S-", time_window,
                                                   "Tracking")

            # If we don't have any events we set it to the window size (which is in hours)
            seconds_since = [time_window * 60 * 60]
            long_count = 0
            short_count = 0
            for event in events:
                start_time = parse(event['start'].get('dateTime'))
                end_time = parse(event['end'].get('dateTime'))
                seconds_since.append(
                    (datetime.datetime.now(datetime.timezone.utc) -
                     start_time).total_seconds())
                event_length = end_time - start_time
                if event_length.seconds <= 30 * 60:
                    short_count += 1
                else:
                    long_count += 1

            data.append(
                DataPoint(time.time(), self._base_name + 's_count.' + suffix,
                          len(events)))
            data.append(
                DataPoint(time.time(),
                          self._base_name + 's_seconds_since.' + suffix,
                          min(seconds_since)))
            data.append(
                DataPoint(time.time(),
                          self._base_name + 's_short_count.' + suffix,
                          short_count))
            data.append(
                DataPoint(time.time(),
                          self._base_name + 's_long_count.' + suffix,
                          long_count))
        return data
Exemplo n.º 4
0
    def collect(self):
        """Collect grabs and returns a set of DataPoints."""
        service = build_service('gmail', 'v1')
        data_points = []
        for query, suffix in zip(self._parameters['queries'], self._parameters['suffixes']):
            mails = list_mails_matching_query(service, query)
            newest_age = sys.maxsize
            oldest_age = 0
            now = time.time()
            for mail in mails:
                msg = get_message(service, mail['id'])
                age = now - (int(msg['internalDate'])/1000)
                newest_age = min(newest_age, age)
                oldest_age = max(oldest_age, age)

            metric_name_oldest = self._base_name + suffix + '_oldest'
            metric_name_newest = self._base_name + suffix + '_newest'
            data_points.append(DataPoint(time.time(), metric_name_oldest, oldest_age))
            data_points.append(DataPoint(time.time(), metric_name_newest, newest_age))
        return data_points
Exemplo n.º 5
0
    def collect(self):
        """Collect grabs and returns a set of DataPoints."""
        service = build_service('gmail', 'v1')
        metric_name = self._base_name + 'inbox_oldest'
        mails = list_mails_matching_query(service, 'in:inbox')
        thread_age = {}
        now = time.time()

        if not mails:
            return [DataPoint(time.time(), metric_name, 0)]

        for mail in mails:
            thread_id = mail['threadId']
            msg = get_message(service, mail['id'])
            age = now - (int(msg['internalDate'])/1000)
            if thread_id not in thread_age:
                thread_age[thread_id] = age
            else:
                if age < thread_age[thread_id]:
                    thread_age[thread_id] = age

        return [DataPoint(time.time(), metric_name, max(thread_age.values()))]