In [136]:
import pandas as pd
import matplotlib as plt
%matplotlib inline
import seaborn as sns
import numpy as np
In [137]:
files_list = pd.DataFrame({'file_name': 
['0_2019_11_21-03_51_01_rychlost_pazmany_JA.txt',
'1_2019_11_21-06_18_54_rychlost_pazmany_MARTIN_CAKL.txt',
'2_2019_11_21-06_33_24_rychlost_pazmany_JIRKA.txt',
'3_2019_11_21-07_29_48_rychlost_pazmany_BASKA.txt',
'4_2019_11_21-07_45_29_rychlost_pazmany_MICHAL.txt',
'5_2019_11_21-08_00_40_rychlost_pazmany_J1.txt',
'6_2019_11_21-08_43_37_rychlost_pazmany_J2.txt',
'7_2019_11_21-09_00_09_rychlost_pazmany_J3.txt',
'8_2019_11_21-09_25_26_rychlost_pazmany_J4.txt',
'9_2019_11_21-09_54_21_rychlost_pazmany_J5.txt',
'10_2019_11_21-09_54_21_rychlost_pazmany_J6.txt',
'11_2019_11_21-10_49_54_rychlost_pazmanyJ_7.txt',
'12_2019_11_21-11_04_22_rychlost_pazmany_J8.txt',
'13_2019_11_21-11_19_04_rychlost_pazmany_J9.txt',
'14_2019_11_21-11_34_26_rychlost_pazmany_J10.txt',
'15_2019_11_21-12_18_55_rychlost_pazmany_AJ11.txt',
'16_2019_11_21-11_57_56_rychlost_pazmany_TJ12.txt']})
In [3]:
df_avg = pd.DataFrame()
count = 0

for sets in range(16,0,-1):
    
    ds = pd.read_csv(str(files_list.iloc[sets, 0]), sep=' ', header=None)

    print('load {} file {}'.format(set, files_list.iloc[sets, 0]))
    
    df = ds.iloc[:, [0,1,2,3,4,8]].copy()
    df.columns=['id', 'time', 'x', 'z', 'y', 'velocity']
    df['y'] = -df['y']
    df['velocity'] = df['velocity'] * 3.6

    df['distance'] = 0
    for i in range (len(df)-1):
        df.loc[i, 'distance'] = np.sqrt((df['x'][i]-df['x'][i+1])**2
                                        +(df['y'][i]-df['y'][i+1])**2
                                        +(df['z'][i]-df['z'][i+1])**2)
    
    print('distancexyz {}'.format(sets))
    
    df['distance_check'] = False
    distance = 0
    df['distance_total'] = 0
    j=0
    for i in range(len(df)):
        if df.loc[j:i, 'distance'].sum() > 100:
            df.loc[i, 'distance_check'] = True
            distance = distance + 100
            df.loc[i, 'distance_total'] =  distance
            j = i

    df = df[df['distance_check']].reset_index()

    print('distance {}'.format(sets))
    
    df['zone'] = 0
    df['zone_index'] = 0
    zone_index1 = 0
    zone_index2 = 0
    zone_index3 = 0
    zone_index4 = 0
    for i in range(len(df)-1):
        if df['x'][i] > 13306.155 and df['x'][i] < 13844.208 and df['y'][i] > 1636.532 and df['y'][i] < 5375.833:
            df.loc[i, 'zone'] = 1
            if df.loc[i, 'distance_check']:
                zone_index1 = zone_index1 + 1
                df.loc[i, 'zone_index'] = zone_index1
        elif df['x'][i] > 9713.305 and df['x'][i] < 13452.605 and df['y'][i] > 5232.253 and df['y'][i] < 5770.306:
            df.loc[i, 'zone'] = 2
            if df.loc[i, 'distance_check']:
                zone_index2 = zone_index2 + 1
                df.loc[i, 'zone_index'] = zone_index2
        elif df['x'][i] > 9318.832 and df['x'][i] < 9856.885 and df['y'][i] > 1636.532 and df['y'][i] < 5371.468:
            df.loc[i, 'zone'] = 3
            if df.loc[i, 'distance_check']:
                zone_index3 = zone_index3 + 1
                df.loc[i, 'zone_index'] = zone_index3
        elif df['x'][i] > 9717.851 and df['x'][i] < 13457.151 and df['y'][i] > 1236.984 and df['y'][i] < 1775.037:
            df.loc[i, 'zone'] = 4
            if df.loc[i, 'distance_check']:
                zone_index4 = zone_index4 + 1
                df.loc[i, 'zone_index'] = zone_index4
    
    df['distance_zone']=0
    df['x_zone']=0
    df['y_zone']=0
    
    j=0
    for i in range(len(df)-2):
        if (df['zone'][i]!=df['zone'][i+1]) and (df['zone'][i+1]!=0):
            j = i
        df.loc[i, 'distance_zone']=df['distance_total'][i]-df['distance_total'][j] 
        df.loc[i, 'x_zone']=df['x'][i]-df['x'][j]
        df.loc[i, 'y_zone']=df['y'][i]-df['y'][j]
    
    df.to_csv('calculated_{}'.format(sets))
        
    df_avg1 = df[(df['zone_index']!=0)&(df['zone']!=0)]
    df_avg = pd.concat([df_avg, df_avg1]).groupby(['zone','zone_index']).sum()
    df_avg.drop(['index', 'id'], axis=1, inplace=True)
    df_avg.reset_index(inplace=True)
    
    count += 1
    
    print(count)
    
