コード例 #1
0
 def show_all(self, sport, start_date, end_date):
     df = self.df_dict[sport].copy(deep=False)
     df = self.get_sessions_in_timespan(df, start_date, end_date)
     df.reset_index(inplace=True)
     df.rename(columns={'index': 'i-th session (0 started)'}, inplace=True)
     df = df.sort_values(by='start_time',
                         ascending=False,
                         ignore_index=True)
     utils.show_dataframe_in_web(df, 'All sessions')
コード例 #2
0
    def show_top_time_consuming(self, sport, how_many, start_date, end_date):
        df = self.df_dict[sport].copy(deep=False)
        df = self.get_sessions_in_timespan(df, start_date, end_date)
        df.reset_index(inplace=True)
        df.rename(columns={'index': 'i-th session (0 started)'}, inplace=True)

        df = df.sort_values(by='duration', ascending=False,
                            ignore_index=True).head(how_many)

        utils.show_dataframe_in_web(
            df, f'{how_many} most time consuming sessions')
コード例 #3
0
    def show_top_time_in_distance(self, sport, how_many, distance, start_date,
                                  end_date):
        column = f'{distance}km_time'
        df = self.df_dict[sport].copy(deep=False)
        df = self.get_sessions_in_timespan(df, start_date, end_date)
        df.reset_index(inplace=True)
        df.rename(columns={'index': 'i-th session (0 started)'}, inplace=True)

        df = df.sort_values(by=column, ascending=True,
                            ignore_index=True).head(how_many)

        utils.show_dataframe_in_web(df, f'Best {distance}km time sessions')
コード例 #4
0
    def show_top_distances(self, sport, how_many, start_date, end_date):
        df = self.df_dict[sport].copy(deep=False)
        df = self.get_sessions_in_timespan(df, start_date, end_date)
        df.reset_index(inplace=True)
        df.rename(columns={'index': 'i-th session (0 started)'}, inplace=True)

        # Dealing with strings and ints
        df = df.replace(const.empty_value, 0)
        df = df.sort_values(by='distance', ascending=False,
                            ignore_index=True).head(how_many)
        df = df.replace(0, const.empty_value)

        utils.show_dataframe_in_web(df, f'{how_many} longest sessions')
コード例 #5
0
    def show_sessions_with_minimum_distance(self, sport, distance, start_date,
                                            end_date):
        df = self.df_dict[sport].copy(deep=False)
        df = self.get_sessions_in_timespan(df, start_date, end_date)
        df.reset_index(inplace=True)
        df.rename(columns={'index': 'i-th session (0 started)'}, inplace=True)

        df = df[df['distance'] >= distance]

        df = df.sort_values(by='start_time',
                            ascending=False,
                            ignore_index=True)

        utils.show_dataframe_in_web(df, f'Sessions with at least {distance}km')
コード例 #6
0
    def show_top_avg_heart_rates(self, sport, how_many, start_date, end_date):
        df = self.df_dict[sport].copy(deep=False)
        df = self.get_sessions_in_timespan(df, start_date, end_date)
        df.reset_index(inplace=True)
        df.rename(columns={'index': 'i-th session (0 started)'}, inplace=True)

        # Dealing with strings and ints
        df = df.replace(const.empty_value, 0)
        df = df.sort_values(by=[
            'avg_heart_rate', 'avg_heart_rate_as_percentage', 'max_heart_rate',
            'max_heart_rate_as_percentage'
        ],
                            ascending=False,
                            ignore_index=True).head(how_many)
        df = df.replace(0, const.empty_value)

        utils.show_dataframe_in_web(
            df, f'{how_many} highest average heart rates in session')
コード例 #7
0
    def show_country_stats(self, sport, start_date, end_date):
        df = self.df_dict[sport].copy(deep=False)
        df = self.get_sessions_in_timespan(df, start_date, end_date)
        df.reset_index(inplace=True)
        df.rename(columns={'index': '# of sessions'}, inplace=True)

        df['duration'] = utils.duration_to_timedelta(df['duration'])

        if const.sport_processor[sport.upper(
        )] == 'running' or const.sport_processor[
                sport.upper()] == 'distance_based' or const.sport_processor[
                    sport.upper()] == 'cycling':
            # Dealing with strings
            df = df.replace(
                {
                    'distance': const.empty_value,
                    'duration': const.empty_value,
                    'avg_speed': const.empty_value
                }, 0)
            df = df.groupby(by='country').agg({
                '# of sessions': 'count',
                'distance': 'sum',
                'duration': 'sum',
                'avg_speed': 'mean'
            })
            df = df.sort_values(
                by=['# of sessions', 'distance', 'duration', 'avg_speed'],
                ascending=False,
                ignore_index=False)
        else:
            df = df.groupby(by='country').agg({
                '# of sessions': 'count',
                'duration': 'sum'
            })
            df = df.sort_values(by=['# of sessions', 'duration'],
                                ascending=False,
                                ignore_index=False)
        df['duration'] = utils.timedelta_to_duration(df['duration'])

        utils.show_dataframe_in_web(df, f'Country stats for {sport}')