Skip to content

Instantly share code, notes, and snippets.

@mcohen01
Created February 7, 2019 22:13
Show Gist options
  • Save mcohen01/fd9c7405474274c7abbd5b87efcdb48b to your computer and use it in GitHub Desktop.
Save mcohen01/fd9c7405474274c7abbd5b87efcdb48b to your computer and use it in GitHub Desktop.
riders = {
'maverick': '''2:01.521 2:00.543 2:08.984 7:53.953 2:00.500 2:00.419 2:00.353 2:08.864 5:51.848 2:00.120 2:06.770 2:08.161 9:52.259 2:03.576 2:00.641 2:06.417 2:00.254 2:00.252 2:00.217 2:00.166 2:00.038 2:13.137 17:08.751 2:01.849 2:00.964 2:06.733 9:42.350 2:01.038 2:00.784 2:01.367 2:07.549 24:39.555 1:59.863 1:59.597 2:05.496 2:00.062 1:59.883 1:59.960 1:59.817 1:59.828 1:59.677 2:15.620 3:44:30.822 2:01.945 2:01.636 2:06.572 9:19.397 2:01.612 2:01.347 2:06.824 22:17.000 2:06.718 10:45.492 2:01.019 2:00.874 2:13.634 10:16.528 2:00.417 2:03.570 5:31.109 1:58.897 2:19.867''',
'rins': '''2:02.779 2:00.252 2:00.333 2:00.085 2:16.415 11:01.027 2:00.839 2:00.884 2:00.368 2:15.964 15:53.040 2:02.111 1:59.978 2:00.418 2:20.209 25:23.315 2:00.811 2:00.327 2:00.160 2:21.776 15:53.420 2:01.575 2:00.384 2:00.848 2:20.687 30:34.733 2:01.857 2:00.412 2:00.544 2:18.916 12:19.015 2:01.598 2:01.679 2:10.196 3:08:39.528 2:03.096 2:00.363 2:00.273 2:00.346 2:10.362 11:24.587 2:00.415 2:00.212 2:00.481 2:17.159 26:35.638 2:00.712 2:00.455 2:19.194 2:07.391 17:43.265 2:01.352 2:00.381 2:14.632 7:16.490 1:59.821 1:59.424 1:59.572 1:59.847 2:22.096''',
'jackass': '''2:02.738 2:01.443 2:01.234 2:13.321 17:44.963 2:00.481 2:00.023 2:14.680 2:00.054 2:14.842 22:31.453 2:00.752 2:00.716 2:00.629 2:00.778 2:18.043 18:15.403 2:00.820 2:00.323 2:00.989 2:22.230 33:24.344 2:03.293 2:01.291 2:03.547 3:54:51.572 2:02.724 2:01.842 2:14.019 18:20.417 2:01.763 2:01.631 2:14.298 12:22.840 2:02.438 2:01.820 2:16.084 14:23.418 2:00.070 2:00.249 1:59.998 2:16.020 10:23.697 2:02.854 2:07.589 4:11.194 1:59.517 3:24.902''',
'dovi': '''2:06.367 2:04.231 2:01.952 2:00.468 2:00.055 2:18.972 12:26.838 2:04.074 2:14.249 2:11.859 2:01.321 2:00.994 2:00.404 2:15.917 10:44.673 2:01.417 1:59.837 1:59.562 2:19.820 19:43.201 2:01.904 2:01.020 2:00.150 2:06.894 46:26.631 2:03.057 2:01.589 2:01.173 2:00.401 2:18.185 2:29:15.257 2:01.100 2:00.444 2:00.670 2:00.614 2:00.537 2:00.774 2:00.637 2:00.891 2:00.886 2:00.276 2:15.407 47:05.964 2:01.602 2:00.976 2:00.664 2:00.745 2:00.753 2:00.479 2:00.604 2:00.555 2:00.508 2:00.592 2:31.794 51:05.836 2:06.178 2:02.998 2:01.892 2:25.581''',
'cal': '''2:03.117 2:01.142 2:04.318 2:00.346 2:11.954 14:47.936 2:02.798 2:00.890 2:13.805 12:10.365 2:02.722 2:00.054 1:59.566 2:09.812 28:10.302 2:08.580 2:58.313 2:01.273 2:00.980 2:01.066 2:00.634 2:21.829 27:56.375 2:01.948 2:08.571 2:01.078 2:22.657 29:08.103 3:05:18.191 2:03.539 2:02.075 2:00.880 2:20.588 20:38.507 2:02.327 2:01.705 2:15.169 21:18.366 2:02.075 2:01.143 2:01.149 2:17.057 17:26.736 2:05.659 2:02.400 2:00.610 2:00.598 2:12.063 7:05.811 2:05.523 2:00.746 3:05.531''',
'rossi': '''2:02.263 2:01.448 2:01.052 2:10.507 7:20.467 1:59.978 1:59.625 2:15.526 20:16.217 2:00.675 2:00.245 2:00.228 2:21.067 39:51.576 2:01.123 2:01.049 2:12.598 9:59.283 2:00.819 2:00.974 2:22.786 11:37.053 2:00.635 2:00.540 2:26.199 3:40:22.312 2:01.927 2:01.534 2:01.122 2:11.411 7:45.707 2:01.952 2:01.443 2:01.327 2:10.082 16:06.574 2:03.559 2:17.598 9:55.684 2:00.743 2:00.137 2:18.889 17:01.853 2:00.474 2:00.606 2:17.821 5:19.650 2:11.467 7:30.969 2:09.436''',
'tito': '''2:05.427 2:03.035 2:01.903 2:01.411 2:01.417 2:01.229 2:01.010 2:00.674 2:11.938 8:02.164 2:00.480 1:59.992 1:59.930 2:00.179 2:15.778 2:05.057 2:00.446 2:00.072 2:00.043 2:18.171 10:40.832 2:01.018 2:35.311 10:03.080 2:01.368 2:00.678 2:00.282 1:59.853 2:24.422 11:24.592 2:01.417 2:01.751 2:01.562 2:06.771 17:04.121 2:03.015 2:02.229 2:15.567 12:38.557 2:02.847 2:02.367 2:05.484 2:01.910 2:20.754 4:01:39.927 2:02.271 2:01.434 2:01.038 2:00.653 2:00.672 2:06.178 7:37.669 2:01.029 2:00.707 2:00.336 2:00.415 2:00.042 2:00.104 2:15.533 11:50.391 2:01.204 2:00.942 2:18.760 7:28.733 2:01.253 2:01.054 2:00.580 2:06.215 5:07.643 2:00.016 2:00.023 1:59.762 1:59.664 2:22.151''',
'marquez': '''2:02.276 2:05.126 2:00.413 1:59.790 2:00.196 2:11.628 34:57.722 2:00.771 2:00.732 2:00.293 2:00.211 2:13.417 37:50.877 2:03.605 2:01.910 2:00.878 2:00.900 2:20.214 1:01:03.081 2:02.533 2:00.845 2:01.530 2:00.799 2:14.660 25:26.089 2:02.235 2:00.750 2:00.598 2:00.568 2:14.978 19:23.912 2:02.411 2:01.242 2:00.915 2:00.685 2:15.803''',
'petrux': '''2:03.052 2:02.594 2:02.119 2:00.644 2:01.437 2:00.598 2:16.778 13:25.657 2:05.744 1:59.845 2:05.288 33:48.980 2:00.048 2:00.646 2:00.388 2:00.724 2:14.756 2:00.370 2:17.614 36:31.370 2:00.725 2:00.846 2:01.061 2:00.751 2:01.002 2:20.112 15:54.636 2:01.940 2:01.056 2:01.285 2:28.696 2:16:15.611 2:01.107 2:00.468 2:00.622 2:00.586 2:00.578 2:00.662 2:00.709 2:00.926 2:00.793 2:00.477 2:15.348 47:05.050 2:01.387 2:00.966 2:00.892 2:00.826 2:00.702 2:00.410 2:00.522 2:00.766 2:00.403 2:00.437 2:30.009 52:54.946 2:02.334 2:00.984 2:01.008 2:19.885 12:23.603 2:00.947 2:00.820 2:20.561'''
}
import re
import matplotlib.pyplot as plt
import warnings
import seaborn as sns
sns.set()
warnings.filterwarnings('ignore')
lap_time_pattern = "[1-2]:[0-9]{2}\.[0-9]{3}"
def parse_lap_time(x):
secs = int(x[0]) * 60
secs += int(x[2:4])
secs = str(secs) + x[4:]
return float(secs)
def parse_laps(rider):
xs = []
for x in [x.split(' ') for x in riders[rider].split('\n')]:
xs.extend(x)
return xs
lap_minimum = 117
lap_maximum = 126
rider_times = {}
for rider in riders.keys():
rider_times[rider] = []
for lap in parse_laps(rider):
match = re.match(lap_time_pattern, lap)
if match:
lap_time = parse_lap_time(lap)
if lap_time > lap_minimum and lap_time < lap_maximum:
rider_times[rider].append(lap_time)
fig, ax = plt.subplots(figsize=(13, 9))
cnt = 0
max_riders = 9
max_laps_per_rider = 45
for rider in rider_times.keys():
if cnt == max_riders: break;
times = sorted([lap for lap in rider_times[rider]])[:max_laps_per_rider]
plt.plot(times, label=rider)
cnt += 1
ax.set_xlabel('laps')
ax.set_ylabel('lap time')
_ = plt.legend()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment