Skip to content

Instantly share code, notes, and snippets.

@btotr
Created March 27, 2023 11:16
Show Gist options
  • Save btotr/c57881f381459d8354b783d9afd0a56c to your computer and use it in GitHub Desktop.
Save btotr/c57881f381459d8354b783d9afd0a56c to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches
import pandas as pd
import sweat
x = [6, 180, 720]
X = sweat.array_1d_to_2d(x)
y = [831,436,332]
#cp = round(((12*y[2])-(3*y[1]))/9)
#w_prime = 0.24*(y[1] - y[2])*1000
pdr = sweat.PowerDurationRegressor(model="3 param")
pdr.fit(X, y)
durations = range(0, 3600)
durations_2d = sweat.array_1d_to_2d(durations)
data = pd.DataFrame({
"3 param": pdr.predict(durations_2d)
})
print(f"CP: {pdr.cp_}")
print(f"W': {pdr.w_prime_}")
#watts is joules per seconden. controle watts = p3min - cp
print(f"W' in watts: {pdr.w_prime_/x[1]}")
# plot cp
fig = plt.figure(figsize=(15, 10))
ax = fig.add_subplot(1, 1, 1)
pp1 = plt.Rectangle((0, pdr.cp_),
x[1], y[1]-pdr.cp_,color='orange',alpha=0.4)
pp2 = plt.Rectangle((0, pdr.cp_),
x[2], y[2]-pdr.cp_,color='orange',alpha=0.4)
ax.add_patch(pp1)
ax.add_patch(pp2)
#asymtoot
plt.text(3000, pdr.cp_-10, "cp asymtoot")
plt.plot([0,3600], [pdr.cp_, pdr.cp_], 'r--')
# linear regressie
plt.scatter(x, y, color="black")
plt.plot(durations, data['3 param'], label="cp curve")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment