import numpy
import pandas as pd
from datetime import datetime
import helpers
# Import Data (e.g. From File)
df = pd.read_csv('./data/Speed Export for Usain Bolt 120805.csv')
# Clean Data (mimic GPS device)
df = helpers.clean_gps_data(df)
# Identify Peak (if data is not scoped, this function finds peak velocity in series and scopes around a 7.5 second dataframe). Scope already defined for Bolt's data.
# df = helpers.indentify_fvp_scope(df)
df
height = 1.95
bodyweight = 94
max_velocity = df["Velocity (m/s)"].max()
tau = 1.55
df["Model Speed (m/s)"] = helpers.model_speed(
df["Time (s)"],
df["Velocity (m/s)"],
max_velocity,
tau
)
df["Acceleration (m/s2)"] = helpers.model_acceleration(
df["Time (s)"],
df["Velocity (m/s)"],
max_velocity,
tau
)
df["Force (N)"] = helpers.model_force(
bodyweight,
height,
df["Acceleration (m/s2)"],
df["Model Speed (m/s)"]
)
df["Force (N/kg)"] = df["Force (N)"] / bodyweight
df["Power (W/kg)"] = df["Force (N/kg)"] * df["Model Speed (m/s)"]
df["Ratio Force (%)"] = helpers.model_ratio_force(
df["Force (N)"],
max_velocity,
bodyweight
)
ratio_of_force_df = df[["Model Speed (m/s)", "Ratio Force (%)"]]
ratio_of_force_df = ratio_of_force_df[df["Ratio Force (%)"] < 0.5] # Filter Rows that have Ratio of Force below 0.5 (50%)
plot = ratio_of_force_df.plot.line(x="Model Speed (m/s)", figsize=(16,8), title="Ratio of Force")
plot.set_ylabel("Ratio of Force (%)")
decrease_ratio_of_force_df = df[["Time (s)", "Ratio Force (%)"]]
plot = decrease_ratio_of_force_df.plot.line(x="Time (s)", figsize=(16,8), title="Rate of Decrease in Ratio of Force")
plot.set_ylabel("Ratio of Force (%)")
f0_n = helpers.calc_f0_n(df["Model Speed (m/s)"], df["Force (N)"])
fv_profile_slope = helpers.calc_fv_profile_slope(df["Model Speed (m/s)"], df["Force (N/kg)"])
v0_ms = ((f0_n * -1) / bodyweight) / fv_profile_slope
pmax = f0_n * v0_ms / 4
rf_max = ratio_of_force_df["Ratio Force (%)"].iloc[0] * 100
drf = helpers.calc_fv_profile_slope(ratio_of_force_df["Model Speed (m/s)"], ratio_of_force_df["Ratio Force (%)"])
fv_kpi_set = {
"F0 (N)": f0_n,
"F0 (N/kg)": f0_n / bodyweight,
"V0 (m/s)": v0_ms,
"Pmax (W)": pmax,
"Pmax (W/kg)": pmax / bodyweight,
"FV Profile Slope": fv_profile_slope,
"RFmax": "{}%".format(round(rf_max, 2)),
"Drf": "{}%".format(round((drf * 100), 2))
}
for key, value in fv_kpi_set.items():
df[key] = value
df
# Write new csv to fvps folder
df.to_csv(r"fvps/Usain Bolt FVP Stats 120805.csv", index=False)