In [1]:
%matplotlib inline
DEFAULT_FIGSIZE = (16, 12)

import itertools
import sys

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import seaborn as sns
sns.set_style('darkgrid')
import pandas as pd

sys.path.append('..')
from antlia.plotdf import plotjoint

%load_ext autoreload
%autoreload 2

import matplotlib as mpl
mpl.rcParams['figure.figsize'] = DEFAULT_FIGSIZE

In [2]:
braking_df = pd.read_pickle('trial2_braking_ttc.p.gz')

In [26]:
import enum

class BrakingType(enum.Enum):
    Constant = 0
    Increasing = 1
    TwoStage = 2
    
    def __str__(self):
        return self.name
    
    def __float__(self):
        return float(self.value)
    

braking_df['braking type'] = [
    # rider 0
    BrakingType.TwoStage,
    BrakingType.TwoStage,
    BrakingType.TwoStage,
    
    BrakingType.Constant,
    BrakingType.Increasing,
    BrakingType.Constant,
    
    BrakingType.Constant,
    BrakingType.Constant,
    BrakingType.Increasing,
    
    # rider 1
    BrakingType.Constant,
    BrakingType.Constant,
    BrakingType.Constant,
    
    BrakingType.Constant,
    BrakingType.Constant,
    BrakingType.Constant,
    
    BrakingType.Constant,
    BrakingType.Constant,
    BrakingType.Constant,
    
    # rider 2
    BrakingType.Constant,
    BrakingType.Constant,
    BrakingType.Constant,
    
    BrakingType.Constant,
    BrakingType.Constant,
    BrakingType.Constant,
    
    BrakingType.Constant,
    BrakingType.Constant,
    BrakingType.Constant,
    
    # rider 3
    BrakingType.Constant,
    BrakingType.TwoStage,
    BrakingType.Constant,
    
    BrakingType.TwoStage,
    BrakingType.Constant,
    BrakingType.Constant,
    
    BrakingType.Constant,
    BrakingType.Constant,
    BrakingType.TwoStage,
    
    # rider 4
    BrakingType.Constant,
    BrakingType.Increasing,
    BrakingType.Increasing,
    
    BrakingType.Constant,
    BrakingType.TwoStage,
    BrakingType.Increasing,
    
    BrakingType.Increasing,
    BrakingType.Increasing,
    BrakingType.Constant,
    
    # rider 5
    BrakingType.Constant,
    BrakingType.Increasing,
    BrakingType.Constant,
    
    BrakingType.Constant,
    BrakingType.Constant,
    BrakingType.Constant,
    
    BrakingType.Constant,
    BrakingType.Constant,
    
    # rider 6
    BrakingType.Constant,
    BrakingType.Constant,
    BrakingType.Constant,
    
    BrakingType.Increasing,
    BrakingType.Constant,
    BrakingType.Constant,
    
    BrakingType.Constant,
    BrakingType.TwoStage,
    BrakingType.TwoStage,
    
    # rider 7
    BrakingType.Constant,
    BrakingType.Constant,
    BrakingType.Constant,
    
    BrakingType.Constant,
    BrakingType.TwoStage,
    BrakingType.TwoStage,
    
    BrakingType.TwoStage,
    BrakingType.TwoStage,
    BrakingType.Constant,
]

In [27]:
df = braking_df.drop([
    'linregress intercept',
    'braking starttime',
    'braking endtime',
    'window size',
    'lockup ranges'
], axis=1)

cols = df.columns.tolist()
cols = cols[-5:] + cols[:-5]
df = df[cols]
    
with pd.option_context('display.max_rows', None,
                       'display.max_columns', None,
                       'float_format', '{:0.3f}'.format):
    display(df)


