|
@@ -1,18 +1,24 @@
|
|
|
import {HttpClient} from '@angular/common/http';
|
|
import {HttpClient} from '@angular/common/http';
|
|
|
import {Injectable} from '@angular/core';
|
|
import {Injectable} from '@angular/core';
|
|
|
|
|
|
|
|
-import {HsDialogContainerService} from 'hslayers-ng/components/layout/dialogs/dialog-container.service';
|
|
|
|
|
import {HsLayerManagerService} from 'hslayers-ng/components/layermanager';
|
|
import {HsLayerManagerService} from 'hslayers-ng/components/layermanager';
|
|
|
import {HsUtilsService} from 'hslayers-ng/components/utils/utils.service';
|
|
import {HsUtilsService} from 'hslayers-ng/components/utils/utils.service';
|
|
|
|
|
|
|
|
|
|
+import clusteringMethods from '../data/clustering_methods.json';
|
|
|
import {obce, osmLayer} from '../app.config';
|
|
import {obce, osmLayer} from '../app.config';
|
|
|
|
|
|
|
|
@Injectable({providedIn: 'root'})
|
|
@Injectable({providedIn: 'root'})
|
|
|
export class AdjusterService {
|
|
export class AdjusterService {
|
|
|
serviceBaseUrl: string;
|
|
serviceBaseUrl: string;
|
|
|
- //nutsCodeRecordRelations = {};
|
|
|
|
|
- //attractivity;
|
|
|
|
|
- factors: any = [];
|
|
|
|
|
|
|
+ factors = [];
|
|
|
|
|
+ clusters = [];
|
|
|
|
|
+ numberOfClusters;
|
|
|
|
|
+ method: string;
|
|
|
|
|
+ methods: Array<{
|
|
|
|
|
+ codename: string;
|
|
|
|
|
+ name: string;
|
|
|
|
|
+ type: string;
|
|
|
|
|
+ }>;
|
|
|
private _clusteringInProcess: boolean;
|
|
private _clusteringInProcess: boolean;
|
|
|
private _raiInProcess: boolean;
|
|
private _raiInProcess: boolean;
|
|
|
|
|
|
|
@@ -23,10 +29,13 @@ export class AdjusterService {
|
|
|
) {
|
|
) {
|
|
|
this.serviceBaseUrl =
|
|
this.serviceBaseUrl =
|
|
|
window.location.hostname === 'localhost'
|
|
window.location.hostname === 'localhost'
|
|
|
- ? 'https://jmacura.ml/ws/' // 'http://localhost:3000/'
|
|
|
|
|
|
|
+ ? 'http://localhost:3000/' // 'https://jmacura.ml/ws/'
|
|
|
: 'https://publish.lesprojekt.cz/nodejs/';
|
|
: 'https://publish.lesprojekt.cz/nodejs/';
|
|
|
- this._raiInProcess = false;
|
|
|
|
|
- this._clusteringInProcess = false;
|
|
|
|
|
|
|
+ this.methods = clusteringMethods.filter(
|
|
|
|
|
+ (m) => m.codename == 'haclustwd2' || m.codename == 'km50l.cluster'
|
|
|
|
|
+ );
|
|
|
|
|
+ this.method = 'haclustwd2';
|
|
|
|
|
+ this.numberOfClusters = 9;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -34,6 +43,11 @@ export class AdjusterService {
|
|
|
* and applies the returned values
|
|
* and applies the returned values
|
|
|
*/
|
|
*/
|
|
|
apply(): void {
|
|
apply(): void {
|
|
|
|
|
+ //this.calculateIndex();
|
|
|
|
|
+ this.calculateClusters();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ calculateIndex(): void {
|
|
|
const f = () => {
|
|
const f = () => {
|
|
|
this._raiInProcess = true;
|
|
this._raiInProcess = true;
|
|
|
this.$http
|
|
this.$http
|
|
@@ -132,6 +146,76 @@ export class AdjusterService {
|
|
|
this.hsUtilsService.debounce(f, 300, false, this)();
|
|
this.hsUtilsService.debounce(f, 300, false, this)();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ calculateClusters(): void {
|
|
|
|
|
+ const f = () => {
|
|
|
|
|
+ this._clusteringInProcess = true;
|
|
|
|
|
+ this.$http
|
|
|
|
|
+ .post(this.serviceBaseUrl + 'clusters/cz', {
|
|
|
|
|
+ numberOfClusters: this.numberOfClusters,
|
|
|
|
|
+ factors: this.factors.map((f) => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ factor: f.name,
|
|
|
|
|
+ weight: f.weight,
|
|
|
|
|
+ datasets: f.datasets
|
|
|
|
|
+ .filter((ds) => ds.included)
|
|
|
|
|
+ .map((ds) => ds.name),
|
|
|
|
|
+ };
|
|
|
|
|
+ }),
|
|
|
|
|
+ })
|
|
|
|
|
+ .toPromise()
|
|
|
|
|
+ .then((data: any) => {
|
|
|
|
|
+ console.log('data received', data);
|
|
|
|
|
+ let logs = 0;
|
|
|
|
|
+ let errs = 0;
|
|
|
|
|
+ const clusterData = data.response;
|
|
|
|
|
+ console.time('forEachObceCluster');
|
|
|
|
|
+ obce.forEachFeature((feature) => {
|
|
|
|
|
+ // Pair each feature with its clustering data
|
|
|
|
|
+ const featureData = clusterData.find(
|
|
|
|
|
+ // NOTE: Do NOT add triple equal sign!
|
|
|
|
|
+ (item) => item['lau2'] == feature.get('nationalCode')
|
|
|
|
|
+ );
|
|
|
|
|
+ if (!featureData && errs < 20) {
|
|
|
|
|
+ errs++;
|
|
|
|
|
+ console.warn(`No data for feature ${feature.get('nationalCode')}`);
|
|
|
|
|
+ console.log(feature);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ logs++;
|
|
|
|
|
+ if (logs % 100 == 0) {
|
|
|
|
|
+ console.log(`processed ${logs} items`);
|
|
|
|
|
+ }
|
|
|
|
|
+ Object.keys(featureData).forEach(function (key, index) {
|
|
|
|
|
+ if (key !== 'lau2') {
|
|
|
|
|
+ feature.set(key, featureData[key]);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ const clusters = [];
|
|
|
|
|
+ for (const region of clusterData) {
|
|
|
|
|
+ if (!clusters.includes(region[this.method])) {
|
|
|
|
|
+ clusters.push(region[this.method]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ console.timeEnd('forEachObceCluster');
|
|
|
|
|
+ console.log('clustering done!');
|
|
|
|
|
+ this.clusters = clusters;
|
|
|
|
|
+ this._clusteringInProcess = false;
|
|
|
|
|
+ //this.adjusterEventService.clustersLoaded.next({success: true});
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch((error) => {
|
|
|
|
|
+ console.warn(`Error obtaining data from ${this.serviceBaseUrl}.`);
|
|
|
|
|
+ console.log(error);
|
|
|
|
|
+ this._clusteringInProcess = false;
|
|
|
|
|
+ /*this.adjusterEventService.clustersLoaded.next({
|
|
|
|
|
+ success: false,
|
|
|
|
|
+ err: error,
|
|
|
|
|
+ });*/
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+ this.hsUtilsService.debounce(f, 300, false, this)();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
init(): void {
|
|
init(): void {
|
|
|
this._raiInProcess = true;
|
|
this._raiInProcess = true;
|
|
|
this.$http
|
|
this.$http
|
|
@@ -156,6 +240,7 @@ export class AdjusterService {
|
|
|
};
|
|
};
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+ this._raiInProcess = false;
|
|
|
this.apply();
|
|
this.apply();
|
|
|
this.hsLayerManagerService.setGreyscale(osmLayer);
|
|
this.hsLayerManagerService.setGreyscale(osmLayer);
|
|
|
})
|
|
})
|