for i in range(2,13):
    df_avg.iloc[:, i] = df_avg.iloc[:, i] / count
load <class 'set'> file 16_2019_11_21-11_57_56_rychlost_pazmany_TJ12.txt
distancexyz 16
distance 16
1
load <class 'set'> file 15_2019_11_21-12_18_55_rychlost_pazmany_AJ11.txt
distancexyz 15
distance 15
2
load <class 'set'> file 14_2019_11_21-11_34_26_rychlost_pazmany_J10.txt
distancexyz 14
distance 14
3
load <class 'set'> file 13_2019_11_21-11_19_04_rychlost_pazmany_J9.txt
distancexyz 13
distance 13
4
load <class 'set'> file 12_2019_11_21-11_04_22_rychlost_pazmany_J8.txt
distancexyz 12
distance 12
5
load <class 'set'> file 11_2019_11_21-10_49_54_rychlost_pazmanyJ_7.txt
distancexyz 11
distance 11
6
load <class 'set'> file 10_2019_11_21-09_54_21_rychlost_pazmany_J6.txt
distancexyz 10
distance 10
7
load <class 'set'> file 9_2019_11_21-09_54_21_rychlost_pazmany_J5.txt
distancexyz 9
distance 9
8
load <class 'set'> file 8_2019_11_21-09_25_26_rychlost_pazmany_J4.txt
distancexyz 8
distance 8
9
load <class 'set'> file 7_2019_11_21-09_00_09_rychlost_pazmany_J3.txt
distancexyz 7
distance 7
10
load <class 'set'> file 6_2019_11_21-08_43_37_rychlost_pazmany_J2.txt
distancexyz 6
distance 6
11
load <class 'set'> file 5_2019_11_21-08_00_40_rychlost_pazmany_J1.txt
distancexyz 5
distance 5
12
load <class 'set'> file 4_2019_11_21-07_45_29_rychlost_pazmany_MICHAL.txt
distancexyz 4
distance 4
13
load <class 'set'> file 3_2019_11_21-07_29_48_rychlost_pazmany_BASKA.txt
distancexyz 3
distance 3
14
load <class 'set'> file 2_2019_11_21-06_33_24_rychlost_pazmany_JIRKA.txt
distancexyz 2
distance 2
15
load <class 'set'> file 1_2019_11_21-06_18_54_rychlost_pazmany_MARTIN_CAKL.txt
distancexyz 1
distance 1
16
In [334]:
df_avg
Out[334]:
zone zone_index time x z y velocity distance distance_check distance_total distance_zone x_zone y_zone
0 1 1 113005.0 13729.214844 51.913621 1686.481796 92.777448 0.206130 1.0000 400.00 100.00 -0.043945 99.904366
1 1 2 116941.5 13729.080811 52.128616 1786.362785 94.081689 0.209009 1.0000 500.00 200.00 -0.177979 199.785355
2 1 3 120772.0 13729.367371 52.335068 1886.240616 98.510639 0.218837 1.0000 600.00 300.00 0.108581 299.663185
3 1 4 124582.0 13727.074890 52.560021 1986.030853 97.437790 0.216516 1.0000 700.00 400.00 -2.183899 399.453423
4 1 5 128428.5 13698.444336 52.760395 2081.028702 98.606047 0.219163 1.0000 800.00 500.00 -30.814453 494.451271
... ... ... ... ... ... ... ... ... ... ... ... ... ...
154 4 35 751003.0 12203.193421 50.155408 1216.384850 73.303545 0.163033 0.9375 15937.50 3281.25 3148.946472 -58.879677
155 4 36 757253.5 12296.820496 49.795256 1216.478081 73.781775 0.174240 0.9375 16031.25 3375.00 3242.573547 -58.786446
156 0 0 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.0000 0.00 0.00 0.000000 0.000000
157 0 0 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.0000 0.00 0.00 0.000000 0.000000
158 0 0 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.0000 0.00 0.00 0.000000 0.000000

