import { Data } from "../interfaces" ; var log = require ( "loglevel" ) . getLogger ( "phases-log" ) ; const calcProgressions = ( data ) : Data => { const { parameters , startPath , endPath } = data ; const numOfPhases = parameters . phases . length ; var progressionsPhaseScope = Array ( numOfPhases ) ; var progressionsGeneralScope = Array ( numOfPhases ) ; var progressions = [ ] ; var durations = [ ] ; for ( let i = 0 ; i < numOfPhases ; i ++ ) { const duration = parameters . phases [ i ] . duration ( { startPath , endPath , prevDurations : durations } ) ; durations . push ( duration ) ; progressionsPhaseScope [ i ] = parameters . phases [ i ] . progressionsPhaseScope ( { startPath , endPath , duration } ) ; const prevPhaseProgressions = i && progressionsGeneralScope [ i - 1 ] ; progressionsGeneralScope [ i ] = parameters . phases [ i ] . progressionsGeneralScope ( { startPath , endPath , duration , prevPhaseProgressions } ) ; for ( let keyVertexIndex = 0 ; keyVertexIndex < progressionsGeneralScope [ i ] . length ; keyVertexIndex ++ ) progressions . push ( progressionsGeneralScope [ i ] [ keyVertexIndex ] ) ; } log . debug ( "progressions phase scope" , progressionsPhaseScope ) ; log . debug ( "progressions general scope" , progressionsGeneralScope ) ; progressions = progressions . sort ( ( a , b ) => a - b ) ; let i = 1 ; while ( i < progressions . length ) { if ( progressions [ i - 1 ] === progressions [ i ] ) progressions . splice ( i , 1 ) ; else i += 1 ; } log . debug ( "progressions" , progressions ) ; return { ... data , progressions , progressionsGeneralScope , progressionsPhaseScope } ; } ; export default calcProgressions ;