Ejemplo n.º 1
0
 def externDetailsPilote(self,
                         data_indir,
                         position_frames=0,
                         position_traitements=1):
     """
     Extern some distinct information about pilots: Poids, Taille, Braquet,
     Longueur Manivelle and the time of the best trial.
         :param data_indir:Path to data indir.
         :param position_frames: Position of the file frames in a trial by default 0.
         :param position_traitements:Position of the file taitement in a trial by default 1.
         :return:txt file.
     """
     bestTrials = NavigateFiles().get_all_best_trials(data_indir)
     masseRiders = []
     BraquetRiders = []
     longueurManivelleRiders = []
     tailleRiders = []
     f = open('Details_riders.txt', 'w')
     print('-----------------------------', file=f)
     for trial in bestTrials:
         fileList = glob.glob((trial + '\\*.csv'))
         traitement = pd.read_csv(
             fileList[position_traitements]
         )  # 0 -> first file in list its CDonetraitement.csv
         frames = pd.read_csv(fileList[position_frames]
                              )  # 2 -  > third file in list its frames
         time = traitement['Time']
         if 'Braquet' in frames.columns:
             braquet = frames['Braquet'][0]
         else:
             braquet = 0
         if 'MasseRider' in frames.columns:
             masseRider = frames['MasseRider'][0]
         else:
             masseRider = 0
         if 'longueurManivelle' in frames.columns:
             longueurManivelle = frames['longueurManivelle'][0]
         else:
             longueurManivelle = 0
         if 'TailleRider' in frames.columns:
             tailleRider = frames['TailleRider'][0]
         else:
             tailleRider = 0
         print('{} time: {:.3f}s'.format(
             trial.split('\\')[-2], time.iloc[-2]),
               file=f)
         print('-----------------------------', file=f)
         print('Poids: {} '.format(masseRider), file=f)
         print('taille: {} '.format(tailleRider), file=f)
         print('braquet: {}'.format(braquet), file=f)
         print('Longueur Manivelle: {}'.format(longueurManivelle), file=f)
         print('-----------------------------', file=f)
         masseRiders.append(masseRider)
         tailleRiders.append(tailleRider)
         BraquetRiders.append(braquet * 10)
         longueurManivelleRiders.append(longueurManivelle)
Ejemplo n.º 2
0
    def get_tps_reaction_all_pilots(self):
        files = NavigateFiles().get_all_files_by_name(data_indir='.\\data\\',
                                                      file_name=2)
        for frames in files:
            pilot_name = frames[0].split("\\")[-3]
            f = open('tps_reaction\\{}.csv'.format(pilot_name), 'w')
            print("TpsReaction,", file=f)
            for frame in frames:
                # pilot_name = frame.split("\\")[-3]
                frames_df = pd.read_csv(frame)
                tps_reaction = frames_df['TpsReaction'][0] - frames_df["Bip"][0]

                print("{},".format(tps_reaction), file=f)
Ejemplo n.º 3
0
    def plot_best_pilot_trial_single(self, data_indir, x_axis, y_axis):
        """
            Plot pilots best trial in separated figure.
                :param data_indir:  Path to data.
                :param x_axis: array of features to plot in x-axis.
                :param y_axis:  array of features to plot in the y-axis.
        """

        best_trials = NavigateFiles().get_all_best_trials(data_indir)
        legend = []
        for xi in x_axis:  # for all x axis variables
            for trial in best_trials:  # for the best trail of the pilot
                fileList = glob.glob(
                    (trial + '\\*.csv'))  # all files of a trial
                traitement = pd.read_csv(
                    fileList[1])  # first file in the trail
                frames = pd.read_csv(fileList[0])
                pilot_name = trial.split('\\')[-2]
                x = traitement[xi]
                coups_de_pedal1 = frames['CoupsDePedal'][0] - frames["Bip"][0]
                coups_de_pedal2 = frames['CoupsDePedal.1'][0] - frames["Bip"][0]
                coups_de_pedal3 = frames['CoupsDePedal.2'][0] - frames["Bip"][0]
                # plt.figure(num=None, figsize=(12.8, 7.2), dpi=300, facecolor='w', edgecolor='k')

                for column in y_axis:  # for all y axis variables
                    col = traitement[column]
                    if column == 'VitesseRider':
                        col = col * 100
                        legend.append('{}'.format(column + '* 100'))
                    else:
                        legend.append('{}'.format(column))
                    plt.plot(x, col)
                str = ','.join(y_axis)
                plt.xlabel(xi)
                plt.ylabel(column)
                plt.legend(legend)
                plt.title('Pilote {}: {} en fonction de {}'.format(
                    pilot_name, str, xi))
                plt.axvline(x[coups_de_pedal1], color='red', linestyle='--')
                plt.axvline(x[frames['TpsReaction'][0] - frames["Bip"][0]],
                            color='red',
                            linestyle='--')
                plt.axvline(x[coups_de_pedal2], color='red', linestyle='--')
                plt.axvline(x[coups_de_pedal3], color='red', linestyle='--')
                plt.grid()
                plt.show()