rider id trial id distance-to-collision time-to-collision braking type linregress slope linregress r-value linregress p-value linregress stderr starting velocity braking duration braking distance
0 0 0 7.785 1.971 TwoStage -0.886 -0.933 0.000 0.016 3.950 3.776 8.003
1 0 1 8.669 1.743 TwoStage -1.452 -0.910 0.000 0.035 4.973 2.916 8.681
2 0 2 10.068 1.689 TwoStage -1.976 -0.923 0.000 0.044 5.960 2.800 10.211
3 0 6 7.749 1.650 Constant -1.698 -0.901 0.000 0.046 4.697 2.520 7.683
4 0 7 4.164 1.263 Increasing -1.569 -0.890 0.000 0.054 3.297 1.760 3.954
5 0 8 9.867 1.624 Constant -1.990 -0.925 0.000 0.044 6.077 2.736 9.818
6 0 12 11.586 1.892 Constant -1.743 -0.912 0.000 0.040 6.124 3.116 11.717
7 0 13 3.219 0.972 Constant -2.142 -0.884 0.000 0.088 3.311 1.336 3.053
8 0 14 6.933 1.423 Increasing -1.997 -0.916 0.000 0.052 4.872 2.232 6.864
9 1 3 13.000 2.806 Constant -0.816 -0.927 0.000 0.013 4.634 5.137 12.313
10 1 4 7.578 2.327 Constant -0.853 -0.911 0.000 0.019 3.256 3.432 6.063
11 1 5 10.584 1.848 Constant -4.530 -0.585 0.000 0.730 5.728 0.608 2.973
12 1 9 9.985 1.774 Constant -1.758 -0.936 0.000 0.034 5.629 3.080 8.916
13 1 10 5.887 1.765 Constant -1.226 -0.925 0.000 0.029 3.336 2.432 4.752
14 1 11 8.087 1.701 Constant -1.525 -0.924 0.000 0.033 4.753 2.868 7.602
15 1 15 6.077 1.813 Constant -1.228 -0.910 0.000 0.032 3.351 2.488 4.713
16 1 16 8.464 1.884 Constant -1.635 -0.923 0.000 0.037 4.492 2.688 6.729
17 1 17 8.870 1.499 Constant -2.174 -0.921 0.000 0.053 5.917 2.400 7.765
18 2 0 7.307 1.485 Constant -2.970 -0.886 0.000 0.125 4.920 1.720 4.636
19 2 1 4.505 1.403 Constant -2.114 -0.890 0.000 0.086 3.211 1.296 2.521
20 2 2 7.012 1.289 Constant -6.986 -0.840 0.000 0.511 5.440 0.940 2.416
21 2 6 6.669 1.315 Constant -1.972 -0.889 0.000 0.059 5.073 2.368 5.141
22 2 7 3.325 1.085 Constant -2.126 -0.926 0.000 0.066 3.064 1.384 2.490
23 2 8 4.680 1.144 Constant -3.085 -0.928 0.000 0.098 4.090 1.304 3.101
24 2 12 3.568 0.949 Constant -3.162 -0.850 0.000 0.158 3.760 1.248 2.945
25 2 13 4.543 1.040 Constant -2.814 -0.910 0.000 0.088 4.369 1.720 3.942
26 2 14 7.666 1.379 Constant -2.400 -0.927 0.000 0.057 5.561 2.336 6.509
27 3 3 14.169 2.617 Constant -0.967 -0.903 0.000 0.019 5.413 4.657 14.629
28 3 4 7.058 2.249 TwoStage -0.733 -0.867 0.000 0.021 3.138 3.328 6.712
29 3 5 12.575 2.797 Constant -0.801 -0.917 0.000 0.014 4.496 4.897 12.203
30 3 9 6.805 2.191 TwoStage -0.791 -0.902 0.000 0.018 3.106 3.552 7.025
31 3 10 10.823 2.419 Constant -1.029 -0.917 0.000 0.020 4.474 3.985 10.849
32 3 11 18.186 3.127 Constant -0.862 -0.904 0.000 0.015 5.816 5.697 18.454
33 3 15 12.555 2.371 Constant -0.947 -0.869 0.000 0.021 5.295 5.273 15.160
34 3 16 7.569 1.675 Constant -1.006 -0.695 0.000 0.050 4.520 3.544 9.597
35 3 17 21.048 3.415 TwoStage -0.786 -0.791 0.000 0.022 6.163 6.385 26.204
36 4 0 9.887 1.605 Constant -2.249 -0.919 0.000 0.052 6.159 2.800 10.281
37 4 1 2.568 0.540 Increasing -4.055 -0.766 0.000 0.290 4.752 1.112 3.302
38 4 2 5.077 0.823 Increasing -3.260 -0.800 0.000 0.166 6.170 1.744 7.300
39 4 6 3.223 0.676 Constant -3.530 -0.785 0.000 0.202 4.764 1.536 4.374
40 4 7 5.541 0.997 TwoStage -2.787 -0.838 0.000 0.118 5.555 1.896 6.426
41 4 8 10.272 1.773 Increasing -2.447 -0.894 0.000 0.068 5.795 2.576 10.005
42 4 12 4.618 0.753 Increasing -3.405 -0.802 0.000 0.168 6.134 1.832 6.423
43 4 13 3.783 1.111 Increasing -1.747 -0.896 0.000 0.061 3.405 1.632 3.561
44 4 14 9.584 1.530 Constant -2.665 -0.924 0.000 0.062 6.265 2.560 9.543
45 5 3 3.720 0.946 Constant -2.040 -0.895 0.000 0.068 3.932 1.820 4.242
46 5 4 7.552 1.679 Increasing -1.497 -0.904 0.000 0.038 4.498 2.780 7.710
47 5 5 11.115 1.862 Constant -1.797 -0.926 0.000 0.037 5.969 3.192 10.902
48 5 9 9.710 1.971 Constant -1.233 -0.935 0.000 0.021 4.927 3.904 10.095
49 5 10 5.914 1.584 Constant -1.298 -0.894 0.000 0.036 3.733 2.588 5.646
50 5 11 13.839 2.306 Constant -1.418 -0.872 0.000 0.037 6.002 3.732 13.968
51 5 15 13.555 2.214 Constant -1.327 -0.899 0.000 0.027 6.124 4.481 14.219
52 5 17 8.429 1.773 Constant -1.561 -0.900 0.000 0.038 4.755 3.200 8.695
53 6 0 4.955 1.852 Constant -0.889 -0.885 0.000 0.026 2.675 2.616 4.635
54 6 1 12.067 2.735 Constant -0.932 -0.921 0.000 0.017 4.412 4.313 11.187
55 6 2 10.693 1.815 Constant -2.016 -0.933 0.000 0.041 5.891 2.824 9.189
56 6 6 9.086 2.166 Increasing -1.181 -0.927 0.000 0.023 4.195 3.432 7.991
57 6 7 5.022 1.551 Constant -1.258 -0.933 0.000 0.028 3.239 2.488 4.282
58 6 8 12.391 2.299 Constant -1.716 -0.928 0.000 0.034 5.390 3.328 10.456
59 6 12 12.481 2.136 Constant -1.782 -0.939 0.000 0.033 5.843 3.220 10.474
60 6 13 7.392 2.276 TwoStage -0.901 -0.905 0.000 0.022 3.248 2.940 6.041
61 6 14 11.089 2.373 TwoStage -1.244 -0.898 0.000 0.031 4.673 3.200 9.438
62 7 3 18.739 4.475 Constant -0.561 -0.907 0.000 0.009 4.188 6.193 16.954
63 7 4 10.709 3.486 Constant -0.496 -0.740 0.000 0.024 3.072 2.944 6.820
64 7 5 18.492 3.458 Constant -0.987 -0.942 0.000 0.014 5.347 5.145 15.303
65 7 9 17.694 3.580 Constant -0.805 -0.928 0.000 0.012 4.943 5.577 15.576
66 7 10 7.173 2.326 TwoStage -0.671 -0.901 0.000 0.016 3.084 3.400 6.332
67 7 11 17.402 3.788 TwoStage -0.573 -0.907 0.000 0.010 4.593 5.957 14.885
68 7 15 7.581 2.428 TwoStage -0.728 -0.910 0.000 0.016 3.122 3.396 6.523
69 7 16 17.027 3.847 TwoStage -0.599 -0.791 0.000 0.021 4.426 4.061 12.737
70 7 17 21.493 5.244 Constant -0.619 -0.876 0.000 0.013 4.098 5.533 14.766

In [32]:
for t in BrakingType:
    print(t, t.value)


Constant 0
Increasing 1
TwoStage 2

In [43]:
from antlia.plotdf import plotjoint

colors = sns.color_palette('tab10', 10)

plt.close('all')

fig, ax = plt.subplots(figsize=(16, 12))
sns.swarmplot(x='braking type', y='starting velocity',
              hue='rider id',
              data=df, ax = ax)

plt.show()



In [41]:
print('BrakingType\tcount')
for t in BrakingType:
    n = df[df['braking type'] == t].count().values[0]
    print('{}\t{}'.format(t, n))


BrakingType	count
Constant	49
Increasing	9
TwoStage	13