raain-model 2.6.10 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/CHANGELOG.md +94 -7
  2. package/README.md +14 -13
  3. package/RELEASE_PROCESS.md +91 -4
  4. package/cartesian/CartesianMeasureValue.d.ts +46 -0
  5. package/{src/cartesian/CartesianMeasureValue.ts → cartesian/CartesianMeasureValue.js} +41 -73
  6. package/cartesian/CartesianMeasureValue.js.map +1 -0
  7. package/cartesian/CartesianTools.d.ts +32 -0
  8. package/{src/cartesian/CartesianTools.ts → cartesian/CartesianTools.js} +69 -130
  9. package/cartesian/CartesianTools.js.map +1 -0
  10. package/cartesian/CartesianValue.d.ts +14 -0
  11. package/cartesian/CartesianValue.js +17 -0
  12. package/cartesian/CartesianValue.js.map +1 -0
  13. package/cartesian/EarthMap.d.ts +5 -0
  14. package/cartesian/EarthMap.js +3 -0
  15. package/cartesian/EarthMap.js.map +1 -0
  16. package/cartesian/ICartesianMeasureValue.d.ts +23 -0
  17. package/cartesian/ICartesianMeasureValue.js +3 -0
  18. package/cartesian/ICartesianMeasureValue.js.map +1 -0
  19. package/cartesian/LatLng.d.ts +16 -0
  20. package/cartesian/LatLng.js +34 -0
  21. package/cartesian/LatLng.js.map +1 -0
  22. package/cartesian/RadarCartesianMeasureValue.d.ts +27 -0
  23. package/cartesian/RadarCartesianMeasureValue.js +24 -0
  24. package/cartesian/RadarCartesianMeasureValue.js.map +1 -0
  25. package/cartesian/RainCartesianMeasureValue.d.ts +25 -0
  26. package/cartesian/RainCartesianMeasureValue.js +25 -0
  27. package/cartesian/RainCartesianMeasureValue.js.map +1 -0
  28. package/cartesian/index.js +25 -0
  29. package/cartesian/index.js.map +1 -0
  30. package/gauge/GaugeMeasure.d.ts +30 -0
  31. package/gauge/GaugeMeasure.js +30 -0
  32. package/gauge/GaugeMeasure.js.map +1 -0
  33. package/gauge/GaugeNode.d.ts +95 -0
  34. package/{src/gauge/GaugeNode.ts → gauge/GaugeNode.js} +28 -54
  35. package/gauge/GaugeNode.js.map +1 -0
  36. package/gauge/GaugeNodeMap.d.ts +35 -0
  37. package/gauge/GaugeNodeMap.js +42 -0
  38. package/gauge/GaugeNodeMap.js.map +1 -0
  39. package/gauge/index.js +20 -0
  40. package/gauge/index.js.map +1 -0
  41. package/index.js +24 -0
  42. package/index.js.map +1 -0
  43. package/organization/EventNode.d.ts +30 -0
  44. package/organization/EventNode.js +30 -0
  45. package/organization/EventNode.js.map +1 -0
  46. package/organization/IVersion.js +3 -0
  47. package/organization/IVersion.js.map +1 -0
  48. package/organization/Link.d.ts +16 -0
  49. package/{src/organization/Link.ts → organization/Link.js} +15 -15
  50. package/organization/Link.js.map +1 -0
  51. package/organization/Measure.d.ts +30 -0
  52. package/organization/Measure.js +51 -0
  53. package/organization/Measure.js.map +1 -0
  54. package/organization/PeopleNode.d.ts +23 -0
  55. package/{src/organization/PeopleNode.ts → organization/PeopleNode.js} +10 -20
  56. package/organization/PeopleNode.js.map +1 -0
  57. package/organization/RaainNode.d.ts +95 -0
  58. package/{src/organization/RaainNode.ts → organization/RaainNode.js} +38 -63
  59. package/organization/RaainNode.js.map +1 -0
  60. package/organization/TeamNode.d.ts +51 -0
  61. package/organization/TeamNode.js +52 -0
  62. package/organization/TeamNode.js.map +1 -0
  63. package/organization/index.js +24 -0
  64. package/organization/index.js.map +1 -0
  65. package/package.json +4 -2
  66. package/polar/AbstractPolarMeasureValue.d.ts +31 -0
  67. package/{src/polar/AbstractPolarMeasureValue.ts → polar/AbstractPolarMeasureValue.js} +34 -62
  68. package/polar/AbstractPolarMeasureValue.js.map +1 -0
  69. package/polar/IPolarMeasureValue.d.ts +19 -0
  70. package/polar/IPolarMeasureValue.js +3 -0
  71. package/polar/IPolarMeasureValue.js.map +1 -0
  72. package/polar/MeasureValuePolarContainer.d.ts +24 -0
  73. package/{src/polar/MeasureValuePolarContainer.ts → polar/MeasureValuePolarContainer.js} +13 -29
  74. package/polar/MeasureValuePolarContainer.js.map +1 -0
  75. package/polar/PolarFilter.d.ts +16 -0
  76. package/polar/PolarFilter.js +45 -0
  77. package/polar/PolarFilter.js.map +1 -0
  78. package/polar/PolarMeasureValue.d.ts +51 -0
  79. package/{src/polar/PolarMeasureValue.ts → polar/PolarMeasureValue.js} +62 -125
  80. package/polar/PolarMeasureValue.js.map +1 -0
  81. package/polar/PolarMeasureValueMap.d.ts +45 -0
  82. package/{src/polar/PolarMeasureValueMap.ts → polar/PolarMeasureValueMap.js} +88 -165
  83. package/polar/PolarMeasureValueMap.js.map +1 -0
  84. package/polar/PolarValue.d.ts +10 -0
  85. package/polar/PolarValue.js +12 -0
  86. package/polar/PolarValue.js.map +1 -0
  87. package/polar/RadarPolarMeasureValue.d.ts +33 -0
  88. package/{src/polar/RadarPolarMeasureValue.ts → polar/RadarPolarMeasureValue.js} +31 -39
  89. package/polar/RadarPolarMeasureValue.js.map +1 -0
  90. package/polar/RainPolarMeasureValue.d.ts +24 -0
  91. package/polar/RainPolarMeasureValue.js +46 -0
  92. package/polar/RainPolarMeasureValue.js.map +1 -0
  93. package/polar/index.js +25 -0
  94. package/polar/index.js.map +1 -0
  95. package/quality/QualityPoint.d.ts +37 -0
  96. package/{src/quality/QualityPoint.ts → quality/QualityPoint.js} +33 -56
  97. package/quality/QualityPoint.js.map +1 -0
  98. package/quality/SpeedMatrix.d.ts +83 -0
  99. package/{src/quality/SpeedMatrix.ts → quality/SpeedMatrix.js} +76 -117
  100. package/quality/SpeedMatrix.js.map +1 -0
  101. package/quality/SpeedMatrixContainer.d.ts +102 -0
  102. package/{src/quality/SpeedMatrixContainer.ts → quality/SpeedMatrixContainer.js} +103 -210
  103. package/quality/SpeedMatrixContainer.js.map +1 -0
  104. package/quality/history/CartesianGaugeHistory.d.ts +15 -0
  105. package/quality/history/CartesianGaugeHistory.js +14 -0
  106. package/quality/history/CartesianGaugeHistory.js.map +1 -0
  107. package/quality/history/CartesianRainHistory.d.ts +9 -0
  108. package/quality/history/CartesianRainHistory.js +11 -0
  109. package/quality/history/CartesianRainHistory.js.map +1 -0
  110. package/quality/history/PositionHistory.d.ts +20 -0
  111. package/quality/history/PositionHistory.js +17 -0
  112. package/quality/history/PositionHistory.js.map +1 -0
  113. package/{src/quality/index.ts → quality/index.d.ts} +0 -3
  114. package/quality/index.js +26 -0
  115. package/quality/index.js.map +1 -0
  116. package/quality/position/Position.d.ts +22 -0
  117. package/quality/position/Position.js +50 -0
  118. package/quality/position/Position.js.map +1 -0
  119. package/quality/position/PositionValue.d.ts +9 -0
  120. package/quality/position/PositionValue.js +12 -0
  121. package/quality/position/PositionValue.js.map +1 -0
  122. package/quality/tools/QualityTools.d.ts +9 -0
  123. package/{src/quality/tools/QualityTools.ts → quality/tools/QualityTools.js} +17 -18
  124. package/quality/tools/QualityTools.js.map +1 -0
  125. package/radar/RadarMeasure.d.ts +38 -0
  126. package/radar/RadarMeasure.js +33 -0
  127. package/radar/RadarMeasure.js.map +1 -0
  128. package/radar/RadarNode.d.ts +41 -0
  129. package/radar/RadarNode.js +58 -0
  130. package/radar/RadarNode.js.map +1 -0
  131. package/radar/RadarNodeMap.d.ts +51 -0
  132. package/radar/RadarNodeMap.js +50 -0
  133. package/radar/RadarNodeMap.js.map +1 -0
  134. package/radar/index.js +20 -0
  135. package/radar/index.js.map +1 -0
  136. package/rain/MergeStrategy.d.ts +13 -0
  137. package/rain/MergeStrategy.js +11 -0
  138. package/rain/MergeStrategy.js.map +1 -0
  139. package/rain/RainComputation.d.ts +59 -0
  140. package/rain/RainComputation.js +68 -0
  141. package/rain/RainComputation.js.map +1 -0
  142. package/rain/RainComputationAbstract.d.ts +89 -0
  143. package/rain/RainComputationAbstract.js +207 -0
  144. package/rain/RainComputationAbstract.js.map +1 -0
  145. package/rain/RainComputationMap.d.ts +113 -0
  146. package/{src/rain/RainComputationMap.ts → rain/RainComputationMap.js} +26 -60
  147. package/rain/RainComputationMap.js.map +1 -0
  148. package/rain/RainComputationQuality.d.ts +58 -0
  149. package/{src/rain/RainComputationQuality.ts → rain/RainComputationQuality.js} +52 -89
  150. package/rain/RainComputationQuality.js.map +1 -0
  151. package/rain/RainMeasure.d.ts +17 -0
  152. package/rain/RainMeasure.js +18 -0
  153. package/rain/RainMeasure.js.map +1 -0
  154. package/rain/RainNode.d.ts +60 -0
  155. package/rain/RainNode.js +198 -0
  156. package/rain/RainNode.js.map +1 -0
  157. package/{src/rain/index.ts → rain/index.d.ts} +1 -0
  158. package/rain/index.js +24 -0
  159. package/rain/index.js.map +1 -0
  160. package/.cursorignore +0 -10
  161. package/.github/workflows/ci.yml +0 -29
  162. package/LICENSE +0 -21
  163. package/RELEASE.md +0 -19
  164. package/specs/REQUIREMENTS.md +0 -42
  165. package/specs/TECHNICAL.md +0 -57
  166. package/specs/cartesian/Cartesian.spec.ts +0 -82
  167. package/specs/cartesian/CartesianTools.spec.ts +0 -121
  168. package/specs/gauge/Gauge.spec.ts +0 -39
  169. package/specs/organization/Organization.spec.ts +0 -38
  170. package/specs/polar/Polar.spec.ts +0 -267
  171. package/specs/quality/Position.spec.ts +0 -18
  172. package/specs/quality/QualityPointEdgeCases.spec.ts +0 -215
  173. package/specs/quality/QualityTools.spec.ts +0 -67
  174. package/specs/quality/SpeedMatrix.spec.ts +0 -214
  175. package/specs/radar/Radar.spec.ts +0 -129
  176. package/specs/rain/Rain.spec.ts +0 -334
  177. package/specs/tsconfig.json +0 -12
  178. package/src/cartesian/CartesianValue.ts +0 -26
  179. package/src/cartesian/EarthMap.ts +0 -5
  180. package/src/cartesian/ICartesianMeasureValue.ts +0 -22
  181. package/src/cartesian/LatLng.ts +0 -43
  182. package/src/cartesian/RadarCartesianMeasureValue.ts +0 -32
  183. package/src/cartesian/RainCartesianMeasureValue.ts +0 -32
  184. package/src/gauge/GaugeMeasure.ts +0 -42
  185. package/src/gauge/GaugeNodeMap.ts +0 -55
  186. package/src/organization/EventNode.ts +0 -43
  187. package/src/organization/Measure.ts +0 -61
  188. package/src/organization/TeamNode.ts +0 -91
  189. package/src/polar/IPolarMeasureValue.ts +0 -21
  190. package/src/polar/PolarFilter.ts +0 -46
  191. package/src/polar/PolarValue.ts +0 -16
  192. package/src/polar/RainPolarMeasureValue.ts +0 -57
  193. package/src/quality/history/CartesianGaugeHistory.ts +0 -23
  194. package/src/quality/history/CartesianRainHistory.ts +0 -15
  195. package/src/quality/history/PositionHistory.ts +0 -31
  196. package/src/quality/position/Position.ts +0 -59
  197. package/src/quality/position/PositionValue.ts +0 -15
  198. package/src/radar/RadarMeasure.ts +0 -41
  199. package/src/radar/RadarNode.ts +0 -78
  200. package/src/radar/RadarNodeMap.ts +0 -61
  201. package/src/rain/MergeStrategy.ts +0 -15
  202. package/src/rain/RainComputation.ts +0 -96
  203. package/src/rain/RainComputationAbstract.ts +0 -262
  204. package/src/rain/RainMeasure.ts +0 -25
  205. package/src/rain/RainNode.ts +0 -235
  206. package/tsconfig.json +0 -17
  207. package/tslint.json +0 -79
  208. package/typedoc.json +0 -31
  209. /package/{src/cartesian/index.ts → cartesian/index.d.ts} +0 -0
  210. /package/{src/gauge/index.ts → gauge/index.d.ts} +0 -0
  211. /package/{src/index.ts → index.d.ts} +0 -0
  212. /package/{src/organization/IVersion.ts → organization/IVersion.d.ts} +0 -0
  213. /package/{src/organization/index.ts → organization/index.d.ts} +0 -0
  214. /package/{src/polar/index.ts → polar/index.d.ts} +0 -0
  215. /package/{src/radar/index.ts → radar/index.d.ts} +0 -0