Ejemplo n.º 4
0
    def concat_all_traitement(self, data_indir, file_name='traitement'):
        """
        Concatenat all csv traitement files onto 1 concatenated csv file

            :param data_indir: Path to data file.
            :param file_name: Prefix of file name.
        """
        files = NavigateFiles().get_all_files_by_name(data_indir, file_name)
        appended_data = []
        for pilote in files:
            for file in pilote:  # the file in th trial
                traitemnt = pd.read_csv(file)
                appended_data.append(traitemnt)
        appended_data = pd.concat(appended_data, axis=0)
        current_directory = os.path.dirname(os.path.realpath(__file__))
        appended_data.to_csv(
            "{}\\AlltraitementConcatenated.csv".format(current_directory),
            index=0)
Ejemplo n.º 5
0
    def plot_by_pilotes_names_trials_nums_dates(self, data_indir,
                                                pilotes_names, trials_nums,
                                                dates_trial, x_axis, y_axis):
        """

        :param data_indir:
        :param pilotes_names:
        :param trials_nums:
        :param x_axis:
        :param y_axis:
        :return:
        """
        trial_files = NavigateFiles(
        ).get_files_by_pilotes_names_trials_nums_dates(data_indir,
                                                       pilotes_names,
                                                       trials_nums,
                                                       dates_trial)
        legend = []
        for xi in x_axis:
            for column in y_axis:
                # plt.figure(num=None, figsize=(12.8, 7.2), dpi=300, facecolor='w', edgecolor='k')
                for trial in trial_files:
                    traitement = pd.read_csv(trial[1])  # first file in the
                    x = traitement[xi]
                    col = traitement[column]
                    pilot_name = trial[0].split('\\')[-3]
                    trial_and_number = trial[0].split('\\')[-2]
                    plt.plot(x, col)
                    legend.append('{} {} '.format(pilot_name,
                                                  trial_and_number))
                plt.xlabel(xi)
                plt.ylabel(column)
                plt.legend(legend)
                plt.title('{} en fonction de {}'.format(column, xi))
                plt.grid()
                # txt = "{}".format()
                # plt.figtext(0.5, 0.01, txt, wrap=True, horizontalalignment='center', fontsize=12)
                # plt.savefig('figures/{}_{}.png'.format(column, xi))
                plt.show()
Ejemplo n.º 6
0
    def plot_best_pilots_trial_together(self, data_indir, x_axis, y_axis):
        """
            Plot the best trial of each pilot in one figure.
                :param data_indir:  Path to data.
                :param x_axis: array of features to plot in xaxis.
                :param y_axis:  array of features to plot in the y-axis.
        """

        bestTrials = NavigateFiles().get_all_best_trials(data_indir)
        legend = []
        for xi in x_axis:
            for column in y_axis:
                # plt.figure(num=None, figsize=(12.8, 7.2), dpi=300, facecolor='w', edgecolor='k')
                for trial in bestTrials:
                    fileList = glob.glob(
                        (trial + '\\*.csv'))  # all files of a trial
                    traitement = pd.read_csv(fileList[1])  # first file in the
                    x = traitement[xi]
                    time = traitement['Time']
                    pilot_name = trial.split('\\')[-2]
                    trial_and_number = trial.split('\\')[-1]
                    col = traitement[column]
                    plt.plot(x, col)
                    legend.append('{} {} time:{:.3f}s'.format(
                        pilot_name, trial_and_number, time.iloc[-2]))
                    print('{} time: {}'.format(
                        trial.split('\\')[-2], time.iloc[-2]))
                print()
                print()
                plt.xlabel(xi)
                plt.ylabel(column)
                plt.legend(legend)
                plt.title('{} en fonction de {}'.format(column, xi))
                plt.grid()
                # txt = "{}".format()
                # plt.figtext(0.5, 0.01, txt, wrap=True, horizontalalignment='center', fontsize=12)
                # plt.savefig('figures/{}_{}.png'.format(column, xi))
                plt.show()
