예제 #1
0
    def get_stats_this_year(user):
        year = today_pacific().year

        sessions = GoogleFitYoga.get_sessions_for_year(user, year)
        total_duration_seconds = 0
        total_sessions = 0

        for session in sessions:
            total_sessions += 1
            total_duration_seconds += session.duration_seconds

        total_minutes = int(total_duration_seconds / 60)
        average_session_length = int((total_duration_seconds / total_sessions) / 60)

        return [
            Stat(
                stat_id='yoga_sessions_current_year',
                description='Total Yoga Sessions',
                value=f'{total_sessions}',
                notes=''
            ),
            Stat(
                stat_id='yoga_duration_current_year',
                description='Time spent doing Yoga (minutes)',
                value=f'{total_minutes}',
                notes=''
            ),
            Stat(
                stat_id='yoga_avg_duration_current_year',
                description='Average Yoga Session (minutes)',
                value=f'{average_session_length}',
                notes=''
            ),
        ]
예제 #2
0
 def _get_books_read_this_year():
     current_year = today_pacific().year
     titles = GoodreadsAPI.get_books_read_for_year(current_year)
     return Stat(stat_id="read_current_year",
                 description="Books I read this year",
                 value=titles,
                 notes='')
예제 #3
0
    def _get_books_read_last_year():
        year = today_pacific().year - 1

        titles = GoodreadsAPI.get_books_read_for_year(year)
        return Stat(stat_id="read_prev_year",
                    description="Books I read last year",
                    value=titles,
                    notes='')
예제 #4
0
    def days_missing(user):
        # we should have days for all of the previous year, and
        # all days this year so far.
        end_date = today_pacific()

        start_date = datetime.date(end_date.year - 1, 1, 1)
        expected_dates = set(util.get_dates_between(start_date, end_date))

        # ok now we query the database for all the dates that we have
        # We could probably filter by start/end dates here
        data_objs = GoogleFitData.query.filter_by(
            user=user
            ).all()

        for data_obj in data_objs:
            if data_obj.date in expected_dates:
                expected_dates.remove(data_obj.date)
        return expected_dates
예제 #5
0
    def _get_recent_stats(user):
        stats = []
        today = today_pacific()
        yesterday = today - datetime.timedelta(days=1)

        data_today = GoogleFitData.get_data_for_day(user, today)
        if data_today:
            stats.append(
                Stat(
                    stat_id='step_count_today',
                    description='Steps Today',
                    value='{steps:,}'.format(steps=data_today.step_count),
                    notes=''
                )
            )
            stats.append(
                Stat(
                    stat_id=f'distance_miles_today',
                    description=f'Distance Today (miles)',
                    value='{distance:.2f}'.format(distance=convert_metres_to_miles(data_today.distance_metres)),
                    notes="Includes running and walking"
                )
            )

        data_yesterday = GoogleFitData.get_data_for_day(user, yesterday)
        if data_yesterday:
            stats.append(
                Stat(
                    stat_id='step_count_yesterday',
                    description='Steps Yesterday',
                    value='{steps:,}'.format(steps=data_yesterday.step_count),
                    notes=''
                )
            )
            stats.append(
                Stat(
                    stat_id=f'distance_miles_yesterday',
                    description=f'Distance Yesterday(miles)',
                    value='{distance:.2f}'.format(distance=convert_metres_to_miles(data_yesterday.distance_metres)),
                    notes="Includes running and walking"
                )
            )

        return stats
예제 #6
0
파일: strava.py 프로젝트: theletterd/stats
    def get_stats(user):
        runs = StravaAPI.get_run_data(user)

        run_data = {}
        for run_date, distance_metres in runs:

            if run_date.year not in run_data:
                run_data[run_date.year] = {
                    'run_count': 0,
                    'distance_run_metres': 0
                }

            run_data[run_date.year]['run_count'] += 1
            run_data[run_date.year]['distance_run_metres'] += distance_metres

        # construct stats
        current_year = today_pacific().year
        prev_year = current_year - 1

        distance_current_year = convert_metres_to_miles(
            run_data.get(current_year, {}).get('distance_run_metres', 0))
        distance_last_year = convert_metres_to_miles(
            run_data.get(prev_year, {}).get('distance_run_metres', 0))

        constructed_stats = [
            Stat(stat_id='distance_run_current_year_miles',
                 description='Distance this year (miles)',
                 value=f"{distance_current_year:.2f}",
                 notes=''),
            Stat(stat_id='distance_run_prev_year_miles',
                 description='Distance last year (miles)',
                 value=f"{distance_last_year:.2f}",
                 notes=''),
            Stat(stat_id='run_count_current_year',
                 description='Runs this year',
                 value=run_data.get(current_year, {}).get('run_count', 0),
                 notes=''),
            Stat(stat_id='run_count_prev_year',
                 description='Runs last year',
                 value=run_data.get(prev_year, {}).get('run_count', 0),
                 notes='')
        ]

        return constructed_stats
예제 #7
0
파일: goals.py 프로젝트: theletterd/stats
 def get_goals_data():
     year = today_pacific().year
     url = URL_FORMAT.format(year=year)
     resp = requests.get(url)
     return resp.json()
예제 #8
0
 def process_args(self):
     self.end_date = self.args.end_date or util.today_pacific()
     self.start_date = self.args.start_date or (self.end_date -
                                                datetime.timedelta(days=1))
     self.user_id = self.args.user_id
예제 #9
0
 def _get_stats_for_prev_year(user):
     year = today_pacific().year - 1
     return WithingsStats._get_stats_for_year(user, year, "Last Year", "prev_year")
예제 #10
0
 def _get_stats_for_current_year(user):
     year = today_pacific().year
     return WithingsStats._get_stats_for_year(user, year, "This year", "current_year")
예제 #11
0
 def _get_stats_for_current_year(user):
     year = today_pacific().year
     return GoogleFitStats._get_stats_for_year(user, year, "This year", "current_year")