import { Data } from "../interfaces" ; import { GroupParameters } from "../../path/interfaces" ; var log = require ( "loglevel" ) . getLogger ( "phases-log" ) ; const generateGroupsParameters = ( data ) : Data => { const { endPath , startPath , progressions , progressionsGeneralScope , progressionsPhaseScope } = data ; const { phases } = data . parameters ; const numOfPhases = phases . length ; var pathsGroupsParameters = Array ( progressions . length ) ; for ( let prIndex = 0 ; prIndex < progressions . length ; prIndex ++ ) { pathsGroupsParameters [ prIndex ] = [ ] ; endPath . vertexes . forEach ( ( vertex , vIndex ) => { const gIndex = vertex . group ; const { indexWithingGroup } = vertex ; var activePhaseIndex ; var keyVertexIndex ; for ( let phIndex = 0 ; phIndex < numOfPhases ; phIndex ++ ) { let phaseIsIncomplete = progressions [ prIndex ] <= progressionsGeneralScope [ phIndex ] [ vIndex ] ; if ( phaseIsIncomplete ) { const { groupsParameters } = phases [ phIndex ] ; activePhaseIndex = phIndex ; break ; } } if ( pathsGroupsParameters [ prIndex ] [ gIndex ] === undefined ) pathsGroupsParameters [ prIndex ] [ gIndex ] = { } ; var parametersSource = activePhaseIndex === undefined ? pathsGroupsParameters [ prIndex - 1 ] [ gIndex ] : phases [ activePhaseIndex ] . groupsParameters [ gIndex ] ; for ( let [ key , source ] of Object . entries ( parametersSource ) ) { let value = activePhaseIndex === undefined ? source [ indexWithingGroup ] : source ( { startPath , endPath , vertex , progression : progressions [ prIndex ] , activePhaseIndex , progressionsGeneralScope , progressionsPhaseScope } ) ; if ( pathsGroupsParameters [ prIndex ] [ gIndex ] [ key ] === undefined ) pathsGroupsParameters [ prIndex ] [ gIndex ] [ key ] = [ ] ; pathsGroupsParameters [ prIndex ] [ gIndex ] [ key ] [ indexWithingGroup ] = value ; } } ) ; } log . debug ( "paths groups parameters" , pathsGroupsParameters ) ; return { ... data , pathsGroupsParameters } ; } ; export default generateGroupsParameters ;