import * as _ from "lodash" ; import { Helper } from "../../../helper" ; import { ActivityInfoModel , AnalysisDataModel , SpeedUnitDataModel , UserSettingsModel } from "@elevate/shared/models" ; import { AbstractDataView } from "./abstract-data.view" ; export class FeaturedDataView extends AbstractDataView { protected analysisData : AnalysisDataModel ; protected activityInfo : ActivityInfoModel ; protected userSettings : UserSettingsModel ; constructor ( analysisData , userSettings , activityInfo ) { super ( null ) ; this . hasGraph = false ; this . analysisData = analysisData ; this . userSettings = userSettings ; this . activityInfo = activityInfo ; if ( ! this . analysisData || ! this . userSettings ) { console . error ( "analysisData and userSettingsData are required" ) ; } if ( this . isSegmentEffortView && ! _ . isEmpty ( this . activityInfo . segmentEffort ) ) { this . mainColor = [ 252 , 76 , 2 ] ; } } public render ( ) { if ( this . analysisData . moveRatio && this . userSettings . displayActivityRatio || this . analysisData . speedData && this . userSettings . displayAdvancedSpeedData || this . analysisData . heartRateData && this . userSettings . displayAdvancedHrData || this . analysisData . powerData && this . userSettings . displayAdvancedPowerData || this . analysisData . gradeData && this . userSettings . displayAdvancedGradeData ) { this . makeGrid ( 7 , 1 ) ; this . insertDataIntoGrid ( ) ; this . content += "<div class=\"featuredData\">" + this . grid . html ( ) + "</div>" ; } } protected insertDataIntoGrid ( ) { const speedUnitsData = Helper . getSpeedUnitData ( window . currentAthlete . get ( "measurement_preference" ) ) ; if ( this . analysisData . moveRatio && this . userSettings . displayActivityRatio && _ . isEmpty ( this . activityInfo . segmentEffort ) ) { this . insertContentAtGridPosition ( 0 , 0 , this . printNumber ( this . analysisData . moveRatio , 2 ) , "Move Ratio" , "" , "displayActivityRatio" ) ; } if ( this . analysisData . speedData && this . userSettings . displayAdvancedSpeedData ) { this . insertContentAtGridPosition ( 1 , 0 , this . printNumber ( ( this . analysisData . speedData . upperQuartileSpeed * speedUnitsData . speedUnitFactor ) , 1 ) , "75% Quartile Speed" , speedUnitsData . speedUnitPerHour , "displayAdvancedSpeedData" ) ; } if ( this . analysisData . heartRateData && this . userSettings . displayAdvancedHrData ) { this . insertContentAtGridPosition ( 2 , 0 , this . printNumber ( this . analysisData . heartRateData . HRSS , 0 ) , "HRSS" , "" , "displayAdvancedHrData" ) ; this . insertContentAtGridPosition ( 3 , 0 , this . printNumber ( this . analysisData . heartRateData . HRSSPerHour , 1 ) , "HRSS / Hour" , "" , "displayAdvancedHrData" ) ; } if ( this . analysisData . powerData && this . userSettings . displayAdvancedPowerData ) { if ( _ . isNumber ( this . analysisData . powerData . best20min ) && ! this . isSegmentEffortView ) { let label = "Best 20min Power" ; if ( ! this . analysisData . powerData . hasPowerMeter ) { label = "Estimated " + label ; } this . insertContentAtGridPosition ( 4 , 0 , this . printNumber ( this . analysisData . powerData . best20min , 0 ) , label , "w" , "displayAdvancedPowerData" ) ; } if ( _ . isNumber ( this . analysisData . powerData . weightedWattsPerKg ) ) { let label = "Weighted Watts/kg" ; if ( ! this . analysisData . powerData . hasPowerMeter ) { label = "Estimated " + label ; } this . insertContentAtGridPosition ( 5 , 0 , this . printNumber ( this . analysisData . powerData . weightedWattsPerKg , 2 ) , label , "w/kg" , "displayAdvancedPowerData" ) ; } } if ( this . analysisData . gradeData && this . userSettings . displayAdvancedGradeData ) { this . insertContentAtGridPosition ( 6 , 0 , this . analysisData . gradeData . gradeProfile , "Grade Profile" , "" , "displayAdvancedGradeData" ) ; } this . grid . find ( "td:empty" ) . remove ( ) ; } }