Commit 7e365e57 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

change the metric notebook, small changes to the postvis such that other...

change the metric notebook, small changes to the postvis such that other simTimeSteps not equal to 0.4 will be used if they are contained in the postvis.trajectories file.
parent ad2d8105
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
# expand the cell of the notebook
import json
import numpy as np
import pandas as pd
import math
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
from IPython.core.display import display, HTML
display(HTML('<style>.container { width:100% !important; }</style>'))
```
%% Cell type:markdown id: tags:
# Methods to convert Vadere trajectories into a DataFrame
%% Cell type:code id: tags:
``` python
def fs_append(pedestrianId, fs, llist):
llist.append([pedestrianId, fs['start']['x'], fs['start']['y'], fs['startTime'], fs['end']['x'], fs['end']['y'], fs['endTime']])
def trajectory_append(pedestrianId, trajectory, llist):
for fs in trajectory:
fs_append(pedestrianId, fs, llist)
def trajectories_to_dataframe(trajectories):
llist = []
for pedId in trajectories:
trajectory_append(pedId, trajectories[pedId], llist)
dataframe = pd.DataFrame(llist, columns=['pedestrianId','startX','startY','startTime','endX','endY','endTime'])
return dataframe
file = "./data/trajectories_distance.txt"
real_file = "./data/KO/ko-240-120-240/ko-240-120-240_combined_MB.txt"
f = open(file, "r")
header = f.readline();
trajectories = dict({});
for row in f:
s = row.split(" ");
pedId = int(s[0]);
footsteps = json.loads(s[1]);
trajectories[pedId] = footsteps[0]['footSteps'];
def get_trajectory(pedId):
return trajectories[pedId]
ptrajectories = trajectories_to_dataframe(trajectories)
ptrajectories.head()
```
%% Cell type:markdown id: tags:
# Helpler method to access parts of the trajectory
%% Cell type:code id: tags:
``` python
def get_trajectory(pedId, trajectories):
"""returns a data frame containing the trajectory of one specific agent."""
query = 'pedestrianId == ' + str(pedId)
return trajectories.query(query)
def get_pedestrianIds(trajectories):
return trajectories['pedestrianId'].unique()
def get_footstep(trajectory, i):
return trajectory[i];
"""returns the i-ths footstep."""
return trajectory.iloc[i];
def start_time(trajectory):
return trajectory[0]['startTime'];
def get_footstep_by_time(trajectory, time):
"""returns the footstep which happens at time or nothing (None)."""
query = 'startTime <= ' + str(time) + ' and ' + str(time) + ' < endTime'
fs = trajectories.query(query)
assert len(fs) >= 1
return fs
def max_start_time(trajectories):
return max(map(lambda i: start_time(trajectories[i]), trajectories))
def start_time(trajectory):
"""returns the time of the first footstep of the trajectory."""
return get_footstep(trajectory, 0)['startTime'];
def end_time(trajectory):
return trajectory[-1]['endTime'];
return get_footstep(trajectory, len(trajectory)-1)['endTime'];
def max_start_time(trajectories):
"""returns the time of the first footstep of the trajectory which starts last."""
pedestrianIds = get_pedestrianIds(trajectories)
return max(map(lambda pedId: start_time(get_trajectory(pedId, trajectories)), pedestrianIds))
def min_end_time(trajectories):
return min(map(lambda i: end_time(trajectories[i]), trajectories))
"""returns the time of the last footstep of the trajectory which ends first."""
pedestrianIds = get_pedestrianIds(trajectories)
return min(map(lambda pedId: end_time(get_trajectory(pedId, trajectories)), pedestrianIds))
def footstep_is_between(fs, time):
"""true if the foostep and the intersection with time is not empty."""
startTime = fs['startTime'];
endTime = fs['endTime'];
return startTime <= time and time < endTime;