```
In [ ]:
```# Speed (m/s) and acceleration (m/s^2) categories
accel_desc = ['nhigh','nmedium', 'nlow','around_zero', 'low', 'medium', 'high']
accel_syms = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
accel_bins = [-100, -1.60, -1.17,-0.57, 0.57, 1.17, 1.60, 100]
speed_desc = ['low', 'medium', 'high', 'very_high']
speed_syms = ['p', 'q', 'r', 's']
speed_bins = [-1.0, 2, 3.7, 6, 20]

```
In [ ]:
```P1 = "\'(<:s:>)%(1000,10000)\'"

```
In [ ]:
```P2 = "\'(<:g);(<:(r||s):>)%(1000,10000)\'"

```
In [ ]:
```P3 = "\'(<:(f||g));((<:s:>)%(1000,2000))\'"

```
In [ ]:
```%matplotlib inline
# In order to process data
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# In order to call montre
import subprocess, shlex

```
In [ ]:
```# Sentio constants
FRAME_PER_SECOND = 10
# Read Sentio data
df = pd.read_csv('data/match.csv', index_col=["MINUTE", "SECOND", 'TIMESTAMP'], header=0,
names=["TIMESTAMP", "HALF", "MINUTE", "SECOND", "TEAM_ID",
"JERSEY_NUMBER", "X_POS", "Y_POS", "DISTANCE", "SPEED"])

```
In [ ]:
```# Usual Suspect
PLAYER_TEAM = 1 # Galatasaray
PLAYER_NUMBER = 29 # Olcan Adin
HALF = 1
# Select the data for the specific player
data = df[(df['TEAM_ID'] == PLAYER_TEAM) &
(df['JERSEY_NUMBER'] == PLAYER_NUMBER) &
(df['HALF'] == HALF)].copy(deep=True)

```
In [ ]:
```data['TIME'] = pd.Series(range(len(data)), index=data.index)
data = data.set_index(['TIME'])
data = data.drop(['HALF', 'TEAM_ID', "JERSEY_NUMBER", "DISTANCE", "SPEED"], axis=1).copy(deep=True)
data.loc[data['X_POS'] < 0, 'X_POS'] = np.nan; data['X_POS'] = data['X_POS'].interpolate()
data.loc[data['Y_POS'] < 0, 'Y_POS'] = np.nan; data['Y_POS'] = data['Y_POS'].interpolate()

If you would like to see the entire movement of the player, it's here:

```
In [ ]:
```fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
# Draw a simple soccer pitch (105x68m)
ax.set_ylim(0,68)
ax.set_xlim(0,105)
plt.plot([52.5,52.5], [0,68], color='black', linewidth=2)
plt.plot([0,16.5,16.5,0], [54,54, 14,14], color='black', linewidth=2)
plt.plot([105,105-16.5,105-16.5,105], [54,54,14,14], color='black', linewidth=2)
circle1=plt.Circle((52.5,34),10, color='black', linewidth=2, fill=False)
ax.add_artist(circle1)
plt.plot(data['X_POS'],data['Y_POS'])

```
In [ ]:
```data['DISPLACEMENT'] = np.sqrt((data['X_POS'].diff())**2 + (data['Y_POS'].diff())**2)
data['DISPLACEMENT'][0] = 0
data['SPEED'] = data['DISPLACEMENT'] * FRAME_PER_SECOND
data['ACCEL'] = data['SPEED'].diff() * FRAME_PER_SECOND
data['ACCEL'][0] = 0
data['ACCEL'][1] = 0
# In case more smoothing is needed.
# data['SPEED'][2:] = data['SPEED'].rolling(center=False,window=3).mean()[2:]
# data['ACCEL'][2:] = data['ACCEL'].rolling(center=False,window=3).mean()[2:]

```
In [ ]:
```data['SPEEDSYM'] = pd.cut(data['SPEED'], bins=speed_bins, labels=speed_syms)
data['ACCELSYM'] = pd.cut(data['ACCEL'], bins=accel_bins, labels=accel_syms)

Then write symbolic behaviors into a file named as INPUT.txt.

```
In [ ]:
```def collect(x, *ys):
y = [''.join(str(i) for i in e) for e in zip(*ys)]
xp = x[0]
yp = y[0]
for (xi, yi) in zip(x,y):
if yi != yp:
yield (xi-xp,yp)
xp = xi
yp = yi
yield (xi-xp,yp)
with open('INPUT.txt', 'w') as f:
for (xi, yi) in collect(data.index.values, list(data['ACCELSYM'].values), list(data['SPEEDSYM'].values)):
f.write('{0} {1}\n'.format(xi*100, yi))

```
In [ ]:
```command = shlex.split("montre" + " " + "-b" + " " + P1 + " " + "-f" + " " + "INPUT.txt" + " " + "-o" + " " + "OUTPUT.txt")
subprocess.call(command)

```
In [8]:
```%%latex
\begin{equation*}
144800 \leq t \leq 148800\\
144800 \leq t' \leq 148800\\
4000 \leq t' -t \leq 4000
\end{equation*}

```
```

We have shown how to perform timed pattern matching over speed and acceleration signals to find all instances of a pattern (e.g. sprints). Perhaps the most important thing in the process is to come up a good pattern definition. And clearly this is not easy and it requires some domain knowledge at the first hand. But, once you have a pattern, the problem can be solved easily by using Montre and some standard data processing.

Finally special thanks to Hande Alemdar and Serdar Alemdar for sharing their data for this demo.