Ejemplo n.º 7
0
    def concat_all_frames(self, data_indir, file_name='frames'):
        """
        Concatenat all csv frame files onto 1 concatenated csv file

            :param data_indir: Path to data.
            :param file_name: Prefix of file name.

        """

        frames = NavigateFiles().get_all_files_by_name(data_indir, file_name)
        appended_data = []
        for pilote in frames:
            for f in pilote:
                trials = "\\".join(f.split('\\')[0:-1])
                traitements = glob.glob((trials + '\\traitement_*.csv'))
                traits = pd.read_csv(traitements[0])
                time = traits['Time'][len(traits) - 2]
                frames = pd.read_csv(f)
                coups_de_pedal0 = frames["TpsReaction"][0] - frames["Bip"][0]
                coups_de_pedal1 = frames['CoupsDePedal'][0] - frames["Bip"][0]
                coups_de_pedal2 = frames['CoupsDePedal.1'][0] - frames["Bip"][0]
                coups_de_pedal3 = frames['CoupsDePedal.2'][0] - frames["Bip"][0]
                frame = frames[['TailleRider', 'longueurManivelle']]

                if 'Braquet' in frames.columns:
                    frame['Braquet'] = frames['Braquet']
                if 'MasseRider' in frames.columns:
                    frame['MasseRider'] = frames['MasseRider']
                if 'MasseBike' in frames.columns:
                    frame['MasseBike'] = frames['MasseBike']
                frame['TimeEnd'] = time
                partie_coups_de_pedal1 = traits[int(coups_de_pedal0
                                                    ):int(coups_de_pedal1)]
                frame['moyennePuissance1'] = partie_coups_de_pedal1[
                    'Puissance'].mean()

                partie_coups_de_pedal1 = traits[int(coups_de_pedal1
                                                    ):int(coups_de_pedal2)]
                frame['moyennePuissance2'] = partie_coups_de_pedal1[
                    'Puissance'].mean()

                partie_coups_de_pedal1 = traits[int(coups_de_pedal2
                                                    ):int(coups_de_pedal3)]
                frame['moyennePuissance3'] = partie_coups_de_pedal1[
                    'Puissance'].mean()

                partie_coups_de_pedal1 = traits[int(coups_de_pedal3):]
                frame['moyennePuissance4'] = partie_coups_de_pedal1[
                    'Puissance'].mean()

                frame['ThetaManivelleDepart'] = frames['ThetaManivelleDepart'][
                    0]
                frame['DistanceRecul'] = frames['DistanceRecul'][0]
                frame['AlphaGaitDmin'] = frames['AlphaGaitDmin'][0]
                frame['TpsReaction'] = traits['Time'][
                    int(frames['TpsReaction'][0]) - int(frames['Bip'][0])]
                frame['DEpauleMin'] = frames['DEpauleMin'][0]
                frame['DAlignementMin'] = frames['DAlignementMin'][0]
                frame['Dmin'] = traits['Time'][int(frames['Dmin'][0]) -
                                               int(frames['Bip'][0])]
                appended_data.append(frame.iloc[0:1])

        appended_data = pd.concat(appended_data, axis=0)
        current_directory = os.path.dirname(os.path.realpath(__file__))
        print(current_directory)
        appended_data.to_csv(
            "{}\\AllframesConcatenated.csv".format(current_directory), index=0)