{% extends "newbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}

{% block title %}Workouts{% endblock %}
{% block scripts %}
{% include "monitorjobs.html" %}
<script type='text/javascript'
        src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
</script>

{% endblock %}

{% block main %}

<script src="https://cdn.pydata.org/bokeh/release/bokeh-1.0.4.min.js"></script>
<script async="true" type="text/javascript">
  Bokeh.set_log_level("info");
</script>

{{ interactiveplot |safe }}


{% if theuser %}
<h1>{{ theuser.first_name }}'s Ranking Pieces</h1>
{% else %}
<h1>{{ user.first_name }}'s Ranking Pieces</h1>
{% endif %}

<ul class="main-content">
  <li class="grid_4">

    <h2>Critical Power Plot</h2>

    {{ the_div|safe }}

    {% if age %}
    <p>The dashed lines are based on the
      <a href="https://log.concept2.com/rankings">Concept2</a>
      rankings for your age, gender
      and weight category. World class means within 5% of
      <a href="http://www.concept2.com/indoor-rowers/racing/records/world">
        World Record</a> in terms
      of power.
      The percentile lines are estimates of where the percentiles
      of the Concept2 rankings historically are for those of exactly
      your age, gender and weight class.
    </p>
    {% endif %}
  </li>
  <li class="grid_4">
    <h2>Ranking Piece Results</h2>

    {% if rankingworkouts %}

    <table width="100%" class="listtable">
      <thead>
        <tr>
	  <th> Distance</th>
	  <th> Duration</th>
	  <th> Date</th>
	  <th> Avg HR </th>
	  <th> Max HR </th>
	  <th> Edit</th>
        <tr>
      </thead>
      <tbody>
        {% for workout in rankingworkouts %}
        <tr>
	  <td> {{ workout.distance }} </td>
	  <td> {{ workout.duration |durationprint:"%H:%M:%S.%f" }} </td>
	  <td> {{ workout.date }} </td>
	  <td> {{ workout.averagehr }} </td>
	  <td> {{ workout.maxhr }} </td>
	  <td>
	    <a href="/rowers/workout/{{ workout.id|encode }}/edit/">
              {{ workout.name }}
            </a>
          </td>

        </tr>

        {% endfor %}
      </tbody>
    </table>
    {% else %}
    <p> No ranking workouts found </p>
    {% endif %}

    <p>Missing your best pieces? Upload stroke data of any Concept2
      ranking piece and they will be automatically added to this page.</p>
    <p>  Don't have stroke data for official Concept2 ranking pieces?
      The <a href="/rowers/paidplans/">PRO membership</a> ranking piece functionality
      allows you to include your best non ranking pieces and even use
      parts of workouts for improved calculation accuracy.
    </p>

    <p>Want to add challenge results but you don't have stroke data?
      <a href="/rowers/workout/addmanual/">Click here.</a></p>

    <p>Scroll down for the chart and pace predictions for ranking pieces.</p>

  </li>



  <li class="grid_2">
    <h2>Pace predictions for Ranking Pieces</h2>

    <p>Add non-ranking piece using the form. The piece will be added in the prediction tables below. </p>
    <form enctype="multipart/form-data" action="{{ formloc }}" method="post">
    {{ form.value }} {{ form.pieceunit }}

    {% csrf_token %}

    <input name="piece" class="button green"
	   formaction="/rowers/ote-bests/user/{{ id }}/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}/"
	   type="submit" value="Add">
    </form>
  </li>/



  <li class="grid_2">
    <h2>Paul's Law</h2>
    {% if nrdata >= 1 %}
    <table width="70%" class="listtable">
      <thead>
        <tr>
	  <th> Duration</th>
	  <th> Distance</th>
	  <th> Power </th>
	  <th> Pace </th>
        <tr>
      </thead>
      <tbody>
        {% for pred in predictions %}
        <tr>
	  {% for key, value in pred.items %}
	  {% if key == "distance" %}
	  <td> {{ value }} m </td>
	  {% endif %}
	  {% if key == "pace" %}
	  <td> {{ value |paceprint }} </td>
	  {% endif %}
	  {% if key == "power" %}
	  <td> {{ value }} W </td>
	  {% endif %}
	  {% if key == "duration" %}
	  <td> {{ value |deltatimeprint }} </td>
	  {% endif %}
	  {% endfor %}
        </tr>
        {% endfor %}
      </tbody>
    </table>

  {% else %}
    <p>Insufficient data to make predictions</p>

    {% endif %}
  </li>
  <li class="grid_2">
    <h2>CP Model</h2>
    {% if nrdata >= 4 %}
    <table width="70%" class="listtable">
      <thead>
        <tr>
	  <th> Duration</th>
	  <th> Distance</th>
	  <th> Power </th>
	  <th> Pace </th>
        <tr>
      </thead>
      <tbody>
        {% for pred in cpredictions %}
        <tr>
	  {% for key, value in pred.items %}
	  {% if key == "distance" %}
	  <td> {{ value }} m </td>
	  {% endif %}
	  {% if key == "pace" %}
	  <td> {{ value |paceprint }} </td>
	  {% endif %}
	  {% if key == "power" %}
	  <td> {{ value }} W </td>
	  {% endif %}
	  {% if key == "duration" %}
	  <td> {{ value |deltatimeprint }} </td>
	  {% endif %}
	  {% endfor %}
        </tr>
        {% endfor %}
      </tbody>
    </table>

    {% else %}
    <p>Insufficient data to make predictions</p>

    {% endif %}
  </li>
  {% if age and sex != 'not specified' %}
  <li>
    <h2>World Records</h2>
    <table width = "100%" class="listtable">
      <tbody>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/100m/">100m
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/500m/">500m
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/1000m/">1000m
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/2000m/">2000m
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/5000m/">5000m
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/6000m/">6000m
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/10000m/">10000m
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/21097m/">Half Marathon
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/42195m/">Full Marathon
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/1min/">1 minute
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/4min/">4 minutes
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/30min/">30 minutes
            </a>
          </td>
        </tr>
        <tr>
          <td>
            <a
              href="/rowers/agegrouprecords/{{ sex }}/{{ weightcategory }}/60min/">1 hour
            </a>
          </td>
        </tr>
      </tbody>
    </table>
  </li>
  {% endif %}
  <li class="grid_2">
    <p>Use this form to select a different date range:</p>
    <p>
      Select start and end date for a date range:

      <form enctype="multipart/form-data" action="" method="post">

        <table>
          {{ dateform.as_table }}
        </table>
        {% csrf_token %}
        <input name='daterange' class="button green" type="submit" value="Submit">
      </form>
  </li>
  <li class="grid_2">
    <p>Summary for {{ theuser.first_name }} {{ theuser.last_name }}
      between {{ startdate|date }} and {{ enddate|date }}</p>

    <p>The table gives the best efforts achieved on the
      <a href="https://log.concept2.com/rankings">official Concept2 ranking pieces</a> in the selected date range. Also the percentile scores on the
      chart are based on the Concept2 rankings.</p>
  </li>
</ul>

{% endblock %}

{% block sidebar %}
{% include 'menu_analytics.html' %}
{% endblock %}
