import * as _ from "lodash" ; import { Helper } from "../../scripts/helper" ; import { ActivitySourceDataModel , ActivityStreamsModel , AnalysisDataModel , AthleteSettingsModel , AthleteSnapshotModel , Gender , UserSettingsModel } from "@elevate/shared/models" ; import { RunningPowerEstimator } from "../../scripts/processors/running-power-estimator" ; import { ActivityComputer } from "../../scripts/processors/activity-computer" ; describe ( "RunningPowerEstimator" , ( ) => { const WATTS_TOLERANCE = 35.5 ; it ( "estimateRunningPower should provide a consistency average power compared to " + "real running power meter (based on https://www.strava.com/activities/874762067)" , ( ) => { const weightKg = 54.32 ; const meters = 6.9 * 1000 ; const totalSeconds = Helper . HHMMSStoSeconds ( "00:39:48" ) ; const elevationGain = 25 ; const expectedAvgPower = 151 ; const power = RunningPowerEstimator . estimateRunningPower ( weightKg , meters , totalSeconds , elevationGain ) ; expect ( power ) . toBeGreaterThanOrEqual ( expectedAvgPower - WATTS_TOLERANCE ) ; expect ( power ) . toBeLessThanOrEqual ( expectedAvgPower + WATTS_TOLERANCE ) ; } ) ; it ( "estimateRunningPower should provide a consistency average power compared to " + "real running power meter (based on https://www.strava.com/activities/852961332)" , ( ) => { const weightKg = 79.4 ; const meters = 12.8 * 1000 ; const totalSeconds = Helper . HHMMSStoSeconds ( "01:02:25" ) ; const elevationGain = 0 ; const expectedAvgPower = 287 ; const power = RunningPowerEstimator . estimateRunningPower ( weightKg , meters , totalSeconds , elevationGain ) ; expect ( power ) . toBeGreaterThanOrEqual ( expectedAvgPower - WATTS_TOLERANCE ) ; expect ( power ) . toBeLessThanOrEqual ( expectedAvgPower + WATTS_TOLERANCE ) ; } ) ; it ( "estimateRunningPower should provide a consistency average power compared to " + "real running power meter (based on https://www.strava.com/activities/878683797)" , ( ) => { const weightKg = 79.4 ; const meters = 15.7 * 1000 ; const totalSeconds = Helper . HHMMSStoSeconds ( "01:14:52" ) ; const elevationGain = 148 ; const expectedAvgPower = 296 ; const power = RunningPowerEstimator . estimateRunningPower ( weightKg , meters , totalSeconds , elevationGain ) ; expect ( power ) . toBeGreaterThanOrEqual ( expectedAvgPower - WATTS_TOLERANCE ) ; expect ( power ) . toBeLessThanOrEqual ( expectedAvgPower + WATTS_TOLERANCE ) ; } ) ; it ( "estimateRunningPower should provide a consistency average power compared to " + "real running power meter (based on https://www.strava.com/activities/849522984)" , ( ) => { const weightKg = 68.94 ; const meters = 5.3 * 1000 ; const totalSeconds = Helper . HHMMSStoSeconds ( "00:30:22" ) ; const elevationGain = 64 ; const expectedAvgPower = 214 ; const power = RunningPowerEstimator . estimateRunningPower ( weightKg , meters , totalSeconds , elevationGain ) ; expect ( power ) . toBeGreaterThanOrEqual ( expectedAvgPower - WATTS_TOLERANCE ) ; expect ( power ) . toBeLessThanOrEqual ( expectedAvgPower + WATTS_TOLERANCE ) ; } ) ; it ( "estimateRunningPower should provide a consistency average power compared to " + "real running power meter (based on https://www.strava.com/activities/862889505)" , ( ) => { const weightKg = 68.94 ; const meters = 7.5 * 1000 ; const totalSeconds = Helper . HHMMSStoSeconds ( "00:44:23" ) ; const elevationGain = 56 ; const expectedAvgPower = 215 ; const power = RunningPowerEstimator . estimateRunningPower ( weightKg , meters , totalSeconds , elevationGain ) ; expect ( power ) . toBeGreaterThanOrEqual ( expectedAvgPower - WATTS_TOLERANCE ) ; expect ( power ) . toBeLessThanOrEqual ( expectedAvgPower + WATTS_TOLERANCE ) ; } ) ; it ( "estimateRunningPower should provide a consistency average power compared to " + "real running power meter (based on https://www.strava.com/activities/791460353)" , ( ) => { const weightKg = 81.61 ; const meters = 8.8 * 1000 ; const totalSeconds = Helper . HHMMSStoSeconds ( "00:41:14" ) ; const elevationGain = 32 ; const expectedAvgPower = 285 ; const power = RunningPowerEstimator . estimateRunningPower ( weightKg , meters , totalSeconds , elevationGain ) ; expect ( power ) . toBeGreaterThanOrEqual ( expectedAvgPower - WATTS_TOLERANCE ) ; expect ( power ) . toBeLessThanOrEqual ( expectedAvgPower + WATTS_TOLERANCE ) ; } ) ; it ( "estimateRunningPower should provide return zero power when totalSeconds = 0" , ( ) => { const weightKg = 54.32 ; const meters = 6.9 * 1000 ; const totalSeconds = 0 ; const elevationGain = 25 ; const expectedAvgPower = 0 ; const power = RunningPowerEstimator . estimateRunningPower ( weightKg , meters , totalSeconds , elevationGain ) ; expect ( power ) . toEqual ( expectedAvgPower ) ; } ) ; it ( "createRunningPowerEstimationStream should provide " + "power stats estimations near real running power meter  (based on https://www.strava.com/activities/874762067)" , ( ) => { const expectedPower = 151 ; const athleteWeight = 54.32 ; const stream = _ . cloneDeep ( require ( "../fixtures/activities/874762067/stream.json" ) ) ; const powerArray = RunningPowerEstimator . createRunningPowerEstimationStream ( athleteWeight , stream . distance , stream . time , stream . altitude ) ; const estimatedAvgPower = _ . mean ( powerArray ) ; expect ( estimatedAvgPower ) . not . toBeNull ( ) ; expect ( estimatedAvgPower ) . toBeGreaterThanOrEqual ( ( expectedPower - WATTS_TOLERANCE ) ) ; expect ( estimatedAvgPower ) . toBeLessThanOrEqual ( ( expectedPower + WATTS_TOLERANCE ) ) ; } ) ; it ( "createRunningPowerEstimationStream should provide " + "power stats estimations near real running power meter  (based on https://www.strava.com/activities/852961332)" , ( ) => { const expectedPower = 287 ; const athleteWeight = 79.4 ; const stream = _ . cloneDeep ( require ( "../fixtures/activities/852961332/stream.json" ) ) ; const powerArray = RunningPowerEstimator . createRunningPowerEstimationStream ( athleteWeight , stream . distance , stream . time , stream . altitude ) ; const estimatedAvgPower = _ . mean ( powerArray ) ; expect ( estimatedAvgPower ) . not . toBeNull ( ) ; expect ( estimatedAvgPower ) . toBeGreaterThanOrEqual ( ( expectedPower - WATTS_TOLERANCE ) ) ; expect ( estimatedAvgPower ) . toBeLessThanOrEqual ( ( expectedPower + WATTS_TOLERANCE ) ) ; } ) ; it ( "createRunningPowerEstimationStream should provide " + "power stats estimations near real running power meter" + "based on https://www.strava.com/activities/878683797" , ( ) => { const expectedPower = 296 ; const athleteWeight = 79.4 ; const stream = _ . cloneDeep ( require ( "../fixtures/activities/878683797/stream.json" ) ) ; const powerArray = RunningPowerEstimator . createRunningPowerEstimationStream ( athleteWeight , stream . distance , stream . time , stream . altitude ) ; const estimatedAvgPower = _ . mean ( powerArray ) ; expect ( estimatedAvgPower ) . not . toBeNull ( ) ; expect ( estimatedAvgPower ) . toBeGreaterThanOrEqual ( ( expectedPower - WATTS_TOLERANCE ) ) ; expect ( estimatedAvgPower ) . toBeLessThanOrEqual ( ( expectedPower + WATTS_TOLERANCE ) ) ; } ) ; it ( "createRunningPowerEstimationStream should provide " + "power stats estimations near real running power meter" + "based on https://www.strava.com/activities/833008371" , ( ) => { const expectedPower = 310 ; const athleteWeight = 79.4 ; const stream = _ . cloneDeep ( require ( "../fixtures/activities/833008371/stream.json" ) ) ; const powerArray = RunningPowerEstimator . createRunningPowerEstimationStream ( athleteWeight , stream . distance , stream . time , stream . altitude ) ; const estimatedAvgPower = _ . mean ( powerArray ) ; expect ( estimatedAvgPower ) . not . toBeNull ( ) ; expect ( estimatedAvgPower ) . toBeGreaterThanOrEqual ( ( expectedPower - WATTS_TOLERANCE ) ) ; expect ( estimatedAvgPower ) . toBeLessThanOrEqual ( ( expectedPower + WATTS_TOLERANCE ) ) ; } ) ; it ( "should compute correctly '1/2 NCNR Run Club' @ https://www.strava.com/activities/874762067" , ( done ) => { const expectedPower = 151 ; const athleteWeight = 54.32 ; const stream = _ . cloneDeep ( require ( "../fixtures/activities/874762067/stream.json" ) ) ; const powerArray = RunningPowerEstimator . createRunningPowerEstimationStream ( athleteWeight , stream . distance , stream . time , stream . altitude ) ; const estimatedAvgPower = _ . mean ( powerArray ) ; expect ( estimatedAvgPower ) . not . toBeNull ( ) ; expect ( estimatedAvgPower ) . toBeGreaterThanOrEqual ( ( expectedPower - WATTS_TOLERANCE ) ) ; expect ( estimatedAvgPower ) . toBeLessThanOrEqual ( ( expectedPower + WATTS_TOLERANCE ) ) ; done ( ) ; } ) ; it ( "should compute correctly 'Begin Running Ep 1 // Stade 40min' " + "@ https://www.strava.com/activities/887284960" , ( done ) => { const activityType = "Run" ; const isTrainer = false ; const isOwner = true ; const hasPowerMeter = false ; const bounds = null ; const returnZones = true ; const userSettingsMock = _ . cloneDeep ( require ( "../fixtures/user-settings/2470979.json" ) ) ; const stream = _ . cloneDeep ( require ( "../fixtures/activities/887284960/stream.json" ) ) ; const activitySourceData = { movingTime : - 1 , elevation : - 1 , distance : - 1 } ; const athleteSnapshot = new AthleteSnapshotModel ( Gender . MEN , new AthleteSettingsModel ( 200 , 45 , null , 240 , null , null , 71.9 ) ) ; const activityComputer = new ActivityComputer ( activityType , isTrainer , userSettingsMock , athleteSnapshot , isOwner , hasPowerMeter , activitySourceData , stream , bounds , returnZones ) ; const result = activityComputer . compute ( ) ; expect ( result . powerData ) . not . toBeNull ( ) ; done ( ) ; } ) ; } ) ;