浏览代码

🐛 re-allow configurable factor weights

jmacura 4 年之前
父节点
当前提交
cd94d1cf97

+ 2 - 1
src/adjuster/adjuster-event.service.ts

@@ -1,5 +1,6 @@
 import {Injectable} from '@angular/core';
 import {Subject} from 'rxjs';
+import {RDFSubject} from './ontology.model';
 
 @Injectable({providedIn: 'root'})
 export class AdjusterEventService {
@@ -7,6 +8,6 @@ export class AdjusterEventService {
   loaded: Subject<{success: boolean; type: string; err?}> = new Subject();
   loaderReady: Subject<void> = new Subject();
   methodChanged: Subject<string> = new Subject();
-  ontologyLoads: Subject<any> = new Subject();
+  ontologyLoads: Subject<Array<RDFSubject>> = new Subject();
   constructor() {}
 }

+ 10 - 5
src/adjuster/adjuster.service.ts

@@ -16,13 +16,14 @@ import {AdjusterEventService} from './adjuster-event.service';
 import {AdjusterLegendService} from './adjuster-legend.service';
 import {AdjusterPresetsService, Factor} from './adjuster-presets.service';
 import {obce, obceIndexLayer, osmLayer} from '../app.config';
+import {RDFSubject} from './ontology.model';
 
 @Injectable({providedIn: 'root'})
 export class AdjusterService {
   /** To be read from a config file */
   allowedClusteringMethods: Array<string>;
   /** To be read from a config file */
-  initialWeights;
+  initialWeights: {[factorId: string]: number};
   /** To be read from a config file */
   serviceBaseUrl: string;
   /** Used in the UI as a selector */
@@ -66,6 +67,7 @@ export class AdjusterService {
     );
     this.numberOfClusters = 9;
 
+    /* Get the ontology file from the service */
     this.loadOntology();
 
     /* Wait for all layers to be ready */
@@ -78,7 +80,7 @@ export class AdjusterService {
       }
     });
 
-    /* Ensure that all layers and also the loader component are ready */
+    /* Ensure that all layers, the loader component and the presets from ontology are ready */
     forkJoin({
       lyr: this.adjusterEventService.layerReady,
       load: this.adjusterEventService.loaderReady,
@@ -96,8 +98,7 @@ export class AdjusterService {
         return {
           id: group.id,
           labels: group.labels,
-          //FIXME: load weights from file
-          weight: 0.5,
+          weight: this.resetFactorWeights(group.id),
           datasets: this.adjusterPresetsService.getGroupDatasets(group.id)
         }
       });
@@ -356,7 +357,7 @@ export class AdjusterService {
 
   async loadOntology() {
     try {
-      const onto = await this.$http.get(this.serviceBaseUrl + 'ontology/').toPromise();
+      const onto = await this.$http.get<RDFSubject[]>(this.serviceBaseUrl + 'ontology/').toPromise();
       this.adjusterEventService.ontologyLoads.next(onto);
       this.adjusterEventService.ontologyLoads.complete();
     } catch (error) {
@@ -443,6 +444,10 @@ export class AdjusterService {
     method.layer.getSource().getFeatures()[0].dispatchEvent('change');
   }
 
+  resetFactorWeights(factorId: string): number {
+    return this.initialWeights[factorId] ?? 0.5;
+  }
+
   clustersLoaded(): boolean {
     return this._clustersLoaded;
   }

+ 3 - 2
src/adjuster/metadata-dialog/metadata-dialog.service.ts

@@ -1,11 +1,12 @@
 import {Injectable} from '@angular/core';
 
-import { AdjusterPresetsService } from '../adjuster-presets.service';
+import {AdjusterPresetsService} from '../adjuster-presets.service';
 import {DatasetDescriptor} from './metadata-dialog.component';
+import {RDFSubject} from '../ontology.model';
 
 @Injectable({providedIn: 'root'})
 export class MetadataDialogService {
-  ontology;
+  ontology: RDFSubject[];
 
   constructor(public adjusterPresetsService: AdjusterPresetsService) {
     this.ontology = this.adjusterPresetsService.ontology;

+ 6 - 6
src/attractiveness.config.json

@@ -4,12 +4,12 @@
     "km50l.cluster"
   ],
   "initialWeights": {
-    "Konec chudoby": 0.1,
-    "Zdraví a kvalitní život": 0.25,
-    "Kvalitní vzdělání": 0.1,
-    "Důstojná práce a ekonomický růst": 0,
-    "Udržitelná města a obce": 0.85,
-    "Ostatní": 0
+    "http://www.semanticweb.org/attractiveness/poverty": 0.1,
+    "http://www.semanticweb.org/attractiveness/wellbeing": 0.25,
+    "http://www.semanticweb.org/attractiveness/qualityeducation": 0.1,
+    "http://www.semanticweb.org/attractiveness/decentwork": 0,
+    "http://www.semanticweb.org/attractiveness/sustainablecities": 0.85,
+    "other": 0
   },
   "serviceBaseUrl": "https://jmacura.eu/ws/"
 }