\documentclass{article}
\title{Conconi Test Report}
\author{Simon Cirnski}

\usepackage[margin=0.7in]{geometry}

\usepackage{makecell}
\usepackage{multirow}

\usepackage{tikz,pgfplots}
\usetikzlibrary{calc}

\begin{document}

  \maketitle

  \begin{table}[h]
    \centering
    \begin{tabular}{r||c|c|c|c|}
                           & Power [W]                        & Heart Rate [bpm]                      & Power to Weight Ratio [W/kg]                                 \\ \hline \hline
      \BLOCK{ for i in range( inputs['power'] | length) }
        \VAR{ loop.index } & \VAR{ inputs['power'][i] | int } & \VAR{ inputs['heart_rate'][i] | int } & \VAR{ '%.2f' | format(inputs['power'][i]/inputs['weight']) } \BLOCK{ if not loop.last }\\\BLOCK{ endif }
      \BLOCK{ endfor }
    \end{tabular}
    \caption{Measurements}
  \end{table}

  \def\hrpoly(#1){\VAR{ hr_poly.poly.coef[0] }*(#1)^3 + \VAR{ hr_poly.poly.coef[1] }*(#1)^2 +  \VAR{ hr_poly.poly.coef[2] }*(#1) + \VAR{ hr_poly.poly.coef[3] }}
  \def\coordinates{
    \BLOCK{ for i in range( inputs['power'] | length) }
      (\VAR{ inputs['power'][i] }, \VAR{ inputs['heart_rate'][i] })
    \BLOCK{ endfor }
  }
  \def\xmin{\VAR{ inputs['power'][0] }}
  \def\xmax{\VAR{ inputs['power'][-1] }}
  \def\ymin{\VAR{ inputs['heart_rate'][0] }}
  \def\ymax{\VAR{ inputs['heart_rate'][-1] }}

  \pgfplotsset{
    axis y line=left,
    ylabel near ticks,
    ylabel=Heart Rate {[}bpm{]},
    ytick={0,10,...,250},
    axis x line=bottom,
    xlabel=Power {[}W{]},
    xtick={0, 50,..., 500},
    width=8.5cm,
    height=8.5cm,
    xmin=\xmin - 40,
    xmax=\xmax + 40,
    ymin=\ymin - 10,
    ymax=\ymax + 10,
    grid,
  }

  \begin{center}
    \begin{tikzpicture}[
      extended line/.style={shorten >=-#1},
      extended line/.default=.5cm,
    ]
    \begin{axis}
      \coordinate (start) at (axis cs: \VAR{ conconi['start_point'][0] }, \VAR{ conconi['start_point'][1] });
      \coordinate (cross) at (axis cs: \VAR{ conconi['cross'][0] }, \VAR{ conconi['cross'][1] });
      \coordinate (end) at (axis cs: \VAR{ conconi['end_point'][0] }, \VAR{ conconi['end_point'][1] });
      \coordinate (cross') at (axis cs: \VAR{ conconi['cross'][0] }, 0);

      % \addplot [domain=\xmin-20:\xmax+20, thick] {\hrpoly(x)};
      \addplot [only marks] coordinates {\coordinates};
      \draw [thick, extended line] (start) -- (cross);
      \draw [thick, extended line] (end) -- (cross);
      \draw [thick] (cross') -- (cross) node[pos=0.5, right] {$P=\VAR{ conconi['power'] | int }W$};
    \end{axis}
    \end{tikzpicture}
  \end{center}

  \begin{table}[h]
    \centering
    \begin{tabular}{r|r||c|c|c}
                                                         &                     & Power [W]                       & Heart Rate [bpm]                    & \makecell{Power to Weight \\ Ratio [W/kg]}                 \\
      \hline \hline
      \multirow{1}{*}{\makecell{Anaerobic \\ threshold}} & Conconi             & \VAR{ conconi['power'] | int }  & \VAR{ conconi['heart_rate'] | int } & \VAR{ '%.2f' | format(conconi['power']/inputs['weight']) }  \\
    \end{tabular}
    \caption{Test Results}
  \end{table}

  \begin{table}[h]
    \centering
    \begin{tabular}{r|l||c|c|c}
      Zone  & Training             & Low watts                                     & High watts                                & Notes     \\
      \hline \hline
      1     & Active recovery      & 0                                             & \VAR{ (conconi['power'] * 0.50) | int }W  & 10h+      \\
      2     & Endurance            & \VAR{ (conconi['power'] * 0.50 + 1) | int }W  & \VAR{ (conconi['power'] * 0.75) | int }W  & 2-10h     \\
      3     & Tempo                & \VAR{ (conconi['power'] * 0.75 + 1) | int }W  & \VAR{ (conconi['power'] * 0.87) | int }W  & 30-90min  \\
      3a    & SubThreshold         & \VAR{ (conconi['power'] * 0.87 + 1) | int }W  & \VAR{ (conconi['power'] * 0.93) | int }W  & 10-60min  \\
      4     & Threshold            & \VAR{ (conconi['power'] * 0.93 + 1) | int }W  & \VAR{ (conconi['power'] * 1.04) | int }W  & 8-30min   \\
      5     & VO2max               & \VAR{ (conconi['power'] * 1.04 + 1) | int }W  & \VAR{ (conconi['power'] * 1.30) | int }W  & 2-8min    \\
      6     & Anaerobic capacity   & \VAR{ (conconi['power'] * 1.30 + 1) | int }W  & \VAR{ (conconi['power'] * 2.00) | int }W  & 30-90s    \\
      7     & Neuromuscular power  & \VAR{ (conconi['power'] * 2.00 + 1) | int }W  & max                                       & 5-15s     \\
    \end{tabular}
    \caption{Zones}
  \end{table}


\end{document}
