// import attractivity from '../Attractivity.json'; import nuts from '../nuts.js'; import {factors} from './factors.js'; export class AdjusterService { constructor(HsCore, HsUtilsService, $rootScope, $http, $location) { 'ngInject'; this.HsCore = HsCore; this.HsUtilsService = HsUtilsService; this.$rootScope = $rootScope; this.$http = $http; this.serviceBaseUrl = $location.host() === 'localhost' ? 'https://jmacura.ml/ws/' : 'https://publish.lesprojekt.cz/nodejs/'; this.factors = factors; this.nutsCodeRecordRelations = {}; this.apply(); } apply() { const f = () => { this.$http({ method: 'get', url: this.serviceBaseUrl + 'clusters', /*data: { factors: this.factors.map((f) => { return { factor: f.factor, weight: f.weight, datasets: f.datasets .filter((ds) => ds.included) .map((ds) => ds.name), }; }), },*/ }).then((response) => { const clusters = response.data.response; console.log(this.clusters); /*let max = 0; this.clusters.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) => { const featureData = clusters.find( (item) => item['nuts_id'] === feature.get('NUTS_ID') ); Object.keys(featureData).forEach(function (key, index) { if (key !== 'nuts_id') { feature.set(key, featureData[key]); } }); }); }); }; this.HsUtilsService.debounce(f, 300)(); } /*init() { this.$http({ url: this.serviceBaseUrl + 'datasets', }).then((response) => { this.factors = response.data.map((dataset) => { return {factor: dataset.Factor, weight: 1, datasets: []}; }); this.factors = this.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(); }); }*/ }