159 rows × 13 columns

CSV load

In [236]:
df_avg1 = pd.DataFrame()
df_avg3 = pd.DataFrame()

for i in range(1,17):
    df_avg3 = pd.read_csv('calculated_{}'.format(i))
    
    df_avg2 = df_avg3[(df_avg3['zone_index']!=0)&(df_avg3['zone']!=0)]
    df_avg1 = pd.concat([df_avg1, df_avg2]).groupby(['zone','zone_index']).sum()
    df_avg1.drop(['index', 'id', 'Unnamed: 0'], axis=1, inplace=True)
    df_avg1.reset_index(inplace=True)

for i in range(2,13):
    df_avg1.iloc[:, i] = df_avg1.iloc[:, i]/16

df_avg = df_avg1

Velocity per 100m

In [408]:
sns.set(rc={'figure.figsize':(15,4)})
g = sns.scatterplot(x='y_zone', y='x_zone', data=df_avg[(df_avg['zone']==1)], hue='velocity')
g.set(xlim=(None, None), ylim=(-1000, 1000), xlabel='Súradnice x [m]', ylabel='Súradnice y [m]', title='Priebeh rýchlosti na úseku č. 1')
g.legend(title='Rychlost [km/h]', bbox_to_anchor=(1.01, 1), loc=2)
g.invert_yaxis()
In [409]:
sns.set(rc={'figure.figsize':(15,4)})
g = sns.scatterplot(x='x_zone', y='y_zone', data=df_avg[(df_avg['zone']==2)], hue='velocity')
g.set(xlim=(None, None), ylim=(-1000, 1000), xlabel='Súradnice x [m]', ylabel='Súradnice y [m]', title='Priebeh rýchlosti na úseku č. 2')
g.legend(title='Rychlost [km/h]', bbox_to_anchor=(1.01, 1), loc=2)
g.invert_yaxis()
g.invert_xaxis()
In [410]:
sns.set(rc={'figure.figsize':(15,4)})
g = sns.scatterplot(x='y_zone', y='x_zone', data=df_avg[(df_avg['zone']==3)], hue='velocity')
g.set(xlim=(None, None), ylim=(-1000, 1000), xlabel='Súradnice x [m]', ylabel='Súradnice y [m]', title='Priebeh rýchlosti na úseku č. 3')
g.legend(title='Rychlost [km/h]', bbox_to_anchor=(1.01, 1), loc=2)
g.invert_xaxis()
In [411]:
sns.set(rc={'figure.figsize':(15,4)})
g = sns.scatterplot(x='x_zone', y='y_zone', data=df_avg[(df_avg['zone']==4)], hue='velocity')
g.set(xlim=(None, None), ylim=(-1000, 1000), xlabel='Súradnice x [m]', ylabel='Súradnice y [m]', title='Priebeh rýchlosti na úseku č. 4')
g.legend(title='Rychlost [km/h]', bbox_to_anchor=(1.01, 1), loc=2)
Out[411]:
<matplotlib.legend.Legend at 0x1289b39d0>

