adjuster.service.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // import attractivity from '../Attractivity.json';
  2. import nuts from '../nuts.js';
  3. import {factors} from './factors.js';
  4. export class AdjusterService {
  5. constructor(HsCore, HsUtilsService, $rootScope, $http, $location) {
  6. 'ngInject';
  7. this.HsCore = HsCore;
  8. this.HsUtilsService = HsUtilsService;
  9. this.$rootScope = $rootScope;
  10. this.$http = $http;
  11. this.serviceBaseUrl =
  12. $location.host() === 'localhost'
  13. ? 'https://jmacura.ml/ws/'
  14. : 'https://publish.lesprojekt.cz/nodejs/';
  15. this.factors = factors;
  16. this.nutsCodeRecordRelations = {};
  17. this.apply();
  18. }
  19. apply() {
  20. const f = () => {
  21. this.$http({
  22. method: 'get',
  23. url: this.serviceBaseUrl + 'clusters',
  24. /*data: {
  25. factors: this.factors.map((f) => {
  26. return {
  27. factor: f.factor,
  28. weight: f.weight,
  29. datasets: f.datasets
  30. .filter((ds) => ds.included)
  31. .map((ds) => ds.name),
  32. };
  33. }),
  34. },*/
  35. }).then((response) => {
  36. const clusters = response.data.response;
  37. console.log(this.clusters);
  38. /*let max = 0;
  39. this.clusters.forEach((a) => {
  40. if (a.aggregate > max) {
  41. max = a.aggregate;
  42. }
  43. });
  44. const normalizer = 1 / max;
  45. this.attractivity.forEach((a) => {
  46. a.aggregate *= normalizer;
  47. });
  48. this.attractivity.forEach((a) => {
  49. this.nutsCodeRecordRelations[a.code] = a;
  50. });*/
  51. nuts.nuts3Source.forEachFeature((feature) => {
  52. const featureData = clusters.find(
  53. (item) => item['nuts_id'] === feature.get('NUTS_ID')
  54. );
  55. Object.keys(featureData).forEach(function (key, index) {
  56. if (key !== 'nuts_id') {
  57. feature.set(key, featureData[key]);
  58. }
  59. });
  60. });
  61. });
  62. };
  63. this.HsUtilsService.debounce(f, 300)();
  64. }
  65. /*init() {
  66. this.$http({
  67. url: this.serviceBaseUrl + 'datasets',
  68. }).then((response) => {
  69. this.factors = response.data.map((dataset) => {
  70. return {factor: dataset.Factor, weight: 1, datasets: []};
  71. });
  72. this.factors = this.HsUtilsService.removeDuplicates(
  73. this.factors,
  74. 'factor'
  75. );
  76. this.factors.forEach((factor) => {
  77. factor.datasets = response.data
  78. .filter((ds) => ds.Factor === factor.factor)
  79. .map((ds) => {
  80. return {
  81. name: ds.Name,
  82. included: true,
  83. };
  84. });
  85. });
  86. this.apply();
  87. });
  88. }*/
  89. }