From 48347baca4ef3e6327cefe18d0ad9ea3cc7be3c8 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Sat, 3 Oct 2020 18:37:13 +0300 Subject: [PATCH] Use stats object and format it on react side --- package.json | 3 ++- src/components/WorkoutStats.tsx | 45 ++++++++++++++++++++++++++++++--- yarn.lock | 10 ++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 948927d..34e858b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "@types/node": "^12.0.0", "@types/react": "^16.9.0", "@types/react-dom": "^16.9.0", - "make-workout": "^0.0.0", + "luxon": "^1.25.0", "react": "^16.13.1", "react-dom": "^16.13.1", "react-scripts": "3.4.3", @@ -39,6 +39,7 @@ ] }, "devDependencies": { + "@types/luxon": "^1.25.0", "@types/styled-components": "^5.1.3" } } diff --git a/src/components/WorkoutStats.tsx b/src/components/WorkoutStats.tsx index f8b5bfa..8c9912c 100644 --- a/src/components/WorkoutStats.tsx +++ b/src/components/WorkoutStats.tsx @@ -1,6 +1,45 @@ import React from 'react'; -import { stats, Workout } from 'make-workout'; +import { stats, Workout, Duration, Intensity } from 'make-workout'; +import { Duration as LuxonDuration } from 'luxon'; -export const WorkoutStats: React.FC<{workout: Workout}> = ({ workout }) => ( -
{stats(workout)}
+const formatDuration = (duration: Duration): string => { + const {hours, minutes, seconds} = LuxonDuration.fromObject({seconds: duration.seconds}).shiftTo('hours', 'minutes', 'seconds'); + if (hours > 0) { + return `${hours}h ${minutes}min`; + } + else if (minutes > 0) { + return `${minutes}min`; + } + else if (seconds > 0) { + return `${seconds}sec`; + } + else { + return `-`; + } +}; + +const formatIntensity = (intensity: Intensity): string => `${Math.round(intensity.value * 100)}%`; + +const StatsLine: React.FC<{ label: string, value: string | number }> = ({ label, value }) => ( +
  • {label} {value}
  • ); + +export const WorkoutStats: React.FC<{workout: Workout}> = ({ workout }) => { + const {totalDuration, averageIntensity, normalizedIntensity, tss, zones} = stats(workout); + + return ( +
    +

    Summary

    + +

    Zone distribution

    + +
    + ) +}; diff --git a/yarn.lock b/yarn.lock index b729d89..9523bf5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1622,6 +1622,11 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0" integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw== +"@types/luxon@^1.25.0": + version "1.25.0" + resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-1.25.0.tgz#3d6fe591fac874f48dd225cb5660b2b785a21a05" + integrity sha512-iIJp2CP6C32gVqI08HIYnzqj55tlLnodIBMCcMf28q9ckqMfMzocCmIzd9JWI/ALLPMUiTkCu1JGv3FFtu6t3g== + "@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" @@ -6676,6 +6681,11 @@ lru-cache@^5.1.1: dependencies: yallist "^3.0.2" +luxon@^1.25.0: + version "1.25.0" + resolved "https://registry.yarnpkg.com/luxon/-/luxon-1.25.0.tgz#d86219e90bc0102c0eb299d65b2f5e95efe1fe72" + integrity sha512-hEgLurSH8kQRjY6i4YLey+mcKVAWXbDNlZRmM6AgWDJ1cY3atl8Ztf5wEY7VBReFbmGnwQPz7KYJblL8B2k0jQ== + make-dir@^2.0.0, make-dir@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5"