| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // 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.clusters = [];
- this._clusteringInProcess = true;
- this.init();
- }
- /**
- * Sends a request to polirural-attractiveness-service
- * and applies the returned values
- */
- apply() {
- const f = () => {
- this._clusteringInProcess = true;
- 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 clusterData = response.data.response;
- /*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) => {
- // Pair each feature with its clustering data
- const featureData = clusterData.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]);
- }
- });
- });
- const clusters = [];
- for (const region of clusterData) {
- if (!clusters.includes(region['km25.cluster'])) {
- clusters.push(region['km25.cluster']);
- }
- }
- this.clusters = clusters;
- this._clusteringInProcess = false;
- this.$rootScope.$broadcast('clusters_loaded');
- });
- };
- this.HsUtilsService.debounce(f, 300)();
- }
- init() {
- this.$http({
- url: this.serviceBaseUrl + 'datasets',
- }).then((response) => {
- this.factors = response.data.map((dataset) => {
- return {name: dataset.Factor, weight: 1, datasets: []};
- });
- this.factors = this.HsUtilsService.removeDuplicates(this.factors, 'name');
- this.factors.forEach((factor) => {
- factor.datasets = response.data
- .filter((ds) => ds.Factor === factor.name)
- .map((ds) => {
- return {
- name: ds.Name,
- included: true,
- };
- });
- });
- this.apply();
- });
- }
- /**
- * @returns {boolean} true if clustering is in process, false otherwise
- */
- isClusteringInProcess() {
- return this._clusteringInProcess;
- }
- }
|