| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import {HttpClient} from '@angular/common/http';
- import {Injectable} from '@angular/core';
- import {HsUtilsService} from 'hslayers-ng/components/utils/utils.service';
- // import attractivity from '../Attractivity.json';
- import nuts from '../nuts';
- @Injectable({providedIn: 'root'})
- export class AdjusterService {
- nutsCodeRecordRelations = {};
- factors: any = [
- {
- name: 'Natural',
- column: 'N_index',
- weight: 1,
- },
- {
- name: 'Social & Human',
- column: 'S_index',
- weight: 1,
- },
- {
- name: 'Anthropic',
- column: 'A_index',
- weight: 1,
- },
- {
- name: 'Economical',
- column: 'E_index',
- weight: 1,
- },
- {
- name: 'Cultural',
- column: 'C_index',
- weight: 1,
- },
- {
- name: 'Institutional',
- column: 'I_index',
- weight: 1,
- },
- ];
- constructor(public HsUtilsService: HsUtilsService, public $http: HttpClient) {
- this.$http
- .get('https://publish.lesprojekt.cz/nodejs/datasets')
- .toPromise()
- .then((response: any) => {
- this.factors = response.data.map((dataset) => {
- return {factor: dataset.Factor, weight: 1, datasets: []};
- });
- this.factors = HsUtilsService.removeDuplicates(this.factors, 'factor');
- this.factors.forEach((factor) => {
- factor.datasets = response.data
- .filter((ds) => ds.Factor === factor.factor)
- .map((ds) => {
- return {
- name: ds.Name,
- included: true,
- };
- });
- });
- this.apply();
- });
- }
- apply() {
- this.HsUtilsService.debounce(
- function () {
- this.$http
- .post('https://publish.lesprojekt.cz/nodejs/scores', {
- factors: this.factors.map((f) => {
- return {
- factor: f.factor,
- weight: f.weight,
- datasets: f.datasets
- .filter((ds) => ds.included)
- .map((ds) => ds.name),
- };
- }),
- })
- .toPromise()
- .then((response: any) => {
- this.attractivity = response.data;
- let max = 0;
- this.attractivity.forEach((a) => {
- if (a.aggregate > max) {
- max = a.aggregate;
- }
- });
- const normalizer = 1 / max;
- this.attractivity.forEach((a) => {
- a.aggregate *= normalizer;
- });
- this.attractivity.forEach((a) => {
- this.nutsCodeRecordRelations[a.code] = a;
- });
- nuts.nuts3Source.forEachFeature((feature) => {
- feature.set(
- 'total',
- this.nutsCodeRecordRelations[feature.get('NUTS_ID')].aggregate
- );
- feature.set(
- 'totalForHumans',
- (
- this.nutsCodeRecordRelations[feature.get('NUTS_ID')]
- .aggregate * 100
- ).toFixed(2)
- );
- this.factors.forEach((factor) => {
- feature.set(
- factor.factor,
- (
- this.nutsCodeRecordRelations[feature.get('NUTS_ID')][
- factor.factor
- ] * 100
- ).toFixed(2)
- );
- });
- });
- });
- },
- 300,
- false,
- this
- )();
- }
- }
|