|
|
@@ -1,20 +1,21 @@
|
|
|
// import attractivity from '../Attractivity.json';
|
|
|
import nuts from '../nuts.js';
|
|
|
-import {factors} from './factors.js';
|
|
|
+//import {factors} from './factors.js';
|
|
|
|
|
|
export class AdjusterService {
|
|
|
constructor(HsCore, HsUtilsService, $rootScope, $http, $location) {
|
|
|
'ngInject';
|
|
|
- this.HsCore = HsCore;
|
|
|
+ //this.HsCore = HsCore;
|
|
|
this.HsUtilsService = HsUtilsService;
|
|
|
this.$rootScope = $rootScope;
|
|
|
this.$http = $http;
|
|
|
this.serviceBaseUrl =
|
|
|
$location.host() === 'localhost'
|
|
|
- ? 'https://jmacura.ml/ws/'
|
|
|
+ ? 'https://jmacura.ml/ws/' // 'http://localhost:3000/'
|
|
|
: 'https://publish.lesprojekt.cz/nodejs/';
|
|
|
- this.factors = factors;
|
|
|
+ this.factors = [];
|
|
|
this.clusters = [];
|
|
|
+ this.method = 'haclust';
|
|
|
this._clusteringInProcess = true;
|
|
|
this.init();
|
|
|
}
|
|
|
@@ -27,22 +28,23 @@ export class AdjusterService {
|
|
|
const f = () => {
|
|
|
this._clusteringInProcess = true;
|
|
|
this.$http({
|
|
|
- method: 'get',
|
|
|
+ method: 'post',
|
|
|
url: this.serviceBaseUrl + 'clusters',
|
|
|
- /*data: {
|
|
|
+ data: {
|
|
|
factors: this.factors.map((f) => {
|
|
|
return {
|
|
|
- factor: f.factor,
|
|
|
+ factor: f.name,
|
|
|
weight: f.weight,
|
|
|
datasets: f.datasets
|
|
|
.filter((ds) => ds.included)
|
|
|
.map((ds) => ds.name),
|
|
|
};
|
|
|
}),
|
|
|
- },*/
|
|
|
- }).then((response) => {
|
|
|
- const clusterData = response.data.response;
|
|
|
- /*let max = 0;
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .then((response) => {
|
|
|
+ const clusterData = response.data.response;
|
|
|
+ /*let max = 0;
|
|
|
this.clusters.forEach((a) => {
|
|
|
if (a.aggregate > max) {
|
|
|
max = a.aggregate;
|
|
|
@@ -55,27 +57,33 @@ export class AdjusterService {
|
|
|
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]);
|
|
|
- }
|
|
|
+ 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']);
|
|
|
+ const clusters = [];
|
|
|
+ for (const region of clusterData) {
|
|
|
+ if (!clusters.includes(region[this.method])) {
|
|
|
+ clusters.push(region[this.method]);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- this.clusters = clusters;
|
|
|
- this._clusteringInProcess = false;
|
|
|
- this.$rootScope.$broadcast('clusters_loaded');
|
|
|
- });
|
|
|
+ this.clusters = clusters;
|
|
|
+ this._clusteringInProcess = false;
|
|
|
+ this.$rootScope.$broadcast('clusters_loaded');
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error(
|
|
|
+ `Error obtaining data from ${this.serviceBaseUrl}: ${error}`
|
|
|
+ );
|
|
|
+ this._clusteringInProcess = false;
|
|
|
+ });
|
|
|
};
|
|
|
this.HsUtilsService.debounce(f, 300)();
|
|
|
}
|
|
|
@@ -83,23 +91,32 @@ export class AdjusterService {
|
|
|
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,
|
|
|
- };
|
|
|
- });
|
|
|
+ })
|
|
|
+ .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,
|
|
|
+ desc: ds.Description,
|
|
|
+ included: true,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ });
|
|
|
+ this.apply();
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error(`Web service at ${this.serviceBaseUrl} unavailable!`);
|
|
|
+ this._clusteringInProcess = false;
|
|
|
});
|
|
|
- this.apply();
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
/**
|