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

{% block title %}Workout Statistics{% endblock %}

{% block main %}
<p>
  {% if workout|previousworkout:rower.user %}
  <a href="/rowers/workout/{{ workout|previousworkout:rower.user }}/stats"
     title="Jump to preceding workout"><em>Previous</em></a>&nbsp;
  {% endif %}
  {% if workout|nextworkout:rower.user %}
  <a href="/rowers/workout/{{ workout|nextworkout:rower.user }}/stats"
     title="Jump to following workout"><em>Next</em></a>
  {% endif %}
</p>

<h1>Workout Statistics for {{ workout.name }}</h1>
<ul class="main-content">
  <li class="grid_4">
    <p>
      This page lists a bunch of statistics for
      your workout. The mean is of a metric is the mean with equal weight for
      each stroke. The time weighted mean takes into account the stroke
      duration.
    </p>
  </li>
  {% if otherstats %}
  <li>
    <h2>Workout Metrics</h2>
    <table width="100%" class="listtable">
      <thead>
        <tr>
          <th>Metric</th>
          <th>Value</th>
          <th>Unit</th>
        </tr>
      </thead>
      <tbody>
        {% for key, value in otherstats.items %}
        <tr>
          <td>{{ value.verbose_name }}</td>
          <td>{{ value.value }}</td>
          <td>{{ value.unit }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </li>
  <li class="grid_2">
    <p>rPower: Equivalent steady state power for the duration of the workout.</p>
    <p>Heart Rate Drift: Comparing heart rate normalized for average power for the first and second half of the workout</p>
    <p>TRIMP: TRaining IMPact. A way to combine duration and heart rate into a single number.</p>
    <p>rScore: Score based on rPower and workout duration to estimate training effect</p>
    <p>rScore (HR): Score based on heart rate, designed to give values comparable to rScore. Used instead of rScore for workouts without power data.</p>
  </li>
  {% endif %}
  <li>
      <form enctype="multipart/form-data" action="{{ formloc }}" method="post">
        {% csrf_token %}
      {% if workstrokesonly == True %}
        <input class="button" type="hidden" name="workstrokesonly" value="False">
        <input class="button" value="Include Rest Strokes" type="Submit">
        {% else %}
        <input class="button" type="hidden" name="workstrokesonly" value="True">
        <input class="button" value="Remove Rest Strokes" type="Submit">
        {% endif %}
      </form>
  </li>

  
  {% if stats %}
  <li class="grid_4">
    <h2>Statistics</h2>
    <table width="100%" class="listtable">
      <thead>
        <tr>
          <th>Metric</th>
          <th>Mean</th>
          <th>Time Weighted Mean</th>
          <th>Minimum</th>
          <th>25&#37;</th>
          <th>Median</th>
          <th>75&#37;</th>
          <th>Maximum</th>
          <th>Standard Deviation</th>
        </tr>
      </thead>
      <tbody>
        {% for key, value in stats.items %}
        <tr>
          {% if value.std > 10 %}
          <td>{{ value.verbosename }}</td>
          <td>{{ value.mean|floatformat:0 }}</td>
          <td> {{ value.wmean|floatformat:0 }}</td>
          <td>{{ value.min|floatformat:0 }}</td>
          <td>{{ value.firstq|floatformat:0 }}</td>
          <td>{{ value.median|floatformat:0 }}</td>
          <td>{{ value.thirdq|floatformat:0 }}</td>
          <td>{{ value.max|floatformat:0 }}</td>
          <td>{{ value.std|floatformat:0 }}</td>
          {% elif value.std > 1 %}
          <td>{{ value.verbosename }}</td>
          <td>{{ value.mean|floatformat:-1 }}</td>
          <td> {{ value.wmean|floatformat:-1 }}</td>
          <td>{{ value.min|floatformat:-1 }}</td>
          <td>{{ value.firstq|floatformat:-1 }}</td>
          <td>{{ value.median|floatformat:-1 }}</td>
          <td>{{ value.thirdq|floatformat:-1 }}</td>
          <td>{{ value.max|floatformat:-1 }}</td>
          <td>{{ value.std|floatformat:-1 }}</td>
          {% else %}
          <td>{{ value.verbosename }}</td>
          <td>{{ value.mean|floatformat:-2 }}</td>
          <td> {{ value.wmean|floatformat:-2 }}</td>
          <td>{{ value.min|floatformat:-2 }}</td>
          <td>{{ value.firstq|floatformat:-2 }}</td>
          <td>{{ value.median|floatformat:-2 }}</td>
          <td>{{ value.thirdq|floatformat:-2 }}</td>
          <td>{{ value.max|floatformat:-2 }}</td>
          <td>{{ value.std|floatformat:-2 }}</td>
          {% endif %}
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </li>
  {% endif %}

  {% if cordict %}
  <li class="grid_4">
    <h2> Correlation matrix</h2>
    <p>This matrix indicates a positive (+) or negative (-) correlation between two parameters. The Spearman correlation coefficient has values between +1 and -1. Positive correlation between two metrics means that if one metric increases, the other value is also likely to increase. Negative is the opposite. The further from zero, the higher the likelyhood.
    </p>
    <table width="90%" class="cortable">
      <thead>
        <tr>
          <th>&nbsp;</th>
          {% for key,value in cordict.items %}
          <th class="rotate"><div><span>{{ key }}</span></div></th>
          {% endfor %}
        </tr>
      </thead>
      <tbody>
        {% for key, thedict in cordict.items %}
        <tr>
          <th> {{ key }}</th>
          {% for key2,value in thedict.items %}
          <td>
            {% if value > 0.5 %}
            <div class="poscor">{{ value|floatformat:-1 }}</div>
            {% elif value > 0.1 %}
            <div class="weakposcor">{{ value|floatformat:-1 }}</div>
            {% elif value < -0.5 %}
            <div class="negcor">{{ value|floatformat:-1 }}</div>
            {% elif value < -0.1 %}
            <div class="weaknegcor">{{ value|floatformat:-1 }}</div>
            {% else %}
            &nbsp;
            {% endif %}
          </td>
          {% endfor %}
        </tr>
        {% endfor %}
      </tbody>
    </table>  
  </li>
  {% endif %}
</ul>


{% endblock %}

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