Velocity plot

In [398]:
sns.set(rc={'figure.figsize':(15,4)})
g = sns.lineplot(x='distance_zone', y='velocity', data=df_avg1[(df_avg1['zone']==1)][:39])
g.set(xlabel='Prejdená vzdialenosť [m]', ylabel='Rýchlosť [km/h]', title='Priebeh rýchlosti na úseku č. 1')
Out[398]:
[Text(0, 0.5, 'Rýchlosť [km/h]'),
 Text(0.5, 0, 'Prejdená vzdialenosť [m]'),
 Text(0.5, 1.0, 'Priebeh rýchlosti na úseku č. 1')]
In [399]:
sns.set(rc={'figure.figsize':(15,4)})
g = sns.lineplot(x='distance_zone', y='velocity', data=df_avg[df_avg['zone']==2])
g.set(xlabel='Prejdená vzdialenosť [m]', ylabel='Rýchlosť [km/h]', title='Priebeh rýchlosti na úseku č. 2')
Out[399]:
[Text(0, 0.5, 'Rýchlosť [km/h]'),
 Text(0.5, 0, 'Prejdená vzdialenosť [m]'),
 Text(0.5, 1.0, 'Priebeh rýchlosti na úseku č. 2')]
In [400]:
sns.set(rc={'figure.figsize':(15,4)})
g = sns.lineplot(x='distance_zone', y='velocity', data=df_avg[(df_avg['zone']==3)])
g.set(xlabel='Prejdená vzdialenosť [m]', ylabel='Rýchlosť [km/h]', title='Priebeh rýchlosti na úseku č. 3')
Out[400]:
[Text(0, 0.5, 'Rýchlosť [km/h]'),
 Text(0.5, 0, 'Prejdená vzdialenosť [m]'),
 Text(0.5, 1.0, 'Priebeh rýchlosti na úseku č. 3')]
In [401]:
sns.set(rc={'figure.figsize':(15,4)})
g = sns.lineplot(x='distance_zone', y='velocity', data=df_avg[(df_avg['zone']==4)])
g.set(xlabel='Prejdená vzdialenosť [m]', ylabel='Rýchlosť [km/h]', title='Priebeh rýchlosti na úseku č. 4')
Out[401]:
[Text(0, 0.5, 'Rýchlosť [km/h]'),
 Text(0.5, 0, 'Prejdená vzdialenosť [m]'),
 Text(0.5, 1.0, 'Priebeh rýchlosti na úseku č. 4')]
In [461]:
g = sns.lineplot(x='distance_total', y='velocity', data=df_avg[df_avg['zone']!=0], ci=None)
g.set(xlim=(0, 16500), ylim=(0,140))
g.set(xlabel='Prejdená vzdialenosť [m]', ylabel='Rýchlosť [km/h]', title='Priebeh priemernej rýchlosti na úseku na celej trase')
Out[461]:
[Text(0, 0.5, 'Rýchlosť [km/h]'),
 Text(0.5, 0, 'Prejdená vzdialenosť [m]'),
 Text(0.5, 1.0, 'Priebeh priemernej rýchlosti na úseku na celej trase')]

Avg velocity in zones

In [402]:
for i in range(1,5):
    avg_velocity = round(df_avg[df_avg['zone']==i]['velocity'].mean(), 2)
    print("Priemerna rýchlosť v zóně č. {} = {} km/h".format(i, avg_velocity))
Priemerna rýchlosť v zóně č. 1 = 98.07 km/h
Priemerna rýchlosť v zóně č. 2 = 89.13 km/h
Priemerna rýchlosť v zóně č. 3 = 82.78 km/h
Priemerna rýchlosť v zóně č. 4 = 77.73 km/h

Avg velocity in zones

In [403]:
df_all = pd.DataFrame()
i=1
for i in range(1,17):
    no1=pd.read_csv('calculated_{}'.format(i))
    no1['ride'] = 'ride_{}'.format(i)
    df_all = pd.concat([df_all, no1], axis=0)
In [454]:
g = sns.lineplot(x='distance_total', y='velocity', data=df_all, hue='ride', ci=None)
g.set(xlim=(0, 17500), ylim=(50,None))
g.legend(title='Jízda číslo:', bbox_to_anchor=(1.01, 1), loc=2)
g.set(xlabel='Prejdená vzdialenosť [m]', ylabel='Rýchlosť [km/h]', title='Priebeh rýchlosti na úseku na celé trase')
Out[454]:
[Text(0, 0.5, 'Rýchlosť [km/h]'),
 Text(0.5, 0, 'Prejdená vzdialenosť [m]'),
 Text(0.5, 1.0, 'Priebeh rýchlosti na úseku na celé trase')]
In [405]:
g = sns.lineplot(x='distance_zone', y='velocity', data=df_all[df_all['zone']==1], hue='ride', ci=None)
g.set(xlim=(0, 4000), ylim=(50,None))
g.legend(title='Jízda číslo:', bbox_to_anchor=(1.01, 1), loc=2)
g.set(xlabel='Prejdená vzdialenosť [m]', ylabel='Rýchlosť [km/h]', title='Priebeh rýchlosti na úseku č v zóně č. 1')
Out[405]:
[Text(0, 0.5, 'Rýchlosť [km/h]'),
 Text(0.5, 0, 'Prejdená vzdialenosť [m]'),
 Text(0.5, 1.0, 'Priebeh rýchlosti na úseku č v zóně č. 1')]
In [406]:
g = sns.lineplot(x='distance_zone', y='velocity', data=df_all[df_all['zone']==2], hue='ride', ci=None)
g.set(xlim=(0, 4000), ylim=(50,None))
g.legend(title='Jízda číslo:', bbox_to_anchor=(1.01, 1), loc=2)
g.set(xlabel='Prejdená vzdialenosť [m]', ylabel='Rýchlosť [km/h]', title='Priebeh rýchlosti na úseku č v zóně č. 2')
Out[406]:
[Text(0, 0.5, 'Rýchlosť [km/h]'),
 Text(0.5, 0, 'Prejdená vzdialenosť [m]'),
 Text(0.5, 1.0, 'Priebeh rýchlosti na úseku č v zóně č. 2')]
In [388]:
g = sns.lineplot(x='distance_zone', y='velocity', data=df_all[df_all['zone']==3], hue='ride', ci=None)
g.set(xlim=(0, 4000), ylim=(50,None))
g.legend(title='Jízda číslo:', bbox_to_anchor=(1.01, 1), loc=2)
g.set(xlabel='Prejdená vzdialenosť [m]', ylabel='Rýchlosť [km/h]', title='Priebeh rýchlosti na úseku č v zóně č. 3')
Out[388]:
[Text(0, 0.5, 'Rýchlosť [km/h]'),
 Text(0.5, 0, 'Prejdená vzdialenosť [m]'),
 Text(0.5, 1.0, 'Průběh rýchlosti v zóně č. 3')]
In [407]:
g = sns.lineplot(x='distance_zone', y='velocity', data=df_all[df_all['zone']==4], hue='ride', ci=None)
g.set(xlim=(0, 4000), ylim=(50,None))
g.legend(title='Jízda číslo:', bbox_to_anchor=(1.01, 1), loc=2)
g.set(xlabel='Prejdená vzdialenosť [m]', ylabel='Rýchlosť [km/h]', title='Priebeh rýchlosti na úseku č v zóně č. 4')
Out[407]:
[Text(0, 0.5, 'Rýchlosť [km/h]'),
 Text(0.5, 0, 'Prejdená vzdialenosť [m]'),
 Text(0.5, 1.0, 'Priebeh rýchlosti na úseku č v zóně č. 4')]
In [ ]: