diff --git a/src/app/simulator/access-and-offer/collaboration-scheme/services/collaboration-scheme.service.ts b/src/app/simulator/access-and-offer/collaboration-scheme/services/collaboration-scheme.service.ts index 448ed7b2ab109b71cf4ac35ab5a50d2a59bfa638..59194ae5b64b14cce88bc9f640006628c1f86382 100644 --- a/src/app/simulator/access-and-offer/collaboration-scheme/services/collaboration-scheme.service.ts +++ b/src/app/simulator/access-and-offer/collaboration-scheme/services/collaboration-scheme.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import { map } from 'rxjs/operators'; +import { map, switchMap } from 'rxjs/operators'; import * as _ from 'lodash'; import { Functionality } from '../../../../shared/entities/functionality/functionality'; @@ -35,65 +35,69 @@ export class CollaborationSchemeService implements NavigableComponentService { collaborationScheme.totalCurrentPublicEnrollment = 0; collaborationScheme.totalProposalPublicEnrollment = 0; - return this.utilitiesService.getStages().pipe( - map(stages => { - collaborationSchemesByStage = stages.map(stage => new CollaborationSchemesByStage({ - id: stage.id, - stageDescription: stage.description, - numberCurrentPublicEnrollment: 0, - numberProposalPublicEnrollment: 0, - federalPercentage: 0, - statePercentage: 0, - municipalPercentage: 0 - })); + return this.getEnrollmentT4().pipe( + switchMap(enrollmentT4 => { + return this.utilitiesService.getStages().pipe( + map(stages => { + collaborationSchemesByStage = stages.map(stage => new CollaborationSchemesByStage({ + id: stage.id, + stageDescription: stage.description, + numberCurrentPublicEnrollment: 0, + numberProposalPublicEnrollment: 0, + federalPercentage: 0, + statePercentage: 0, + municipalPercentage: 0 + })); - const enrollmentOfferYear: number = this.currentYearService.getEnrollmentCurrentYear(); + const resultForEnrollmentProjection: EnrollmentProjection = this.sessionService.getItem<EnrollmentProjection>(Functionality.enrollmentProjection.key); + const enrollmentOfferYear: number = this.currentYearService.getEnrollmentCurrentYear(); - collaborationScheme.yearCurrentPublicEnrollment = enrollmentOfferYear; - collaborationScheme.yearProposalPublicEnrollment = enrollmentOfferYear + 1; + collaborationScheme.yearCurrentPublicEnrollment = enrollmentOfferYear; + collaborationScheme.yearProposalPublicEnrollment = enrollmentOfferYear + 1; - const resultForEnrollmentProjection: EnrollmentProjection = this.sessionService.getItem<EnrollmentProjection>(Functionality.enrollmentProjection.key); - const resultForViewEnrollmentProjection: ViewEnrollmentByStageSeries = - this.sessionService.getItem<ViewEnrollmentByStageSeries>(Functionality.viewEnrollmentByStageAndSeries.key); - const resultForSelectLocation: SelectLocation = this.sessionService.getItem<SelectLocation>(Functionality.selectLocation.key); + for (const stage of stages) { - for (const stage of stages) { + const collaboration: CollaborationSchemesByStage = _.find(collaborationSchemesByStage, c => c.id === stage.id); + const stagesAdmDependencyLocationEnrollments = _.filter(enrollmentT4, s => s.education_level_short_id === stage.id); - const collaboration: CollaborationSchemesByStage = _.find(collaborationSchemesByStage, c => c.id === stage.id); + const enrollmentsByAdmDependencyFederal = _.find(stagesAdmDependencyLocationEnrollments, t => t.adm_dependency_id === AdmDependency.Federal); + const enrollmentsByAdmDependencyState = _.find(stagesAdmDependencyLocationEnrollments, t => t.adm_dependency_id === AdmDependency.State); + const enrollmentsByAdmDependencyMunicipal = _.find(stagesAdmDependencyLocationEnrollments, t => t.adm_dependency_id === AdmDependency.Municipal); - const stagesAdmDependencyLocationEnrollments = _.find(resultForViewEnrollmentProjection.stagesAdmDependencyLocationEnrollments, s => s.id === stage.id); + const totalEnrollmentsByAdmDependencyFederal = enrollmentsByAdmDependencyFederal ? enrollmentsByAdmDependencyFederal.total : 0; + const totalEnrollmentsByAdmDependencyState = enrollmentsByAdmDependencyState ? enrollmentsByAdmDependencyState.total : 0; + const totalEnrollmentsByAdmDependencyMunicipal = enrollmentsByAdmDependencyMunicipal ? enrollmentsByAdmDependencyMunicipal.total : 0; - const totalEnrollmentsByAdmDependencyFederal = _.find(stagesAdmDependencyLocationEnrollments.totalEnrollmentsByAdmDependency, t => t.id === AdmDependency.Federal); - const totalEnrollmentsByAdmDependencyState = _.find(stagesAdmDependencyLocationEnrollments.totalEnrollmentsByAdmDependency, t => t.id === AdmDependency.State); - const totalEnrollmentsByAdmDependencyMunicipal = _.find(stagesAdmDependencyLocationEnrollments.totalEnrollmentsByAdmDependency, t => t.id === AdmDependency.Municipal); - const totalCurrentPublicEnrollment = (totalEnrollmentsByAdmDependencyFederal.quantity + totalEnrollmentsByAdmDependencyState.quantity + totalEnrollmentsByAdmDependencyMunicipal.quantity); + const totalCurrentPublicEnrollment = + (totalEnrollmentsByAdmDependencyFederal + totalEnrollmentsByAdmDependencyState + totalEnrollmentsByAdmDependencyMunicipal); - if (collaboration) { - const enrollmentProjectionByLocation: EnrollmentProjectionByLocation = _.head(resultForEnrollmentProjection.enrollmentsProjectionsByLocations); + if (collaboration) { + const enrollmentProjectionByLocation: EnrollmentProjectionByLocation = _.head(resultForEnrollmentProjection.enrollmentsProjectionsByLocations); - const stageEnrollment = _.find(enrollmentProjectionByLocation.stagesEnrollments, r => r.id === stage.id); + const stageEnrollment = _.find(enrollmentProjectionByLocation.stagesEnrollments, r => r.id === stage.id); - if (stageEnrollment) { - collaboration.numberCurrentPublicEnrollment = stageEnrollment.totalCurrentOffers; + if (stageEnrollment) { + collaboration.numberCurrentPublicEnrollment = totalCurrentPublicEnrollment; - const stagesEnrollmentsProposal = _.find(enrollmentProjectionByLocation.stagesEnrollments, r => r.id === stage.id); - collaboration.numberProposalPublicEnrollment = - _.find(stagesEnrollmentsProposal.totalEnrollments, s => s.year === collaborationScheme.yearProposalPublicEnrollment).quantity; + const stagesEnrollmentsProposal = _.find(enrollmentProjectionByLocation.stagesEnrollments, r => r.id === stage.id); + collaboration.numberProposalPublicEnrollment = + _.find(stagesEnrollmentsProposal.totalEnrollments, s => s.year === collaborationScheme.yearProposalPublicEnrollment).quantity; - collaboration.federalPercentage = ((totalEnrollmentsByAdmDependencyFederal.quantity / totalCurrentPublicEnrollment) * 100); - collaboration.statePercentage = ((totalEnrollmentsByAdmDependencyState.quantity / totalCurrentPublicEnrollment) * 100); - collaboration.municipalPercentage = ((totalEnrollmentsByAdmDependencyMunicipal.quantity / totalCurrentPublicEnrollment) * 100); - } + collaboration.federalPercentage = ((totalEnrollmentsByAdmDependencyFederal / totalCurrentPublicEnrollment) * 100); + collaboration.statePercentage = ((totalEnrollmentsByAdmDependencyState / totalCurrentPublicEnrollment) * 100); + collaboration.municipalPercentage = ((totalEnrollmentsByAdmDependencyMunicipal / totalCurrentPublicEnrollment) * 100); + } - } + } - collaborationScheme.collaborationSchemeByStage.push(collaboration); - collaborationScheme.totalCurrentPublicEnrollment = collaborationScheme.collaborationSchemeByStage.reduce((prevVal, elem) => prevVal + elem.numberCurrentPublicEnrollment, 0); - collaborationScheme.totalProposalPublicEnrollment = collaborationScheme.collaborationSchemeByStage.reduce((prevVal, elem) => prevVal + elem.numberProposalPublicEnrollment, 0); - } - collaborationScheme.sourceInformations = this.getSourceInformations(); - return collaborationScheme; + collaborationScheme.collaborationSchemeByStage.push(collaboration); + collaborationScheme.totalCurrentPublicEnrollment = collaborationScheme.collaborationSchemeByStage.reduce((prevVal, elem) => prevVal + elem.numberCurrentPublicEnrollment, 0); + collaborationScheme.totalProposalPublicEnrollment = collaborationScheme.collaborationSchemeByStage.reduce((prevVal, elem) => prevVal + elem.numberProposalPublicEnrollment, 0); + } + collaborationScheme.sourceInformations = this.getSourceInformations(); + return collaborationScheme; + })); })); } @@ -111,4 +115,27 @@ export class CollaborationSchemeService implements NavigableComponentService { })); return footNotes; } + + getEnrollmentT4(): Observable<any> { + + const url: string = `${this.httpService.apiEndpointV1}/enrollment?dims=education_level_short,adm_dependency`; + let filtersLocation: Array<string> = new Array<string>(); + const enrollmentCurrentYear: number = this.currentYearService.getEnrollmentCurrentYear(); + + filtersLocation = this.utilitiesService.getSelectLocationFilter(); + + let filters: Array<string> = new Array<string>( + `min_year:"${enrollmentCurrentYear}"`, + `max_year:"${enrollmentCurrentYear}"`, + `adm_dependency:["1","2","3"]` + ); + + filters = filters.concat(filtersLocation); + + const options: any = this.httpService.getRequestOptionsWithSearchParams(new Map<string, string>([['filter', filters.join(',')]])); + + return this.httpService.get<Array<any>>(`${url}`, options).pipe( + map(diagnosticT4 => diagnosticT4)); + } + } diff --git a/src/app/simulator/quality-conditions/offer-goal-enrollment-full-time/services/offer-goal-enrollment-full-time.service.ts b/src/app/simulator/quality-conditions/offer-goal-enrollment-full-time/services/offer-goal-enrollment-full-time.service.ts index d36ea246743aa5f47cbc6fbe5a4023501bab8a95..4e6094ee065769f9eb7edb5e5e00d448a57aa779 100644 --- a/src/app/simulator/quality-conditions/offer-goal-enrollment-full-time/services/offer-goal-enrollment-full-time.service.ts +++ b/src/app/simulator/quality-conditions/offer-goal-enrollment-full-time/services/offer-goal-enrollment-full-time.service.ts @@ -57,7 +57,7 @@ export class OfferGoalEnrollmentFullTimeService implements NavigableComponentSer for (let i = 0; i < diagnostic.length; i++) { for (let j = 0; j < fullTimes.length; j++) { if (fullTimes[j].id === diagnostic[i].education_level_short_id) { - const enrollmentStage = _.find(enrollmentT4, rEP => rEP.education_level_mod_name === fullTimes[j].stageDescription); + const enrollmentStage = _.find(enrollmentT4, rEP => rEP.education_level_short_id === fullTimes[j].id); fullTimes[j].diagnostic = enrollmentStage.total > 0 ? ((diagnostic[i].total / enrollmentStage.total) * 100) : undefined; } @@ -97,7 +97,7 @@ export class OfferGoalEnrollmentFullTimeService implements NavigableComponentSer getEnrollmentT4(): Observable<any> { - const url: string = `${this.httpService.apiEndpointV1}/enrollment?dims=education_level_mod`; + const url: string = `${this.httpService.apiEndpointV1}/enrollment?dims=education_level_short`; let filtersLocation: Array<string> = new Array<string>(); const enrollmentCurrentYear: number = this.currentYearService.getEnrollmentCurrentYear();