#!/bin/bash
#
# RJP 5.3.2025
# Heart rate counter for exercise. It gives approximal rates for training.
# Suorces:
# https://www.topendsports.com/testing/heart-rate-max.htm
# https://www.topendsports.com/fitness/karvonen-formula.htm
# https://www.topendsports.com/fitness/heartrate-range.htm
# https://www.topendsports.com/testing/heart-rate.htm
# https://vocatum.fi/sykealueet-liikunta/
# 
#
AGE=`yad --center --width=100 --height=100 --button=OK:0 --text-align=center --title=$"Heart Rate Counter" --text="PUT YOUR AGE TO THE" --entry --entry-label=BOX --entry-text=""`
#
if [[ $AGE -lt 10 ]] || [[ $AGE -gt 80 ]]
then
yad --width=300 --text-align=center --center --button=OK:0 --title=$"Your results are:" --text="
You are too young or old for the test "
else
awk "BEGIN {print (220 - ($AGE))}" > /tmp/tulos0.txt
awk -v FS='.' '{print $1}' /tmp/tulos0.txt > /tmp/tulos.txt
#
sleep 0,1
awk "BEGIN {print ($(cat /tmp/tulos.txt) * (80 / 100))}" > /tmp/aaero0.txt
awk -v FS='.' '{print $1}' /tmp/aaero0.txt > /tmp/aaero.txt
#
sleep 0,1
awk "BEGIN {print ($(cat /tmp/tulos.txt) * (65 / 100))}" > /tmp/basic0.txt
awk -v FS='.' '{print $1}' /tmp/basic0.txt > /tmp/basic.txt
#
sleep 0,1
awk "BEGIN {print ($(cat /tmp/tulos.txt) * (55 / 100))}" > /tmp/rest0.txt
awk -v FS='.' '{print $1}' /tmp/rest0.txt > /tmp/rest.txt
# The results
yad --width=400 --text-align=center --center  --button=OK:0 --title=$"Your results are:" --text="YOUR HEART RATEs ARE 

Your maximum heart rate is $(cat /tmp/tulos.txt) 

Your anaerobic rate is  $(cat /tmp/aaero.txt)

Your basic training rate is  $(cat /tmp/basic.txt)

Your light training rate is $(cat /tmp/rest.txt)"
fi






