import { ActivitySourceDataModel , ActivityStreamsModel , AnalysisDataModel , AthleteSettingsModel , AthleteSnapshotModel , Gender , UserSettingsModel } from "@elevate/shared/models" ; import { ActivityComputer } from "../../../scripts/processors/activity-computer" ; import * as _ from "lodash" ; const expectBetween = ( expectValue , toEqual , tolerance ) => { const lowerOk = toEqual - tolerance ; const higherOk = toEqual + tolerance ; const isBetween = ( lowerOk <= expectValue && expectValue <= higherOk ) ; expect ( isBetween ) . toBeTruthy ( "Expected '" + expectValue + "' to equals '" + toEqual + "' is not between min: '" + ( lowerOk ) + "' and max: '" + ( higherOk ) + "'.\r\n=> Lower: " + lowerOk + " <= expected: " + expectValue + " <= higher: " + higherOk ) ; } ; describe ( "ActivityComputer Cycling Power" , ( ) => { const activityType = "Ride" ; const isTrainer = false ; const isOwner = true ; const bounds = null ; const returnZones = false ; const userSettingsMock = _ . cloneDeep ( require ( "../../fixtures/user-settings/2470979.json" ) ) ; const athleteSnapshot = new AthleteSnapshotModel ( Gender . MEN , new AthleteSettingsModel ( 200 , 45 , null , 240 , null , null , 71.9 ) ) ; const activitySourceData = { movingTime : - 1 , elevation : - 1 , distance : - 1 } ; let TOLERANCE ; beforeEach ( ( ) => { TOLERANCE = 5 ; } ) ; it ( "should compute REAL power data as ESTIMATED of activity 1109968202 (IM Canada Bike)" , ( done ) => { const hasPowerMeter = true ; const stream = _ . cloneDeep ( require ( "../../fixtures/activities/1109968202/stream.json" ) ) ; athleteSnapshot . athleteSettings . cyclingFtp = 288 ; const activityComputer = new ActivityComputer ( activityType , isTrainer , userSettingsMock , athleteSnapshot , isOwner , hasPowerMeter , activitySourceData , stream , bounds , returnZones ) ; const result = activityComputer . compute ( ) ; expectBetween ( result . powerData . avgWatts , 180 , TOLERANCE ) ; expectBetween ( _ . floor ( result . powerData . weightedPower ) , 193 , TOLERANCE ) ; expectBetween ( _ . floor ( result . powerData . best20min ) , 223 , TOLERANCE ) ; done ( ) ; } ) ; it ( "should compute REAL power data as ESTIMATED of activity 1302129959 (20-minute FTP test. First time ever!, result not bad!)" , ( done ) => { const hasPowerMeter = true ; const stream = _ . cloneDeep ( require ( "../../fixtures/activities/1302129959/stream.json" ) ) ; athleteSnapshot . athleteSettings . cyclingFtp = 380 ; const activityComputer = new ActivityComputer ( activityType , isTrainer , userSettingsMock , athleteSnapshot , isOwner , hasPowerMeter , activitySourceData , stream , bounds , returnZones ) ; const result = activityComputer . compute ( ) ; expectBetween ( result . powerData . avgWatts , 208 , TOLERANCE ) ; expectBetween ( _ . floor ( result . powerData . weightedPower ) , 265 , TOLERANCE ) ; expectBetween ( _ . floor ( result . powerData . best20min ) , 380 , TOLERANCE ) ; done ( ) ; } ) ; it ( "should compute ESTIMATED power data of activity 343080886 (Alpe d'Huez)" , ( done ) => { const hasPowerMeter = false ; const stream = _ . cloneDeep ( require ( "../../fixtures/activities/343080886/stream.json" ) ) ; stream . watts = stream . watts_calc ; athleteSnapshot . athleteSettings . cyclingFtp = 260 ; athleteSnapshot . athleteSettings . maxHr = 205 ; athleteSnapshot . athleteSettings . restHr = 55 ; const activityComputer = new ActivityComputer ( activityType , isTrainer , userSettingsMock , athleteSnapshot , isOwner , hasPowerMeter , activitySourceData , stream , bounds , returnZones ) ; const result = activityComputer . compute ( ) ; expectBetween ( _ . floor ( result . powerData . avgWatts ) , 175 , TOLERANCE ) ; expectBetween ( _ . floor ( result . powerData . best20min ) , 253 , TOLERANCE ) ; done ( ) ; } ) ; it ( "should compute ESTIMATED power data of activity 600329531 (Sheep Ride)" , ( done ) => { const hasPowerMeter = false ; const stream = _ . cloneDeep ( require ( "../../fixtures/activities/600329531/stream.json" ) ) ; stream . watts = stream . watts_calc ; athleteSnapshot . athleteSettings . cyclingFtp = 239 ; const activityComputer = new ActivityComputer ( activityType , isTrainer , userSettingsMock , athleteSnapshot , isOwner , hasPowerMeter , activitySourceData , stream , bounds , returnZones ) ; const result = activityComputer . compute ( ) ; expectBetween ( _ . floor ( result . powerData . avgWatts ) , 178 , TOLERANCE ) ; expectBetween ( _ . floor ( result . powerData . best20min ) , 224 , TOLERANCE ) ; done ( ) ; } ) ; it ( "should compute ESTIMATED power data of activity 597999523 (4 Seigneurs x Vik + Murianette x Philippe)" , ( done ) => { const hasPowerMeter = false ; const stream = _ . cloneDeep ( require ( "../../fixtures/activities/597999523/stream.json" ) ) ; stream . watts = stream . watts_calc ; const activityComputer = new ActivityComputer ( activityType , isTrainer , userSettingsMock , athleteSnapshot , isOwner , hasPowerMeter , activitySourceData , stream , bounds , returnZones ) ; const result = activityComputer . compute ( ) ; expectBetween ( _ . floor ( result . powerData . avgWatts ) , 142 , TOLERANCE ) ; expect ( result . powerData . weightedPower > _ . floor ( result . powerData . avgWatts ) ) . toBeTruthy ( ) ; expect ( result . powerData . best20min > _ . floor ( result . powerData . avgWatts ) ) . toBeTruthy ( ) ; done ( ) ; } ) ; it ( "should compute ESTIMATED power data of activity 1610385844 (#ComeBack - 10 / 43km / 96min / 142HrSS)" , ( done ) => { const hasPowerMeter = false ; const stream = _ . cloneDeep ( require ( "../../fixtures/activities/1610385844/stream.json" ) ) ; stream . watts = stream . watts_calc ; athleteSnapshot . athleteSettings . cyclingFtp = 130 ; const activityComputer = new ActivityComputer ( activityType , isTrainer , userSettingsMock , athleteSnapshot , isOwner , hasPowerMeter , activitySourceData , stream , bounds , returnZones ) ; const result = activityComputer . compute ( ) ; expectBetween ( _ . floor ( result . powerData . avgWatts ) , 118 , TOLERANCE ) ; expectBetween ( _ . floor ( result . powerData . best20min ) , 145 , TOLERANCE ) ; done ( ) ; } ) ; it ( "should compute ESTIMATED power data of activity 1811220111 (Brötchen suchen im Hanftal, echte 632Hm)" , ( done ) => { const hasPowerMeter = false ; const stream = _ . cloneDeep ( require ( "../../fixtures/activities/1811220111/stream.json" ) ) ; stream . watts = stream . watts_calc ; const activityComputer = new ActivityComputer ( activityType , isTrainer , userSettingsMock , athleteSnapshot , isOwner , hasPowerMeter , activitySourceData , stream , bounds , returnZones ) ; const result = activityComputer . compute ( ) ; expectBetween ( _ . floor ( result . powerData . avgWatts ) , 200 , TOLERANCE ) ; expect ( result . powerData . weightedPower > _ . floor ( result . powerData . avgWatts ) ) . toBeTruthy ( ) ; expect ( result . powerData . best20min > _ . floor ( result . powerData . avgWatts ) ) . toBeTruthy ( ) ; done ( ) ; } ) ; it ( "should compute ESTIMATED power data of activity 1817318910" , ( done ) => { const hasPowerMeter = false ; const stream = _ . cloneDeep ( require ( "../../fixtures/activities/1817318910/stream.json" ) ) ; stream . watts = stream . watts_calc ; const activityComputer = new ActivityComputer ( activityType , isTrainer , userSettingsMock , athleteSnapshot , isOwner , hasPowerMeter , activitySourceData , stream , bounds , returnZones ) ; const result = activityComputer . compute ( ) ; expectBetween ( _ . floor ( result . powerData . avgWatts ) , 134 , TOLERANCE ) ; expect ( result . powerData . weightedPower > _ . floor ( result . powerData . avgWatts ) ) . toBeTruthy ( ) ; done ( ) ; } ) ; } ) ;