@@ -1,96 +0,0 @@
1
- import {Link, RaainNode} from '../organization';
2
- import {RainPolarMeasureValue} from '../polar';
3
- import {CartesianTools, LatLng, RainCartesianMeasureValue} from '../cartesian';
4
- import {RainComputationAbstract} from './RainComputationAbstract';
5
- import {RainMeasure} from './RainMeasure';
6
- import {MergeStrategy} from './MergeStrategy';
7
-
8
- /**
9
- * api/rains/:rainId/computations/:computationId
10
- * or as an array on
11
- * api/rains/:id/computations?format=id&begin=...
12
- */
13
- export class RainComputation extends RainComputationAbstract {
14
-
15
- public static TYPE = 'rain-computation';
16
-
17
- // why "results" ? because "values" came from Measure.values, "results" came from computation
18
- // why array ? because you can have different angle/axis from the Radar
19
- public results: RainPolarMeasureValue[] | RainCartesianMeasureValue[];
20
-
21
- constructor(json: {
22
- id: string,
23
- date: Date,
24
- isReady: boolean,
25
- results: RainPolarMeasureValue[] | RainCartesianMeasureValue[],
26
- links?: Link[] | RaainNode[],
27
- version?: string,
28
- quality?: number,
29
- progressIngest?: number,
30
- progressComputing?: number,
31
- timeSpentInMs?: number,
32
- isDoneDate?: Date,
33
- launchedBy?: string,
34
- rain?: Link | RaainNode,
35
- radars?: Link[] | RaainNode[],
36
-
37
- }) {
38
- super(json);
39
- this.setResults(json.results);
40
- }
41
-
42
- public toJSON(options = {
43
- stringify: false
44
- }): any {
45
- const json = super.toJSON();
46
- json['results'] = this.results.map(r => r.toJSON(options));
47
- return json;
48
- }
49
-
50
- mergeCartesianResults(options: {
51
- mergeStrategy: MergeStrategy,
52
- mergeLimitPoints: [LatLng, LatLng],
53
- cartesianTools: CartesianTools,
54
- removeNullValues?: boolean,
55
- }): RainMeasure[] {
56
-
57
- this.buildLatLngMatrix(options);
58
-
59
- return this.mergeRainMeasures([new RainMeasure({
60
- id: this.id,
61
- values: this.results,
62
- date: this.date
63
- })], options);
64
- }
65
-
66
- protected getLinkType(): string {
67
- return RainComputation.TYPE;
68
- }
69
-
70
- private setResults(results: string[] | RainPolarMeasureValue[] | RainCartesianMeasureValue[]) {
71
- if (typeof results === 'string') {
72
- results = JSON.parse(results);
73
- }
74
-
75
- if (!results || results.length === 0 || !Array.isArray(results)) {
76
- this.results = [];
77
- return;
78
- }
79
-
80
- this.results = results.map(r => {
81
- if (typeof r === 'string' && r.indexOf('polarMeasureValue') >= 0) {
82
- return new RainPolarMeasureValue(JSON.parse(r));
83
- } else if (r.polarMeasureValue) {
84
- return new RainPolarMeasureValue(r);
85
- }
86
- if (typeof r === 'string' && r.indexOf('cartesian') >= 0) {
87
- return new RainCartesianMeasureValue(JSON.parse(r));
88
- } else if (r.cartesianValues) {
89
- return new RainCartesianMeasureValue(r);
90
- } else {
91
- return r;
92
- }
93
- });
94
- }
95
-
96
- }
@@ -1,262 +0,0 @@
1
- import {Link, RaainNode} from '../organization';
2
- import {RadarMeasure, RadarNode} from '../radar';
3
- import {RainNode} from './RainNode';
4
- import {CartesianMeasureValue, CartesianTools, CartesianValue, LatLng, RainCartesianMeasureValue} from '../cartesian';
5
- import {RainMeasure} from './RainMeasure';
6
- import {MergeLatLng, MergeStrategy} from './MergeStrategy';
7
-
8
- /**
9
- * not used directly
10
- */
11
- export class RainComputationAbstract extends RaainNode {
12
-
13
- public quality: number;
14
- public progressIngest: number;
15
- public progressComputing: number;
16
- public timeSpentInMs: number;
17
- public date: Date;
18
- public isReady: boolean;
19
- public isDoneDate: Date;
20
- public launchedBy: string;
21
- public name: string;
22
-
23
- protected mergeTools: {
24
- cartesianTools: CartesianTools;
25
- latsLngs: MergeLatLng[][];
26
- limitPoints: LatLng[];
27
- };
28
-
29
- constructor(json: {
30
- id: string,
31
- date: Date,
32
- isReady: boolean,
33
-
34
- links?: Link[] | RaainNode[],
35
- version?: string,
36
- quality?: number,
37
- progressIngest?: number,
38
- progressComputing?: number,
39
- timeSpentInMs?: number,
40
- isDoneDate?: Date,
41
- launchedBy?: string,
42
- rain?: Link | RaainNode,
43
- radars?: Link[] | RaainNode[],
44
-
45
- }) {
46
- super(json);
47
-
48
- this.date = json.date ? new Date(json.date) : null;
49
- this.quality = json.quality >= 0 ? json.quality : -1;
50
- this.progressIngest = json.progressIngest >= 0 ? json.progressIngest : -1;
51
- this.progressComputing = json.progressComputing >= 0 ? json.progressComputing : -1;
52
- this.timeSpentInMs = json.timeSpentInMs;
53
- this.isReady = !!json.isReady;
54
- this.isDoneDate = json.isDoneDate ? new Date(json.isDoneDate) : undefined;
55
- this.launchedBy = json.launchedBy;
56
-
57
- this.replaceRainLink(json.links);
58
- this.replaceRainLink(json.rain);
59
- this.addRadarLinks(json.links);
60
- this.addRadarLinks(json.radars);
61
- }
62
-
63
- private static _getRadarLinks(linksToPurify: any[]): any[] {
64
- if (!linksToPurify || linksToPurify.length === 0) {
65
- return [];
66
- }
67
-
68
- return linksToPurify.map(l => {
69
- if (l instanceof Link) {
70
- return l;
71
- } else if (l && l['_id']) {
72
- return new RadarNode({id: l['_id'].toString(), latitude: 0, longitude: 0, name: l.name, team: l.team});
73
- } else if (l && l.id) {
74
- return new RadarNode({
75
- id: l.id.toString(),// 'hex'
76
- latitude: 0, longitude: 0, name: l.name, team: l.team
77
- });
78
- }
79
- });
80
- }
81
-
82
- private static _getRadarMeasureLinks(linksToPurify: any[]): any[] {
83
- if (!linksToPurify || linksToPurify.length === 0) {
84
- return [];
85
- }
86
-
87
- return linksToPurify.map(l => {
88
- if (l instanceof Link) {
89
- return l;
90
- } else if (l && l['_id']) {
91
- return new RadarMeasure({id: l['_id'].toString(), values: []});
92
- } else if (l && l.id) {
93
- return new RadarMeasure({id: l.id.toString(), values: []}); // 'hex'
94
- }
95
- });
96
- }
97
-
98
- private static _getRainLink(linkToPurify: RaainNode): RainNode {
99
- if (!linkToPurify || !linkToPurify.id) {
100
- return null;
101
- }
102
-
103
- return new RainNode({
104
- id: linkToPurify.id.toString(),
105
- name: linkToPurify.id.toString(),
106
- team: null
107
- });
108
- }
109
-
110
- public toJSON(): any {
111
- const json = super.toJSON();
112
- json['date'] = this.date.toISOString();
113
- json['quality'] = this.quality;
114
- json['progressIngest'] = this.progressIngest;
115
- json['progressComputing'] = this.progressComputing;
116
- json['timeSpentInMs'] = this.timeSpentInMs;
117
- json['isReady'] = this.isReady;
118
- json['isDoneDate'] = this.isDoneDate?.toISOString();
119
- json['launchedBy'] = this.launchedBy;
120
- json['name'] = this.name;
121
- return json;
122
- }
123
-
124
- public addRadarLinks(linksToAdd: Link[] | RaainNode[]): void {
125
- this.addLinks(RainComputationAbstract._getRadarLinks(linksToAdd));
126
- }
127
-
128
- public replaceRainLink(linksToAdd: Link | RaainNode | any): void {
129
- this.addLinks([RainComputationAbstract._getRainLink(linksToAdd)]);
130
- }
131
-
132
- public addRadarMeasureLinks(linksToAdd: Link[] | any[]): void {
133
- this.addLinks(RainComputationAbstract._getRadarMeasureLinks(linksToAdd));
134
- }
135
-
136
- public getBuiltMergeTools(rainMeasures: RainMeasure[], options: {
137
- cartesianTools: CartesianTools,
138
- mergeLimitPoints: LatLng[]
139
- }) {
140
- this.buildLatLngMatrix(options);
141
- this.buildMergeTools(rainMeasures);
142
- return this.mergeTools;
143
- }
144
-
145
- public getMergeLatLngIndex(cartesianValue: CartesianValue) {
146
-
147
- const latLng = this.mergeTools.cartesianTools.getLatLngFromEarthMap(cartesianValue);
148
- const latLngScale = this.mergeTools.cartesianTools.getScaleLatLngFromEarth(latLng);
149
-
150
- const latIndex = Math.round((latLng.lat - this.mergeTools.limitPoints[0].lat) / latLngScale.lat);
151
- const lngIndex = Math.round((latLng.lng - this.mergeTools.limitPoints[0].lng) / latLngScale.lng);
152
-
153
- return {index: [latIndex, lngIndex], latLng};
154
- }
155
-
156
- protected buildLatLngMatrix(options: {
157
- cartesianTools: CartesianTools,
158
- mergeLimitPoints: LatLng[]
159
- }) {
160
- const latsLngs: MergeLatLng[][] = [];
161
- this.mergeTools = {latsLngs, cartesianTools: options.cartesianTools, limitPoints: []};
162
- if (!options.mergeLimitPoints) {
163
- return this.mergeTools;
164
- }
165
-
166
- const downPoint = options.cartesianTools.getLatLngFromEarthMap(options.mergeLimitPoints[0]);
167
- const topPoint = options.cartesianTools.getLatLngFromEarthMap(options.mergeLimitPoints[1]);
168
- const scaleLat = options.cartesianTools.getScaleLatLng(downPoint);
169
-
170
- for (let lat = downPoint.lat; lat <= topPoint.lat; lat += scaleLat.lat) {
171
- lat = CartesianTools.LimitWithPrecision(lat);
172
- const latLng = new LatLng({lat, lng: downPoint.lng});
173
- const scaleLng = options.cartesianTools.getScaleLatLng(latLng);
174
- const lngCount = Math.round((topPoint.lng - downPoint.lng) / scaleLng.lng) + 1;
175
- const lngs = [];
176
- for (let i = 0; i < lngCount; i++) {
177
- const initValue: MergeLatLng = {sum: 0, max: 0, count: 0, latLng: undefined};
178
- lngs.push(initValue);
179
- }
180
- latsLngs.push(lngs);
181
- }
182
-
183
- this.mergeTools = {latsLngs, cartesianTools: options.cartesianTools, limitPoints: [downPoint, topPoint]};
184
- return this.mergeTools;
185
- }
186
-
187
- protected buildMergeTools(rainMeasures: RainMeasure[]) {
188
- for (const rainMeasure of rainMeasures) {
189
- for (const value of rainMeasure.values) {
190
- if (typeof value['cartesianValues'] !== 'undefined') {
191
- const cartesianMeasureValue = new CartesianMeasureValue(value as any);
192
- const cartesianValues = cartesianMeasureValue.getCartesianValues();
193
- for (const cartesianValue of cartesianValues) {
194
- const {index, latLng} = this.getMergeLatLngIndex(cartesianValue);
195
- if (index[0] >= 0 && index[1] >= 0 && index[0] < this.mergeTools.latsLngs.length &&
196
- index[1] < this.mergeTools.latsLngs[index[0]].length) {
197
- this.mergeTools.latsLngs[index[0]][index[1]].latLng = CartesianTools.CreateLatLng(latLng);
198
- this.mergeTools.latsLngs[index[0]][index[1]].sum += cartesianValue.value;
199
- this.mergeTools.latsLngs[index[0]][index[1]].max = Math.max(
200
- cartesianValue.value, this.mergeTools.latsLngs[index[0]][index[1]].max);
201
- this.mergeTools.latsLngs[index[0]][index[1]].count++;
202
- } else {
203
- // throw new Error(`Wrong mergeRainMeasure ${latLngIndex[0]} ${latLngIndex[1]}`);
204
- }
205
- }
206
- }
207
- }
208
- }
209
- }
210
-
211
- protected getLinkType(): string {
212
- throw Error('abstract');
213
- }
214
-
215
- protected mergeRainMeasures(rainMeasures: RainMeasure[],
216
- options: {
217
- mergeStrategy: MergeStrategy,
218
- mergeLimitPoints: [LatLng, LatLng],
219
- removeNullValues?: boolean,
220
- }): RainMeasure[] {
221
-
222
- if (rainMeasures.length === 0) {
223
- return [];
224
- }
225
-
226
- this.buildMergeTools(rainMeasures);
227
-
228
- const firstCartesianRainMeasure = rainMeasures[0];
229
- const cartesianValuesMerged = this.buildMergeCartesianValues(options.mergeStrategy, options.removeNullValues);
230
-
231
- const rm = new RainMeasure(firstCartesianRainMeasure.toJSON());
232
- rm.values = [new RainCartesianMeasureValue({
233
- cartesianValues: cartesianValuesMerged,
234
- version: firstCartesianRainMeasure.getVersion(),
235
- limitPoints: options.mergeLimitPoints,
236
- })];
237
-
238
- return [rm];
239
- }
240
-
241
- protected buildMergeCartesianValues(mergeStrategy: MergeStrategy, removeNullValues = false) {
242
- const cartesianValuesMerged: CartesianValue[] = [];
243
- for (const [latIndex, latValues] of this.mergeTools.latsLngs.entries()) {
244
- for (const [lngIndex, mergeValue] of latValues.entries()) {
245
- let value = mergeValue.sum;
246
- if (mergeStrategy === MergeStrategy.AVERAGE) {
247
- value = mergeValue.count ? value / mergeValue.count : -1;
248
- } else if (mergeStrategy === MergeStrategy.MAX) {
249
- value = mergeValue.max;
250
- }
251
-
252
- if (mergeValue.count && !(removeNullValues && !value)) {
253
- const lat = mergeValue.latLng.lat;
254
- const lng = mergeValue.latLng.lng;
255
- cartesianValuesMerged.push(new CartesianValue({value, lat, lng}));
256
- }
257
- }
258
- }
259
- return cartesianValuesMerged;
260
- }
261
-
262
- }
@@ -1,25 +0,0 @@
1
- import {Measure} from '../organization';
2
- import {IPolarMeasureValue} from '../polar';
3
- import {ICartesianMeasureValue} from '../cartesian';
4
-
5
- /**
6
- * api/rains/:id/computations/:id?format=map => RainComputationMap getMapData() => RainMeasure[]
7
- */
8
- export class RainMeasure extends Measure {
9
-
10
- public static TYPE = 'rain-measure';
11
-
12
- constructor(json: {
13
- id: string,
14
- values: IPolarMeasureValue[] | ICartesianMeasureValue[] | number[],
15
- date?: Date,
16
- validity?: number,
17
- configurationAsJSON?: string,
18
- }) {
19
- super(json);
20
- }
21
-
22
- protected getLinkType(): string {
23
- return RainMeasure.TYPE;
24
- }
25
- }
@@ -1,235 +0,0 @@
1
- import {Link, RaainNode, TeamNode} from '../organization';
2
- import {RadarNode} from '../radar';
3
- import {RainComputation} from './RainComputation';
4
- import {GaugeNode} from '../gauge';
5
- import {LatLng} from '../cartesian';
6
-
7
- /**
8
- * api/rains/:id
9
- */
10
- export class RainNode extends RaainNode {
11
-
12
- public static TYPE = 'rain';
13
-
14
- public name: string;
15
- public description: string;
16
- public team: TeamNode;
17
- public status: number;
18
- public quality: number;
19
- public latLngRectsAsJSON: string;
20
-
21
- // internal
22
- private configurationAsJSON: string;
23
-
24
- constructor(json: {
25
- id: string,
26
- name: string,
27
- team: TeamNode,
28
- description?: string,
29
- links?: Link[] | RaainNode[],
30
- version?: string,
31
- status?: number,
32
- quality?: number,
33
- radars?: RadarNode[],
34
- gauges?: GaugeNode[],
35
- latLngRectsAsJSON?: string,
36
- configurationAsJSON?: any,
37
- lastCompletedComputations?: RainComputation[],
38
- }) {
39
- super(json);
40
-
41
- const links = json?.links ? json.links as any[] : [];
42
-
43
- this.name = json.name;
44
- this.description = json.description;
45
- this.team = json.team;
46
- this.status = json.status >= 0 ? json.status : -1;
47
- this.quality = json.quality >= 0 ? json.quality : -1;
48
- this.latLngRectsAsJSON = json.latLngRectsAsJSON;
49
-
50
- this.addRadars(links.filter(l => l instanceof RadarNode));
51
- this.addRadars(json.radars);
52
- this.addGauges(links.filter(l => l instanceof GaugeNode));
53
- this.addGauges(json.gauges);
54
- this.setConfiguration(json.configurationAsJSON);
55
- this.addCompletedComputations(links.filter(l => l instanceof RainComputation));
56
- this.addCompletedComputations(json.lastCompletedComputations);
57
- }
58
-
59
- private static _getRadarLinks(linksToPurify: any[]): any[] {
60
- if (!linksToPurify || linksToPurify.length === 0) {
61
- return [];
62
- }
63
-
64
- const linksPurified = linksToPurify.map(l => {
65
- if (l instanceof Link) {
66
- return l;
67
- } else if (l && l['_id']) {
68
- return new RadarNode({id: l['_id'].toString(), latitude: l.latitude, longitude: l.latitude, name: l.name, team: l.team});
69
- } else if (l && l.id) {
70
- return new RadarNode({id: l.id.toString(), latitude: l.latitude, longitude: l.longitude, name: l.name, team: l.team});
71
- }
72
- });
73
-
74
- return linksPurified.filter(l => !!l);
75
- }
76
-
77
- private static _getRainComputationLinks(linksToPurify: any[]): any[] {
78
- if (!linksToPurify || linksToPurify.length === 0) {
79
- return [];
80
- }
81
-
82
- const linksPurified = linksToPurify.map(l => {
83
- if (l instanceof Link) {
84
- return l;
85
- } else if (l && l['_id']) {
86
- return new RainComputation({
87
- id: l['_id'].toString(),
88
- date: l.date, version: l.version,
89
- isReady: null, results: null,
90
- });
91
- } else if (l && l.id) {
92
- return new RainComputation({
93
- id: l.id.toString(),
94
- date: l.date, version: l.version,
95
- isReady: null, results: null
96
- });
97
- }
98
- });
99
-
100
- return linksPurified.filter(l => !!l);
101
- }
102
-
103
- private static _getGaugeLinks(linksToPurify: any[]): any[] {
104
- if (!linksToPurify || linksToPurify.length === 0) {
105
- return [];
106
- }
107
-
108
- const linksPurified = linksToPurify.map(l => {
109
- if (l instanceof Link) {
110
- return l;
111
- } else if (l && l['_id']) {
112
- return new GaugeNode({id: l['_id'].toString(), latitude: l.latitude, longitude: l.longitude, name: l.name, team: l.team});
113
- } else if (l && l.id) {
114
- return new GaugeNode({id: l.id.toString(), latitude: l.latitude, longitude: l.longitude, name: l.name, team: l.team});
115
- }
116
- });
117
-
118
- return linksPurified.filter(l => !!l);
119
- }
120
-
121
- public setConfiguration(configuration: string | any) {
122
- let conf = configuration;
123
- try {
124
- conf = JSON.parse(configuration);
125
- } catch (ignored) {
126
- }
127
-
128
- if (conf) {
129
- this.configurationAsJSON = JSON.stringify(conf);
130
- }
131
- }
132
-
133
- public getConfiguration(): any {
134
- try {
135
- return JSON.parse(this.configurationAsJSON);
136
- } catch (e) {
137
- }
138
- return null;
139
- }
140
-
141
- public toJSON(): any {
142
- const json = super.toJSON();
143
- json['name'] = this.name;
144
- json['description'] = this.description;
145
- json['status'] = this.status;
146
- json['quality'] = this.quality;
147
- json['team'] = this.team?.id || this.team;
148
- json['latLngRectsAsJSON'] = this.latLngRectsAsJSON;
149
- json['configurationAsJSON'] = this.configurationAsJSON;
150
- json['radars'] = this.links.filter(l => l.getLinkType() === RadarNode.TYPE).map(l => l.getId());
151
- json['gauges'] = this.links.filter(l => l.getLinkType() === GaugeNode.TYPE).map(l => l.getId());
152
- json['lastCompletedComputations'] = this.links.filter(l => l.getLinkType() === RainComputation.TYPE).map(l => l.getId());
153
- return json;
154
- }
155
-
156
- public addRadars(linksToAdd: Link[] | RadarNode[]): void {
157
- this.addLinks(RainNode._getRadarLinks(linksToAdd));
158
- this.setDefaultLatLng(linksToAdd);
159
- }
160
-
161
- public addCompletedComputations(linksToAdd: Link[] | RainComputation[]): void {
162
- this.addLinks(RainNode._getRainComputationLinks(linksToAdd));
163
- }
164
-
165
- public addGauges(linksToAdd: Link[] | GaugeNode[]): void {
166
- this.addLinks(RainNode._getGaugeLinks(linksToAdd));
167
- }
168
-
169
- public getCenter(): LatLng {
170
-
171
- let center = new LatLng({lat: 0, lng: 0});
172
-
173
- this.setDefaultLatLng(this['radars'])
174
-
175
- if (this.latLngRectsAsJSON && this.latLngRectsAsJSON !== '[]') {
176
- const rects = JSON.parse(this.latLngRectsAsJSON);
177
- let latMax: number, lngMax: number, latMin: number, lngMin: number;
178
- for (const rect of rects) {
179
- const topLeft = rect[0];
180
- const bottomRight = rect[1];
181
- latMax = typeof latMax === 'undefined' ? topLeft.lat : Math.max(topLeft.lat, latMax);
182
- lngMin = typeof lngMin === 'undefined' ? topLeft.lng : Math.min(topLeft.lng, lngMin);
183
- latMin = typeof latMin === 'undefined' ? bottomRight.lat : Math.min(bottomRight.lat, latMin);
184
- lngMax = typeof lngMax === 'undefined' ? bottomRight.lng : Math.max(bottomRight.lng, lngMax);
185
- }
186
-
187
- center = new LatLng({lat: ((latMax - latMin) / 2) + latMin, lng: ((lngMax - lngMin) / 2) + lngMin})
188
- }
189
-
190
- return center;
191
- }
192
-
193
- public getLimitPoints(): [LatLng, LatLng] {
194
- let limitPoints: [LatLng, LatLng];
195
-
196
- this.setDefaultLatLng(this['radars']);
197
-
198
- if (this.latLngRectsAsJSON && this.latLngRectsAsJSON !== '[]') {
199
- const rects = JSON.parse(this.latLngRectsAsJSON);
200
- let latMax: number, lngMax: number, latMin: number, lngMin: number;
201
- for (const rect of rects) {
202
- const rectA = rect[0];
203
- const rectB = rect[1];
204
- latMax = Math.max(rectA.lat, rectB.lat, typeof latMax !== 'undefined' ? latMax : rectA.lat);
205
- lngMin = Math.min(rectA.lng, rectB.lng, typeof lngMin !== 'undefined' ? lngMin : rectA.lng);
206
- latMin = Math.min(rectA.lat, rectB.lat, typeof latMin !== 'undefined' ? latMin : rectB.lat);
207
- lngMax = Math.max(rectA.lng, rectB.lng, typeof lngMax !== 'undefined' ? lngMax : rectB.lng);
208
- }
209
-
210
- limitPoints = [new LatLng({lat: latMin, lng: lngMin}), new LatLng({lat: latMax, lng: lngMax})];
211
- }
212
-
213
- return limitPoints;
214
- }
215
-
216
- protected getLinkType(): string {
217
- return RainNode.TYPE;
218
- }
219
-
220
- private setDefaultLatLng(radars: any[]) {
221
- // TODO put a default latLngRectsAsJSON based on cartesianTools earth ?
222
- if (radars?.length && (!this.latLngRectsAsJSON || this.latLngRectsAsJSON === '[]')) {
223
- const latLngRects = [];
224
- for (const radarNode of radars) {
225
- if (radarNode instanceof RadarNode) {
226
- latLngRects.push([
227
- new LatLng({lat: radarNode.latitude + 1, lng: radarNode.longitude - 1}),
228
- new LatLng({lat: radarNode.latitude - 1, lng: radarNode.longitude + 1})]);
229
- }
230
- }
231
-
232
- this.latLngRectsAsJSON = JSON.stringify(latLngRects);
233
- }
234
- }
235
- }
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2018",
4
- "module": "commonjs",
5
- "declaration": true,
6
- "sourceMap": true,
7
- "outDir": "dist"
8
- },
9
- "exclude": [
10
- "node_modules",
11
- "dist",
12
- "examples",
13
- "specs",
14
- "coverage",
15
- ".coverage"
16
- ]
17
- }