Merge pull request #253 from SamR1/add-date-formats-to-stats
Apply date format to charts
This commit is contained in:
commit
c275d4fb01
2
fittrackee/dist/index.html
vendored
2
fittrackee/dist/index.html
vendored
@ -1 +1 @@
|
|||||||
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><!--[if IE]><link rel="icon" href="/favicon.ico"><![endif]--><link rel="stylesheet" href="/static/css/fork-awesome.min.css"/><link rel="stylesheet" href="/static/css/leaflet.css"/><title>FitTrackee</title><script defer="defer" src="/static/js/chunk-vendors.50f5c7a2.js"></script><script defer="defer" src="/static/js/app.fab0b67d.js"></script><link href="/static/css/app.c5a6ea83.css" rel="stylesheet"><link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#4DBA87"><meta name="apple-mobile-web-app-capable" content="no"><meta name="apple-mobile-web-app-status-bar-style" content="default"><meta name="apple-mobile-web-app-title" content="fittrackee_client"><link rel="apple-touch-icon" href="/img/icons/apple-touch-icon-152x152.png"><link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color="#4DBA87"><meta name="msapplication-TileImage" content="/img/icons/msapplication-icon-144x144.png"><meta name="msapplication-TileColor" content="#000000"></head><body><noscript><strong>We're sorry but FitTrackee doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><!--[if IE]><link rel="icon" href="/favicon.ico"><![endif]--><link rel="stylesheet" href="/static/css/fork-awesome.min.css"/><link rel="stylesheet" href="/static/css/leaflet.css"/><title>FitTrackee</title><script defer="defer" src="/static/js/chunk-vendors.50f5c7a2.js"></script><script defer="defer" src="/static/js/app.455eebb6.js"></script><link href="/static/css/app.564b9516.css" rel="stylesheet"><link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#4DBA87"><meta name="apple-mobile-web-app-capable" content="no"><meta name="apple-mobile-web-app-status-bar-style" content="default"><meta name="apple-mobile-web-app-title" content="fittrackee_client"><link rel="apple-touch-icon" href="/img/icons/apple-touch-icon-152x152.png"><link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color="#4DBA87"><meta name="msapplication-TileImage" content="/img/icons/msapplication-icon-144x144.png"><meta name="msapplication-TileColor" content="#000000"></head><body><noscript><strong>We're sorry but FitTrackee doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
2
fittrackee/dist/service-worker.js
vendored
2
fittrackee/dist/service-worker.js
vendored
File diff suppressed because one or more lines are too long
2
fittrackee/dist/service-worker.js.map
vendored
2
fittrackee/dist/service-worker.js.map
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
fittrackee/dist/static/js/app.455eebb6.js
vendored
Normal file
2
fittrackee/dist/static/js/app.455eebb6.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
fittrackee/dist/static/js/app.455eebb6.js.map
vendored
Normal file
1
fittrackee/dist/static/js/app.455eebb6.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
2
fittrackee/dist/static/js/app.fab0b67d.js
vendored
2
fittrackee/dist/static/js/app.fab0b67d.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,2 +1,2 @@
|
|||||||
"use strict";(self["webpackChunkfittrackee_client"]=self["webpackChunkfittrackee_client"]||[]).push([[193],{7885:function(e,s,t){t.r(s),t.d(s,{default:function(){return A}});var a=t(6252),r=t(2262),l=t(3577),o=(t(7658),t(9150)),n=t(4998);const c={class:"chart-menu"},i={class:"chart-arrow"},u={class:"time-frames custom-checkboxes-group"},d={class:"time-frames-checkboxes custom-checkboxes"},p=["id","name","checked","onInput"],m={class:"chart-arrow"};var v=(0,a.aZ)({__name:"StatsMenu",emits:["arrowClick","timeFrameUpdate"],setup(e,{emit:s}){const t=(0,r.iH)("month"),o=["week","month","year"];function n(e){t.value=e,s("timeFrameUpdate",e)}return(e,r)=>((0,a.wg)(),(0,a.iD)("div",c,[(0,a._)("div",i,[(0,a._)("i",{class:"fa fa-chevron-left","aria-hidden":"true",onClick:r[0]||(r[0]=e=>s("arrowClick",!0))})]),(0,a._)("div",u,[(0,a._)("div",d,[((0,a.wg)(),(0,a.iD)(a.HY,null,(0,a.Ko)(o,(s=>(0,a._)("div",{class:"time-frame custom-checkbox",key:s},[(0,a._)("label",null,[(0,a._)("input",{type:"radio",id:s,name:s,checked:t.value===s,onInput:e=>n(s)},null,40,p),(0,a._)("span",null,(0,l.zw)(e.$t(`statistics.TIME_FRAMES.${s}`)),1)])]))),64))])]),(0,a._)("div",m,[(0,a._)("i",{class:"fa fa-chevron-right","aria-hidden":"true",onClick:r[1]||(r[1]=e=>s("arrowClick",!1))})])]))}}),k=t(3744);const _=(0,k.Z)(v,[["__scopeId","data-v-22d55de2"]]);var S=_,w=t(631);const f={class:"sports-menu"},h=["id","name","checked","onInput"],U={class:"sport-label"};var b=(0,a.aZ)({__name:"StatsSportsMenu",props:{userSports:null,selectedSportIds:{default:()=>[]}},emits:["selectedSportIdsUpdate"],setup(e,{emit:s}){const t=e,{t:n}=(0,o.QT)(),c=(0,a.f3)("sportColors"),{selectedSportIds:i}=(0,r.BK)(t),u=(0,a.Fl)((()=>(0,w.xH)(t.userSports,n)));function d(e){s("selectedSportIdsUpdate",e)}return(e,s)=>{const t=(0,a.up)("SportImage");return(0,a.wg)(),(0,a.iD)("div",f,[((0,a.wg)(!0),(0,a.iD)(a.HY,null,(0,a.Ko)((0,r.SU)(u),(e=>((0,a.wg)(),(0,a.iD)("label",{type:"checkbox",key:e.id,style:(0,l.j5)({color:e.color?e.color:(0,r.SU)(c)[e.label]})},[(0,a._)("input",{type:"checkbox",id:e.id,name:e.label,checked:(0,r.SU)(i).includes(e.id),onInput:s=>d(e.id)},null,40,h),(0,a.Wm)(t,{"sport-label":e.label,color:e.color},null,8,["sport-label","color"]),(0,a._)("span",U,(0,l.zw)(e.translatedLabel),1)],4)))),128))])}}});const I=b;var g=I,T=t(9318);const y={key:0,id:"user-statistics"};var C=(0,a.aZ)({__name:"index",props:{sports:null,user:null},setup(e){const s=e,{t:t}=(0,o.QT)(),{sports:l,user:c}=(0,r.BK)(s),i=(0,r.iH)("month"),u=(0,r.iH)(v(i.value)),d=(0,a.Fl)((()=>(0,w.xH)(s.sports,t))),p=(0,r.iH)(_(s.sports));function m(e){i.value=e,u.value=v(i.value)}function v(e){return(0,T.aZ)(new Date,e,s.user.weekm)}function k(e){u.value=(0,T.FN)(u.value,e,s.user.weekm)}function _(e){return e.map((e=>e.id))}function f(e){p.value.includes(e)?p.value=p.value.filter((s=>s!==e)):p.value.push(e)}return(0,a.YP)((()=>s.sports),(e=>{p.value=_(e)})),(e,s)=>(0,r.SU)(d)?((0,a.wg)(),(0,a.iD)("div",y,[(0,a.Wm)(S,{onTimeFrameUpdate:m,onArrowClick:k}),(0,a.Wm)(n.Z,{sports:(0,r.SU)(l),user:(0,r.SU)(c),chartParams:u.value,"displayed-sport-ids":p.value,fullStats:!0},null,8,["sports","user","chartParams","displayed-sport-ids"]),(0,a.Wm)(g,{"selected-sport-ids":p.value,"user-sports":(0,r.SU)(l),onSelectedSportIdsUpdate:f},null,8,["selected-sport-ids","user-sports"])])):(0,a.kq)("",!0)}});const F=(0,k.Z)(C,[["__scopeId","data-v-30799d13"]]);var Z=F,x=t(5630),D=t(5801),H=t(9917);const E={id:"statistics",class:"view"},R={key:0,class:"container"};var W=(0,a.aZ)({__name:"StatisticsView",setup(e){const s=(0,H.o)(),t=(0,a.Fl)((()=>s.getters[D.YN.GETTERS.AUTH_USER_PROFILE])),o=(0,a.Fl)((()=>s.getters[D.O8.GETTERS.SPORTS].filter((e=>t.value.sports_list.includes(e.id)))));return(e,s)=>{const n=(0,a.up)("Card");return(0,a.wg)(),(0,a.iD)("div",E,[(0,r.SU)(t).username?((0,a.wg)(),(0,a.iD)("div",R,[(0,a.Wm)(n,null,{title:(0,a.w5)((()=>[(0,a.Uk)((0,l.zw)(e.$t("statistics.STATISTICS")),1)])),content:(0,a.w5)((()=>[(0,a.Wm)(Z,{class:(0,l.C_)({"stats-disabled":0===(0,r.SU)(t).nb_workouts}),user:(0,r.SU)(t),sports:(0,r.SU)(o)},null,8,["class","user","sports"])])),_:1}),0===(0,r.SU)(t).nb_workouts?((0,a.wg)(),(0,a.j4)(x.Z,{key:0})):(0,a.kq)("",!0)])):(0,a.kq)("",!0)])}}});const P=(0,k.Z)(W,[["__scopeId","data-v-2e341d4e"]]);var A=P}}]);
|
"use strict";(self["webpackChunkfittrackee_client"]=self["webpackChunkfittrackee_client"]||[]).push([[193],{7885:function(e,s,t){t.r(s),t.d(s,{default:function(){return A}});var a=t(6252),r=t(2262),l=t(3577),o=(t(7658),t(9150)),n=t(3170);const c={class:"chart-menu"},i={class:"chart-arrow"},u={class:"time-frames custom-checkboxes-group"},d={class:"time-frames-checkboxes custom-checkboxes"},p=["id","name","checked","onInput"],m={class:"chart-arrow"};var v=(0,a.aZ)({__name:"StatsMenu",emits:["arrowClick","timeFrameUpdate"],setup(e,{emit:s}){const t=(0,r.iH)("month"),o=["week","month","year"];function n(e){t.value=e,s("timeFrameUpdate",e)}return(e,r)=>((0,a.wg)(),(0,a.iD)("div",c,[(0,a._)("div",i,[(0,a._)("i",{class:"fa fa-chevron-left","aria-hidden":"true",onClick:r[0]||(r[0]=e=>s("arrowClick",!0))})]),(0,a._)("div",u,[(0,a._)("div",d,[((0,a.wg)(),(0,a.iD)(a.HY,null,(0,a.Ko)(o,(s=>(0,a._)("div",{class:"time-frame custom-checkbox",key:s},[(0,a._)("label",null,[(0,a._)("input",{type:"radio",id:s,name:s,checked:t.value===s,onInput:e=>n(s)},null,40,p),(0,a._)("span",null,(0,l.zw)(e.$t(`statistics.TIME_FRAMES.${s}`)),1)])]))),64))])]),(0,a._)("div",m,[(0,a._)("i",{class:"fa fa-chevron-right","aria-hidden":"true",onClick:r[1]||(r[1]=e=>s("arrowClick",!1))})])]))}}),k=t(3744);const _=(0,k.Z)(v,[["__scopeId","data-v-22d55de2"]]);var S=_,w=t(631);const f={class:"sports-menu"},h=["id","name","checked","onInput"],U={class:"sport-label"};var b=(0,a.aZ)({__name:"StatsSportsMenu",props:{userSports:null,selectedSportIds:{default:()=>[]}},emits:["selectedSportIdsUpdate"],setup(e,{emit:s}){const t=e,{t:n}=(0,o.QT)(),c=(0,a.f3)("sportColors"),{selectedSportIds:i}=(0,r.BK)(t),u=(0,a.Fl)((()=>(0,w.xH)(t.userSports,n)));function d(e){s("selectedSportIdsUpdate",e)}return(e,s)=>{const t=(0,a.up)("SportImage");return(0,a.wg)(),(0,a.iD)("div",f,[((0,a.wg)(!0),(0,a.iD)(a.HY,null,(0,a.Ko)((0,r.SU)(u),(e=>((0,a.wg)(),(0,a.iD)("label",{type:"checkbox",key:e.id,style:(0,l.j5)({color:e.color?e.color:(0,r.SU)(c)[e.label]})},[(0,a._)("input",{type:"checkbox",id:e.id,name:e.label,checked:(0,r.SU)(i).includes(e.id),onInput:s=>d(e.id)},null,40,h),(0,a.Wm)(t,{"sport-label":e.label,color:e.color},null,8,["sport-label","color"]),(0,a._)("span",U,(0,l.zw)(e.translatedLabel),1)],4)))),128))])}}});const I=b;var g=I,T=t(9318);const y={key:0,id:"user-statistics"};var C=(0,a.aZ)({__name:"index",props:{sports:null,user:null},setup(e){const s=e,{t:t}=(0,o.QT)(),{sports:l,user:c}=(0,r.BK)(s),i=(0,r.iH)("month"),u=(0,r.iH)(v(i.value)),d=(0,a.Fl)((()=>(0,w.xH)(s.sports,t))),p=(0,r.iH)(_(s.sports));function m(e){i.value=e,u.value=v(i.value)}function v(e){return(0,T.aZ)(new Date,e,s.user.weekm)}function k(e){u.value=(0,T.FN)(u.value,e,s.user.weekm)}function _(e){return e.map((e=>e.id))}function f(e){p.value.includes(e)?p.value=p.value.filter((s=>s!==e)):p.value.push(e)}return(0,a.YP)((()=>s.sports),(e=>{p.value=_(e)})),(e,s)=>(0,r.SU)(d)?((0,a.wg)(),(0,a.iD)("div",y,[(0,a.Wm)(S,{onTimeFrameUpdate:m,onArrowClick:k}),(0,a.Wm)(n.Z,{sports:(0,r.SU)(l),user:(0,r.SU)(c),chartParams:u.value,"displayed-sport-ids":p.value,fullStats:!0},null,8,["sports","user","chartParams","displayed-sport-ids"]),(0,a.Wm)(g,{"selected-sport-ids":p.value,"user-sports":(0,r.SU)(l),onSelectedSportIdsUpdate:f},null,8,["selected-sport-ids","user-sports"])])):(0,a.kq)("",!0)}});const F=(0,k.Z)(C,[["__scopeId","data-v-30799d13"]]);var Z=F,x=t(5630),D=t(5801),H=t(9917);const E={id:"statistics",class:"view"},R={key:0,class:"container"};var W=(0,a.aZ)({__name:"StatisticsView",setup(e){const s=(0,H.o)(),t=(0,a.Fl)((()=>s.getters[D.YN.GETTERS.AUTH_USER_PROFILE])),o=(0,a.Fl)((()=>s.getters[D.O8.GETTERS.SPORTS].filter((e=>t.value.sports_list.includes(e.id)))));return(e,s)=>{const n=(0,a.up)("Card");return(0,a.wg)(),(0,a.iD)("div",E,[(0,r.SU)(t).username?((0,a.wg)(),(0,a.iD)("div",R,[(0,a.Wm)(n,null,{title:(0,a.w5)((()=>[(0,a.Uk)((0,l.zw)(e.$t("statistics.STATISTICS")),1)])),content:(0,a.w5)((()=>[(0,a.Wm)(Z,{class:(0,l.C_)({"stats-disabled":0===(0,r.SU)(t).nb_workouts}),user:(0,r.SU)(t),sports:(0,r.SU)(o)},null,8,["class","user","sports"])])),_:1}),0===(0,r.SU)(t).nb_workouts?((0,a.wg)(),(0,a.j4)(x.Z,{key:0})):(0,a.kq)("",!0)])):(0,a.kq)("",!0)])}}});const P=(0,k.Z)(W,[["__scopeId","data-v-2e341d4e"]]);var A=P}}]);
|
||||||
//# sourceMappingURL=statistics.cd487330.js.map
|
//# sourceMappingURL=statistics.04a17f2e.js.map
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -145,7 +145,8 @@
|
|||||||
props.sports,
|
props.sports,
|
||||||
props.displayedSportIds,
|
props.displayedSportIds,
|
||||||
statistics.value,
|
statistics.value,
|
||||||
props.user.imperial_units
|
props.user.imperial_units,
|
||||||
|
props.user.date_format
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,12 +6,18 @@ import { createI18n, LocaleMessages, VueMessageType } from 'vue-i18n'
|
|||||||
* The loaded `JSON` locale messages is pre-compiled by `@intlify/vue-i18n-loader`, which is integrated into `vue-cli-plugin-i18n`.
|
* The loaded `JSON` locale messages is pre-compiled by `@intlify/vue-i18n-loader`, which is integrated into `vue-cli-plugin-i18n`.
|
||||||
* See: https://github.com/intlify/vue-i18n-loader#rocket-i18n-resource-pre-compilation
|
* See: https://github.com/intlify/vue-i18n-loader#rocket-i18n-resource-pre-compilation
|
||||||
*/
|
*/
|
||||||
|
const disabledLanguages = ['nb'] // to remove after norwegian translations release
|
||||||
|
|
||||||
function loadLocaleMessages(): Record<string, LocaleMessages<VueMessageType>> {
|
function loadLocaleMessages(): Record<string, LocaleMessages<VueMessageType>> {
|
||||||
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.ts$/i)
|
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.ts$/i)
|
||||||
const messages: Record<string, LocaleMessages<VueMessageType>> = {}
|
const messages: Record<string, LocaleMessages<VueMessageType>> = {}
|
||||||
locales.keys().forEach((key) => {
|
locales.keys().forEach((key) => {
|
||||||
const matched = key.match(/([A-Za-z0-9-_]+)\./i)
|
const matched = key.match(/([A-Za-z0-9-_]+)\./i)
|
||||||
if (matched && matched.length > 1) {
|
if (
|
||||||
|
matched &&
|
||||||
|
matched.length > 1 &&
|
||||||
|
!disabledLanguages.includes(matched[1])
|
||||||
|
) {
|
||||||
const locale = matched[1]
|
const locale = matched[1]
|
||||||
messages[locale] = locales(key).default
|
messages[locale] = locales(key).default
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import {
|
|||||||
subYears,
|
subYears,
|
||||||
} from 'date-fns'
|
} from 'date-fns'
|
||||||
|
|
||||||
|
import createI18n from '@/i18n'
|
||||||
import { IChartDataset } from '@/types/chart'
|
import { IChartDataset } from '@/types/chart'
|
||||||
import { ISport } from '@/types/sports'
|
import { ISport } from '@/types/sports'
|
||||||
import {
|
import {
|
||||||
@ -23,14 +24,17 @@ import {
|
|||||||
TStatisticsDatasets,
|
TStatisticsDatasets,
|
||||||
TStatisticsFromApi,
|
TStatisticsFromApi,
|
||||||
} from '@/types/statistics'
|
} from '@/types/statistics'
|
||||||
import { incrementDate, getStartDate } from '@/utils/dates'
|
import { incrementDate, getStartDate, getDateFormat } from '@/utils/dates'
|
||||||
|
import { localeFromLanguage } from '@/utils/locales'
|
||||||
import { sportColors } from '@/utils/sports'
|
import { sportColors } from '@/utils/sports'
|
||||||
import { convertStatsDistance } from '@/utils/units'
|
import { convertStatsDistance } from '@/utils/units'
|
||||||
|
|
||||||
|
const { locale } = createI18n.global
|
||||||
|
|
||||||
const dateFormats: Record<string, Record<string, string>> = {
|
const dateFormats: Record<string, Record<string, string>> = {
|
||||||
week: {
|
week: {
|
||||||
api: 'yyyy-MM-dd',
|
api: 'yyyy-MM-dd',
|
||||||
chart: 'dd/MM/yyyy',
|
chart: 'MM/dd/yyyy',
|
||||||
},
|
},
|
||||||
month: {
|
month: {
|
||||||
api: 'yyyy-MM',
|
api: 'yyyy-MM',
|
||||||
@ -135,7 +139,8 @@ export const formatStats = (
|
|||||||
sports: ISport[],
|
sports: ISport[],
|
||||||
displayedSportsId: number[],
|
displayedSportsId: number[],
|
||||||
apiStats: TStatisticsFromApi,
|
apiStats: TStatisticsFromApi,
|
||||||
useImperialUnits: boolean
|
useImperialUnits: boolean,
|
||||||
|
userDateFormat: string
|
||||||
): IStatisticsChartData => {
|
): IStatisticsChartData => {
|
||||||
const dayKeys = getDateKeys(params, weekStartingMonday)
|
const dayKeys = getDateKeys(params, weekStartingMonday)
|
||||||
const dateFormat = dateFormats[params.duration]
|
const dateFormat = dateFormats[params.duration]
|
||||||
@ -151,7 +156,13 @@ export const formatStats = (
|
|||||||
|
|
||||||
dayKeys.map((key) => {
|
dayKeys.map((key) => {
|
||||||
const date: string = format(key, dateFormat.api)
|
const date: string = format(key, dateFormat.api)
|
||||||
const label: string = format(key, dateFormat.chart)
|
const label: string = format(
|
||||||
|
key,
|
||||||
|
params.duration === 'week'
|
||||||
|
? getDateFormat(userDateFormat, locale.value)
|
||||||
|
: dateFormat.chart,
|
||||||
|
{ locale: localeFromLanguage[locale.value] }
|
||||||
|
)
|
||||||
labels.push(label)
|
labels.push(label)
|
||||||
datasetKeys.map((datasetKey) => {
|
datasetKeys.map((datasetKey) => {
|
||||||
datasets[datasetKey].map((dataset) => {
|
datasets[datasetKey].map((dataset) => {
|
||||||
|
@ -2,6 +2,7 @@ import { assert } from 'chai'
|
|||||||
|
|
||||||
import { sports } from './fixtures'
|
import { sports } from './fixtures'
|
||||||
|
|
||||||
|
import createI18n from '@/i18n'
|
||||||
import {
|
import {
|
||||||
IStatisticsChartData,
|
IStatisticsChartData,
|
||||||
TStatisticsDatasets,
|
TStatisticsDatasets,
|
||||||
@ -15,6 +16,8 @@ import {
|
|||||||
updateChartParams,
|
updateChartParams,
|
||||||
} from '@/utils/statistics'
|
} from '@/utils/statistics'
|
||||||
|
|
||||||
|
const { locale } = createI18n.global
|
||||||
|
|
||||||
describe('getDateKeys (week starting Sunday)', () => {
|
describe('getDateKeys (week starting Sunday)', () => {
|
||||||
const testsParams = [
|
const testsParams = [
|
||||||
{
|
{
|
||||||
@ -353,7 +356,15 @@ describe('formatStats', () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
formatStats(inputParams, false, sports, [], inputStats, false),
|
formatStats(
|
||||||
|
inputParams,
|
||||||
|
false,
|
||||||
|
sports,
|
||||||
|
[],
|
||||||
|
inputStats,
|
||||||
|
false,
|
||||||
|
'MM/dd/yyyy'
|
||||||
|
),
|
||||||
expected
|
expected
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -416,7 +427,15 @@ describe('formatStats', () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
formatStats(inputParams, false, sports, [2], inputStats, false),
|
formatStats(
|
||||||
|
inputParams,
|
||||||
|
false,
|
||||||
|
sports,
|
||||||
|
[2],
|
||||||
|
inputStats,
|
||||||
|
false,
|
||||||
|
'MM/dd/yyyy'
|
||||||
|
),
|
||||||
expected
|
expected
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -479,7 +498,15 @@ describe('formatStats', () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
formatStats(inputParams, false, sports, [], inputStats, false),
|
formatStats(
|
||||||
|
inputParams,
|
||||||
|
false,
|
||||||
|
sports,
|
||||||
|
[],
|
||||||
|
inputStats,
|
||||||
|
false,
|
||||||
|
'MM/dd/yyyy'
|
||||||
|
),
|
||||||
expected
|
expected
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -581,7 +608,15 @@ describe('formatStats', () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
formatStats(inputParams, false, sports, [1], inputStats, false),
|
formatStats(
|
||||||
|
inputParams,
|
||||||
|
false,
|
||||||
|
sports,
|
||||||
|
[1],
|
||||||
|
inputStats,
|
||||||
|
false,
|
||||||
|
'MM/dd/yyyy'
|
||||||
|
),
|
||||||
expected
|
expected
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -685,13 +720,21 @@ describe('formatStats (duration)', () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
formatStats(inputParams, false, sports, [1], inputStats, false),
|
formatStats(
|
||||||
|
inputParams,
|
||||||
|
false,
|
||||||
|
sports,
|
||||||
|
[1],
|
||||||
|
inputStats,
|
||||||
|
false,
|
||||||
|
'MM/dd/yyyy'
|
||||||
|
),
|
||||||
expected
|
expected
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
it("returns datasets when duration is 'year'", () => {
|
it("returns datasets when duration is 'month'", () => {
|
||||||
const inputStats: TStatisticsFromApi = {
|
const inputStats: TStatisticsFromApi = {
|
||||||
'2020': {
|
'2021-10': {
|
||||||
1: {
|
1: {
|
||||||
average_speed: 12,
|
average_speed: 12,
|
||||||
nb_workouts: 1,
|
nb_workouts: 1,
|
||||||
@ -701,7 +744,7 @@ describe('formatStats (duration)', () => {
|
|||||||
total_descent: 100,
|
total_descent: 100,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'2021': {
|
'2021-11': {
|
||||||
1: {
|
1: {
|
||||||
average_speed: 18,
|
average_speed: 18,
|
||||||
nb_workouts: 1,
|
nb_workouts: 1,
|
||||||
@ -719,7 +762,7 @@ describe('formatStats (duration)', () => {
|
|||||||
total_descent: 200,
|
total_descent: 200,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'2022': {
|
'2021-12': {
|
||||||
3: {
|
3: {
|
||||||
average_speed: 8.64,
|
average_speed: 8.64,
|
||||||
nb_workouts: 2,
|
nb_workouts: 2,
|
||||||
@ -731,19 +774,19 @@ describe('formatStats (duration)', () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
const inputParams = {
|
const inputParams = {
|
||||||
duration: 'year',
|
duration: 'month',
|
||||||
start: new Date('January 1, 2020 00:00:00'),
|
start: new Date('October 1, 2021 00:00:00'),
|
||||||
end: new Date('December 31, 2021 23:59:59.999'),
|
end: new Date('December 31, 2021 23:59:59.999'),
|
||||||
}
|
}
|
||||||
const expected: IStatisticsChartData = {
|
const expected: IStatisticsChartData = {
|
||||||
labels: ['2020', '2021'],
|
labels: ['10/2021', '11/2021', '12/2021'],
|
||||||
datasets: {
|
datasets: {
|
||||||
average_speed: [
|
average_speed: [
|
||||||
{
|
{
|
||||||
label: 'Cycling (Sport)',
|
label: 'Cycling (Sport)',
|
||||||
backgroundColor: ['#4c9792'],
|
backgroundColor: ['#4c9792'],
|
||||||
borderColor: ['#4c9792'],
|
borderColor: ['#4c9792'],
|
||||||
data: [12, 18],
|
data: [12, 18, null],
|
||||||
type: 'line',
|
type: 'line',
|
||||||
spanGaps: true,
|
spanGaps: true,
|
||||||
},
|
},
|
||||||
@ -752,41 +795,49 @@ describe('formatStats (duration)', () => {
|
|||||||
{
|
{
|
||||||
label: 'Cycling (Sport)',
|
label: 'Cycling (Sport)',
|
||||||
backgroundColor: ['#4c9792'],
|
backgroundColor: ['#4c9792'],
|
||||||
data: [1, 1],
|
data: [1, 1, 0],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
total_distance: [
|
total_distance: [
|
||||||
{
|
{
|
||||||
label: 'Cycling (Sport)',
|
label: 'Cycling (Sport)',
|
||||||
backgroundColor: ['#4c9792'],
|
backgroundColor: ['#4c9792'],
|
||||||
data: [10, 15],
|
data: [10, 15, 0],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
total_duration: [
|
total_duration: [
|
||||||
{
|
{
|
||||||
label: 'Cycling (Sport)',
|
label: 'Cycling (Sport)',
|
||||||
backgroundColor: ['#4c9792'],
|
backgroundColor: ['#4c9792'],
|
||||||
data: [3000, 3500],
|
data: [3000, 3500, 0],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
total_ascent: [
|
total_ascent: [
|
||||||
{
|
{
|
||||||
label: 'Cycling (Sport)',
|
label: 'Cycling (Sport)',
|
||||||
backgroundColor: ['#4c9792'],
|
backgroundColor: ['#4c9792'],
|
||||||
data: [150, 250],
|
data: [150, 250, 0],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
total_descent: [
|
total_descent: [
|
||||||
{
|
{
|
||||||
label: 'Cycling (Sport)',
|
label: 'Cycling (Sport)',
|
||||||
backgroundColor: ['#4c9792'],
|
backgroundColor: ['#4c9792'],
|
||||||
data: [100, 150],
|
data: [100, 150, 0],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
formatStats(inputParams, false, sports, [1], inputStats, false),
|
formatStats(
|
||||||
|
inputParams,
|
||||||
|
false,
|
||||||
|
sports,
|
||||||
|
[1],
|
||||||
|
inputStats,
|
||||||
|
false,
|
||||||
|
'MM/dd/yyyy'
|
||||||
|
),
|
||||||
expected
|
expected
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -838,7 +889,7 @@ describe('formatStats (duration)', () => {
|
|||||||
end: new Date('October 23, 2021 23:59:59.999'),
|
end: new Date('October 23, 2021 23:59:59.999'),
|
||||||
}
|
}
|
||||||
const expected: IStatisticsChartData = {
|
const expected: IStatisticsChartData = {
|
||||||
labels: ['03/10/2021', '10/10/2021', '17/10/2021'],
|
labels: ['10/03/2021', '10/10/2021', '10/17/2021'],
|
||||||
datasets: {
|
datasets: {
|
||||||
average_speed: [
|
average_speed: [
|
||||||
{
|
{
|
||||||
@ -888,7 +939,15 @@ describe('formatStats (duration)', () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
formatStats(inputParams, false, sports, [1], inputStats, false),
|
formatStats(
|
||||||
|
inputParams,
|
||||||
|
false,
|
||||||
|
sports,
|
||||||
|
[1],
|
||||||
|
inputStats,
|
||||||
|
false,
|
||||||
|
'MM/dd/yyyy'
|
||||||
|
),
|
||||||
expected
|
expected
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -940,7 +999,7 @@ describe('formatStats (duration)', () => {
|
|||||||
end: new Date('October 24, 2021 23:59:59.999'),
|
end: new Date('October 24, 2021 23:59:59.999'),
|
||||||
}
|
}
|
||||||
const expected: IStatisticsChartData = {
|
const expected: IStatisticsChartData = {
|
||||||
labels: ['04/10/2021', '11/10/2021', '18/10/2021'],
|
labels: ['10/04/2021', '10/11/2021', '10/18/2021'],
|
||||||
datasets: {
|
datasets: {
|
||||||
average_speed: [
|
average_speed: [
|
||||||
{
|
{
|
||||||
@ -990,12 +1049,20 @@ describe('formatStats (duration)', () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
formatStats(inputParams, true, sports, [1], inputStats, false),
|
formatStats(
|
||||||
|
inputParams,
|
||||||
|
true,
|
||||||
|
sports,
|
||||||
|
[1],
|
||||||
|
inputStats,
|
||||||
|
false,
|
||||||
|
'MM/dd/yyyy'
|
||||||
|
),
|
||||||
expected
|
expected
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns datasets after conversion to imperial units', () => {
|
it("returns datasets when duration is 'week' and date format 'dd/MM/yyyy'", () => {
|
||||||
const inputStats: TStatisticsFromApi = {
|
const inputStats: TStatisticsFromApi = {
|
||||||
'2021-10-03': {
|
'2021-10-03': {
|
||||||
1: {
|
1: {
|
||||||
@ -1043,6 +1110,227 @@ describe('formatStats (duration)', () => {
|
|||||||
}
|
}
|
||||||
const expected: IStatisticsChartData = {
|
const expected: IStatisticsChartData = {
|
||||||
labels: ['03/10/2021', '10/10/2021', '17/10/2021'],
|
labels: ['03/10/2021', '10/10/2021', '17/10/2021'],
|
||||||
|
datasets: {
|
||||||
|
average_speed: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
borderColor: ['#4c9792'],
|
||||||
|
data: [12, 18, null],
|
||||||
|
type: 'line',
|
||||||
|
spanGaps: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
nb_workouts: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
data: [1, 1, 0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
total_distance: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
data: [10, 15, 0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
total_duration: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
data: [3000, 3500, 0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
total_ascent: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
data: [150, 250, 0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
total_descent: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
data: [100, 150, 0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.deepEqual(
|
||||||
|
formatStats(
|
||||||
|
inputParams,
|
||||||
|
false,
|
||||||
|
sports,
|
||||||
|
[1],
|
||||||
|
inputStats,
|
||||||
|
false,
|
||||||
|
'dd/MM/yyyy'
|
||||||
|
),
|
||||||
|
expected
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns datasets when duration is 'week' and date format is 'date_string'", () => {
|
||||||
|
locale.value = 'fr'
|
||||||
|
const inputStats: TStatisticsFromApi = {
|
||||||
|
'2021-10-03': {
|
||||||
|
1: {
|
||||||
|
average_speed: 12,
|
||||||
|
nb_workouts: 1,
|
||||||
|
total_distance: 10,
|
||||||
|
total_duration: 3000,
|
||||||
|
total_ascent: 150,
|
||||||
|
total_descent: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'2021-10-10': {
|
||||||
|
1: {
|
||||||
|
average_speed: 18,
|
||||||
|
nb_workouts: 1,
|
||||||
|
total_distance: 15,
|
||||||
|
total_duration: 3500,
|
||||||
|
total_ascent: 250,
|
||||||
|
total_descent: 150,
|
||||||
|
},
|
||||||
|
2: {
|
||||||
|
average_speed: 24,
|
||||||
|
nb_workouts: 2,
|
||||||
|
total_distance: 20,
|
||||||
|
total_duration: 3000,
|
||||||
|
total_ascent: 150,
|
||||||
|
total_descent: 200,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'2021-10-17': {
|
||||||
|
3: {
|
||||||
|
average_speed: 8.64,
|
||||||
|
nb_workouts: 2,
|
||||||
|
total_distance: 20,
|
||||||
|
total_duration: 3000,
|
||||||
|
total_ascent: 100,
|
||||||
|
total_descent: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const inputParams = {
|
||||||
|
duration: 'week',
|
||||||
|
start: new Date('October 03, 2021 00:00:00'),
|
||||||
|
end: new Date('October 23, 2021 23:59:59.999'),
|
||||||
|
}
|
||||||
|
const expected: IStatisticsChartData = {
|
||||||
|
labels: ['3 oct. 2021', '10 oct. 2021', '17 oct. 2021'],
|
||||||
|
datasets: {
|
||||||
|
average_speed: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
borderColor: ['#4c9792'],
|
||||||
|
data: [12, 18, null],
|
||||||
|
type: 'line',
|
||||||
|
spanGaps: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
nb_workouts: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
data: [1, 1, 0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
total_distance: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
data: [10, 15, 0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
total_duration: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
data: [3000, 3500, 0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
total_ascent: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
data: [150, 250, 0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
total_descent: [
|
||||||
|
{
|
||||||
|
label: 'Cycling (Sport)',
|
||||||
|
backgroundColor: ['#4c9792'],
|
||||||
|
data: [100, 150, 0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.deepEqual(
|
||||||
|
formatStats(
|
||||||
|
inputParams,
|
||||||
|
false,
|
||||||
|
sports,
|
||||||
|
[1],
|
||||||
|
inputStats,
|
||||||
|
false,
|
||||||
|
'date_string'
|
||||||
|
),
|
||||||
|
expected
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns datasets after conversion to imperial units', () => {
|
||||||
|
const inputStats: TStatisticsFromApi = {
|
||||||
|
'2021-10-03': {
|
||||||
|
1: {
|
||||||
|
average_speed: 12,
|
||||||
|
nb_workouts: 1,
|
||||||
|
total_distance: 10,
|
||||||
|
total_duration: 3000,
|
||||||
|
total_ascent: 150,
|
||||||
|
total_descent: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'2021-10-10': {
|
||||||
|
1: {
|
||||||
|
average_speed: 18,
|
||||||
|
nb_workouts: 1,
|
||||||
|
total_distance: 15,
|
||||||
|
total_duration: 3500,
|
||||||
|
total_ascent: 250,
|
||||||
|
total_descent: 150,
|
||||||
|
},
|
||||||
|
2: {
|
||||||
|
average_speed: 24,
|
||||||
|
nb_workouts: 2,
|
||||||
|
total_distance: 20,
|
||||||
|
total_duration: 3000,
|
||||||
|
total_ascent: 150,
|
||||||
|
total_descent: 200,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'2021-10-17': {
|
||||||
|
3: {
|
||||||
|
average_speed: 8.64,
|
||||||
|
nb_workouts: 2,
|
||||||
|
total_distance: 20,
|
||||||
|
total_duration: 3000,
|
||||||
|
total_ascent: 100,
|
||||||
|
total_descent: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const inputParams = {
|
||||||
|
duration: 'week',
|
||||||
|
start: new Date('October 03, 2021 00:00:00'),
|
||||||
|
end: new Date('October 23, 2021 23:59:59.999'),
|
||||||
|
}
|
||||||
|
const expected: IStatisticsChartData = {
|
||||||
|
labels: ['10/03/2021', '10/10/2021', '10/17/2021'],
|
||||||
datasets: {
|
datasets: {
|
||||||
average_speed: [
|
average_speed: [
|
||||||
{
|
{
|
||||||
@ -1092,7 +1380,15 @@ describe('formatStats (duration)', () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
formatStats(inputParams, false, sports, [1], inputStats, true),
|
formatStats(
|
||||||
|
inputParams,
|
||||||
|
false,
|
||||||
|
sports,
|
||||||
|
[1],
|
||||||
|
inputStats,
|
||||||
|
true,
|
||||||
|
'MM/dd/yyyy'
|
||||||
|
),
|
||||||
expected
|
expected
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user