|
@@ -1,111 +1,90 @@
|
|
|
// import attractivity from '../Attractivity.json';
|
|
// import attractivity from '../Attractivity.json';
|
|
|
import nuts from '../nuts.js';
|
|
import nuts from '../nuts.js';
|
|
|
|
|
+import {factors} from './factors.js';
|
|
|
|
|
|
|
|
-export default function (HsCore, HsUtilsService, $rootScope, $http) {
|
|
|
|
|
- 'ngInject';
|
|
|
|
|
- const me = {
|
|
|
|
|
- factors: [
|
|
|
|
|
- {
|
|
|
|
|
- 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,
|
|
|
|
|
- },
|
|
|
|
|
- ],
|
|
|
|
|
- apply() {
|
|
|
|
|
- HsUtilsService.debounce(function () {
|
|
|
|
|
- $http({
|
|
|
|
|
- method: 'post',
|
|
|
|
|
- url: 'https://publish.lesprojekt.cz/nodejs/scores',
|
|
|
|
|
- data: {
|
|
|
|
|
- factors: me.factors.map((f) => {
|
|
|
|
|
- return {
|
|
|
|
|
- factor: f.factor,
|
|
|
|
|
- weight: f.weight,
|
|
|
|
|
- datasets: f.datasets
|
|
|
|
|
- .filter((ds) => ds.included)
|
|
|
|
|
- .map((ds) => ds.name),
|
|
|
|
|
- };
|
|
|
|
|
- }),
|
|
|
|
|
- },
|
|
|
|
|
- }).then((response) => {
|
|
|
|
|
- me.attractivity = response.data;
|
|
|
|
|
- let max = 0;
|
|
|
|
|
- me.attractivity.forEach((a) => {
|
|
|
|
|
- if (a.aggregate > max) {
|
|
|
|
|
- max = a.aggregate;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- const normalizer = 1 / max;
|
|
|
|
|
- me.attractivity.forEach((a) => {
|
|
|
|
|
- a.aggregate *= normalizer;
|
|
|
|
|
- });
|
|
|
|
|
- me.attractivity.forEach((a) => {
|
|
|
|
|
- me.nutsCodeRecordRelations[a.code] = a;
|
|
|
|
|
- });
|
|
|
|
|
- nuts.nuts3Source.forEachFeature((feature) => {
|
|
|
|
|
- feature.set(
|
|
|
|
|
- 'total',
|
|
|
|
|
- me.nutsCodeRecordRelations[feature.get('NUTS_ID')].aggregate
|
|
|
|
|
- );
|
|
|
|
|
|
|
+export class AdjusterService {
|
|
|
|
|
+ constructor(HsCore, HsUtilsService, $rootScope, $http) {
|
|
|
|
|
+ 'ngInject';
|
|
|
|
|
+ this.HsCore = HsCore;
|
|
|
|
|
+ this.HsUtilsService = HsUtilsService;
|
|
|
|
|
+ this.$rootScope = $rootScope;
|
|
|
|
|
+ this.$http = $http;
|
|
|
|
|
+ this.factors = factors;
|
|
|
|
|
+ this.nutsCodeRecordRelations = {};
|
|
|
|
|
+ this.init();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ apply() {
|
|
|
|
|
+ const f = () => {
|
|
|
|
|
+ this.$http({
|
|
|
|
|
+ method: 'post',
|
|
|
|
|
+ url: 'https://publish.lesprojekt.cz/nodejs/scores',
|
|
|
|
|
+ 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) => {
|
|
|
|
|
+ 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(
|
|
feature.set(
|
|
|
- 'totalForHumans',
|
|
|
|
|
|
|
+ factor.factor,
|
|
|
(
|
|
(
|
|
|
- me.nutsCodeRecordRelations[feature.get('NUTS_ID')].aggregate *
|
|
|
|
|
- 100
|
|
|
|
|
|
|
+ this.nutsCodeRecordRelations[feature.get('NUTS_ID')][
|
|
|
|
|
+ factor.factor
|
|
|
|
|
+ ] * 100
|
|
|
).toFixed(2)
|
|
).toFixed(2)
|
|
|
);
|
|
);
|
|
|
- me.factors.forEach((factor) => {
|
|
|
|
|
- feature.set(
|
|
|
|
|
- factor.factor,
|
|
|
|
|
- (
|
|
|
|
|
- me.nutsCodeRecordRelations[feature.get('NUTS_ID')][
|
|
|
|
|
- factor.factor
|
|
|
|
|
- ] * 100
|
|
|
|
|
- ).toFixed(2)
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
- /*
|
|
|
|
|
-
|
|
|
|
|
- */
|
|
|
|
|
- }, 300)();
|
|
|
|
|
- },
|
|
|
|
|
- };
|
|
|
|
|
- me.nutsCodeRecordRelations = {};
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+ this.HsUtilsService.debounce(f, 300)();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- $http({url: 'https://publish.lesprojekt.cz/nodejs/datasets'}).then(
|
|
|
|
|
- (response) => {
|
|
|
|
|
- me.factors = response.data.map((dataset) => {
|
|
|
|
|
|
|
+ init() {
|
|
|
|
|
+ this.$http({
|
|
|
|
|
+ url: 'https://publish.lesprojekt.cz/nodejs/datasets',
|
|
|
|
|
+ }).then((response) => {
|
|
|
|
|
+ this.factors = response.data.map((dataset) => {
|
|
|
return {factor: dataset.Factor, weight: 1, datasets: []};
|
|
return {factor: dataset.Factor, weight: 1, datasets: []};
|
|
|
});
|
|
});
|
|
|
- me.factors = HsUtilsService.removeDuplicates(me.factors, 'factor');
|
|
|
|
|
- me.factors.forEach((factor) => {
|
|
|
|
|
|
|
+ this.factors = this.HsUtilsService.removeDuplicates(
|
|
|
|
|
+ this.factors,
|
|
|
|
|
+ 'factor'
|
|
|
|
|
+ );
|
|
|
|
|
+ this.factors.forEach((factor) => {
|
|
|
factor.datasets = response.data
|
|
factor.datasets = response.data
|
|
|
.filter((ds) => ds.Factor === factor.factor)
|
|
.filter((ds) => ds.Factor === factor.factor)
|
|
|
.map((ds) => {
|
|
.map((ds) => {
|
|
@@ -115,9 +94,7 @@ export default function (HsCore, HsUtilsService, $rootScope, $http) {
|
|
|
};
|
|
};
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
- me.apply();
|
|
|
|
|
- }
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- return me;
|
|
|
|
|
|
|
+ this.apply();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|