@golemio/chmu 1.2.0 → 1.2.1-dev.2699381352

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 (62) hide show
  1. package/db/migrations/postgresql/20260619120000-opendata-columns.js +49 -0
  2. package/db/migrations/postgresql/sqls/20260619120000-opendata-columns-down.sql +36 -0
  3. package/db/migrations/postgresql/sqls/20260619120000-opendata-columns-up.sql +40 -0
  4. package/dist/integration-engine/data-access/MeasurementsRepository.js +1 -1
  5. package/dist/integration-engine/data-access/MeasurementsRepository.js.map +1 -1
  6. package/dist/integration-engine/data-access/StationsRepository.d.ts +8 -0
  7. package/dist/integration-engine/data-access/StationsRepository.js +57 -0
  8. package/dist/integration-engine/data-access/StationsRepository.js.map +1 -0
  9. package/dist/integration-engine/datasources/AbstractOpendataDatasource.d.ts +19 -0
  10. package/dist/integration-engine/datasources/AbstractOpendataDatasource.js +47 -0
  11. package/dist/integration-engine/datasources/AbstractOpendataDatasource.js.map +1 -0
  12. package/dist/integration-engine/datasources/OpendataDatasource.d.ts +8 -0
  13. package/dist/integration-engine/datasources/OpendataDatasource.js +37 -0
  14. package/dist/integration-engine/datasources/OpendataDatasource.js.map +1 -0
  15. package/dist/integration-engine/datasources/OpendataHistoricalDatasource.d.ts +8 -0
  16. package/dist/integration-engine/datasources/OpendataHistoricalDatasource.js +38 -0
  17. package/dist/integration-engine/datasources/OpendataHistoricalDatasource.js.map +1 -0
  18. package/dist/integration-engine/ioc/Di.js +12 -0
  19. package/dist/integration-engine/ioc/Di.js.map +1 -1
  20. package/dist/integration-engine/ioc/ModuleContainerToken.d.ts +6 -0
  21. package/dist/integration-engine/ioc/ModuleContainerToken.js +8 -0
  22. package/dist/integration-engine/ioc/ModuleContainerToken.js.map +1 -1
  23. package/dist/integration-engine/transformations/MeasurementsTransformation.js +18 -0
  24. package/dist/integration-engine/transformations/MeasurementsTransformation.js.map +1 -1
  25. package/dist/integration-engine/transformations/OpendataMeasurementsTransformation.d.ts +15 -0
  26. package/dist/integration-engine/transformations/OpendataMeasurementsTransformation.js +128 -0
  27. package/dist/integration-engine/transformations/OpendataMeasurementsTransformation.js.map +1 -0
  28. package/dist/integration-engine/workers/ChmuWorker.js +2 -0
  29. package/dist/integration-engine/workers/ChmuWorker.js.map +1 -1
  30. package/dist/integration-engine/workers/interfaces/IDownloadOpendataHistoricalMessage.d.ts +10 -0
  31. package/dist/integration-engine/workers/interfaces/IDownloadOpendataHistoricalMessage.js +3 -0
  32. package/dist/integration-engine/workers/interfaces/IDownloadOpendataHistoricalMessage.js.map +1 -0
  33. package/dist/integration-engine/workers/interfaces/IDownloadOpendataMessage.d.ts +8 -0
  34. package/dist/integration-engine/workers/interfaces/IDownloadOpendataMessage.js +3 -0
  35. package/dist/integration-engine/workers/interfaces/IDownloadOpendataMessage.js.map +1 -0
  36. package/dist/integration-engine/workers/tasks/DownloadMeasurementsTask.js +2 -2
  37. package/dist/integration-engine/workers/tasks/DownloadMeasurementsTask.js.map +1 -1
  38. package/dist/integration-engine/workers/tasks/DownloadOpendataHistoricalMeasurementsTask.d.ts +26 -0
  39. package/dist/integration-engine/workers/tasks/DownloadOpendataHistoricalMeasurementsTask.js +149 -0
  40. package/dist/integration-engine/workers/tasks/DownloadOpendataHistoricalMeasurementsTask.js.map +1 -0
  41. package/dist/integration-engine/workers/tasks/DownloadOpendataHistoricalMessageSchema.d.ts +7 -0
  42. package/dist/integration-engine/workers/tasks/DownloadOpendataHistoricalMessageSchema.js +40 -0
  43. package/dist/integration-engine/workers/tasks/DownloadOpendataHistoricalMessageSchema.js.map +1 -0
  44. package/dist/integration-engine/workers/tasks/DownloadOpendataMeasurementsTask.d.ts +22 -0
  45. package/dist/integration-engine/workers/tasks/DownloadOpendataMeasurementsTask.js +112 -0
  46. package/dist/integration-engine/workers/tasks/DownloadOpendataMeasurementsTask.js.map +1 -0
  47. package/dist/integration-engine/workers/tasks/DownloadOpendataMessageSchema.d.ts +6 -0
  48. package/dist/integration-engine/workers/tasks/DownloadOpendataMessageSchema.js +33 -0
  49. package/dist/integration-engine/workers/tasks/DownloadOpendataMessageSchema.js.map +1 -0
  50. package/dist/schema-definitions/datasources/OpendataSchemaProvider.d.ts +55 -0
  51. package/dist/schema-definitions/datasources/OpendataSchemaProvider.js +47 -0
  52. package/dist/schema-definitions/datasources/OpendataSchemaProvider.js.map +1 -0
  53. package/dist/schema-definitions/datasources/interfaces/IInputOpendataRecord.d.ts +15 -0
  54. package/dist/schema-definitions/datasources/interfaces/IInputOpendataRecord.js +3 -0
  55. package/dist/schema-definitions/datasources/interfaces/IInputOpendataRecord.js.map +1 -0
  56. package/dist/schema-definitions/definitions/interfaces/IMeasurementDto.d.ts +18 -0
  57. package/dist/schema-definitions/definitions/models/MeasurementModel.d.ts +18 -0
  58. package/dist/schema-definitions/definitions/models/MeasurementModel.js +37 -1
  59. package/dist/schema-definitions/definitions/models/MeasurementModel.js.map +1 -1
  60. package/docs/asyncapi.yaml +78 -3
  61. package/docs/implementation_documentation.md +114 -23
  62. package/package.json +1 -1
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.OpendataMeasurementsTransformation = void 0;
10
+ const AbstractTransformation_1 = require("@golemio/core/dist/helpers/transformation/AbstractTransformation");
11
+ const luxon_1 = require("@golemio/core/dist/shared/luxon");
12
+ const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
13
+ /**
14
+ * Maps ČHMÚ opendata ELEMENT codes to IMeasurementDto columns.
15
+ * Optional transform function applies per-element unit conversion.
16
+ */
17
+ const ELEMENT_COLUMN = {
18
+ T: { column: "air_temp" },
19
+ H: { column: "air_hum" },
20
+ P: { column: "air_pressure" },
21
+ F: { column: "wind_speed" },
22
+ D: { column: "wind_dir" },
23
+ SRA10M: { column: "precip" },
24
+ // SSV10M: sunshine duration in seconds over the last 10 minutes (max 600 s).
25
+ // DB stores sunlight in tenths of an hour (1 tenth = 6 min = 360 s), same unit as FTP SSV1H.
26
+ // Max per 10-min interval: 600 s / 360 ≈ 1.67 tenths.
27
+ SSV10M: { column: "sunlight", transform: (v) => v / 360 },
28
+ TMA: { column: "air_temp_max" },
29
+ TMI: { column: "air_temp_min" },
30
+ TPM: { column: "air_temp_ground" },
31
+ Fprum: { column: "wind_speed_avg" },
32
+ Dprum: { column: "wind_dir_avg" },
33
+ Fmax: { column: "wind_gust" },
34
+ Dmax: { column: "wind_gust_dir" },
35
+ Casmax: { column: "wind_gust_time" },
36
+ SCEa: { column: "snow_depth" },
37
+ SVHa: { column: "snow_water" },
38
+ RGLB10: { column: "radiation_glob" },
39
+ REUV10: { column: "radiation_uv" },
40
+ REUV25: { column: "radiation_uv" },
41
+ T05: { column: "soil_temp_5cm" },
42
+ T10: { column: "soil_temp_10cm" },
43
+ T20: { column: "soil_temp_20cm" },
44
+ T50: { column: "soil_temp_50cm" },
45
+ T100: { column: "soil_temp_100cm" },
46
+ };
47
+ let OpendataMeasurementsTransformation = class OpendataMeasurementsTransformation extends AbstractTransformation_1.AbstractTransformation {
48
+ constructor() {
49
+ super(...arguments);
50
+ this.name = "OpendataMeasurementsTransformation";
51
+ this.transformInternal = (records) => {
52
+ const { station_id, DT } = records[0]; // group key — same across all records
53
+ const dt = luxon_1.DateTime.fromISO(DT).setZone("Europe/Prague");
54
+ if (!dt.isValid) {
55
+ return null;
56
+ }
57
+ const dto = {
58
+ measured_at: dt.toUTC().toISO(),
59
+ station_id,
60
+ year: dt.year,
61
+ month: dt.month,
62
+ day: dt.day,
63
+ time: dt.toFormat("HH:mm"),
64
+ air_temp: null,
65
+ air_hum: null,
66
+ precip: null,
67
+ air_pressure: null,
68
+ wind_speed: null,
69
+ wind_dir: null,
70
+ sunlight: null,
71
+ soil_hum_0_10: null,
72
+ soil_hum_10_50: null,
73
+ soil_hum_50_100: null,
74
+ air_temp_max: null,
75
+ air_temp_min: null,
76
+ air_temp_ground: null,
77
+ wind_speed_avg: null,
78
+ wind_dir_avg: null,
79
+ wind_gust: null,
80
+ wind_gust_dir: null,
81
+ wind_gust_time: null,
82
+ snow_depth: null,
83
+ snow_water: null,
84
+ radiation_glob: null,
85
+ radiation_uv: null,
86
+ soil_temp_5cm: null,
87
+ soil_temp_10cm: null,
88
+ soil_temp_20cm: null,
89
+ soil_temp_50cm: null,
90
+ soil_temp_100cm: null,
91
+ data_source: "opendata",
92
+ };
93
+ for (const record of records) {
94
+ const mapping = ELEMENT_COLUMN[record.ELEMENT];
95
+ if (!mapping || record.VAL === "") {
96
+ continue;
97
+ }
98
+ dto[mapping.column] = mapping.transform ? mapping.transform(record.VAL) : record.VAL;
99
+ }
100
+ return dto;
101
+ };
102
+ }
103
+ /**
104
+ * Pivots long-format opendata records into wide IMeasurementDto rows.
105
+ * Groups by (station_id, DT) and maps each ELEMENT to its DB column.
106
+ * DT is UTC ISO 8601; year/month/day/time are expressed in Europe/Prague local time.
107
+ */
108
+ async transform(data) {
109
+ const groups = this.groupByStationAndDt(data);
110
+ return this.transformArray(groups).filter((dto) => dto !== null);
111
+ }
112
+ groupByStationAndDt(data) {
113
+ const groups = new Map();
114
+ for (const record of data) {
115
+ const key = `${record.station_id}|${record.DT}`;
116
+ if (!groups.has(key)) {
117
+ groups.set(key, []);
118
+ }
119
+ groups.get(key).push(record);
120
+ }
121
+ return Array.from(groups.values());
122
+ }
123
+ };
124
+ exports.OpendataMeasurementsTransformation = OpendataMeasurementsTransformation;
125
+ exports.OpendataMeasurementsTransformation = OpendataMeasurementsTransformation = __decorate([
126
+ (0, tsyringe_1.injectable)()
127
+ ], OpendataMeasurementsTransformation);
128
+ //# sourceMappingURL=OpendataMeasurementsTransformation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpendataMeasurementsTransformation.js","sourceRoot":"","sources":["../../../src/integration-engine/transformations/OpendataMeasurementsTransformation.ts"],"names":[],"mappings":";;;;;;;;;AAGA,6GAA0G;AAC1G,2DAA2D;AAC3D,iEAAgE;AAahE;;;GAGG;AACH,MAAM,cAAc,GAA6C;IAC7D,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE;IACzB,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE;IACxB,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE;IAC7B,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE;IAC3B,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE;IACzB,MAAM,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;IAC5B,6EAA6E;IAC7E,6FAA6F;IAC7F,sDAAsD;IACtD,MAAM,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE;IACzD,GAAG,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE;IAC/B,GAAG,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE;IAC/B,GAAG,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE;IAClC,KAAK,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE;IACnC,KAAK,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE;IACjC,IAAI,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE;IAC7B,IAAI,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE;IACjC,MAAM,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE;IACpC,IAAI,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE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,cAAc,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAA0B,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC;IAC7F,CAAC;IAyDO,mBAAmB,CAAC,IAA4B;QACpD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkC,CAAC;QACzD,KAAK,MAAM,MAAM,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;YAChD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACnB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACxB,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACvC,CAAC;CACJ,CAAA;AAlFY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,qBAAU,GAAE;GACA,kCAAkC,CAkF9C"}
@@ -15,6 +15,8 @@ class ChmuWorker extends workers_1.AbstractWorker {
15
15
  };
16
16
  // Register tasks
17
17
  this.registerTask(Di_1.ChmuContainer.resolve(ModuleContainerToken_1.ModuleContainerToken.DownloadMeasurementsTask));
18
+ this.registerTask(Di_1.ChmuContainer.resolve(ModuleContainerToken_1.ModuleContainerToken.DownloadOpendataMeasurementsTask));
19
+ this.registerTask(Di_1.ChmuContainer.resolve(ModuleContainerToken_1.ModuleContainerToken.DownloadOpendataHistoricalMeasurementsTask));
18
20
  }
19
21
  }
20
22
  exports.ChmuWorker = ChmuWorker;
@@ -1 +1 @@
1
- {"version":3,"file":"ChmuWorker.js","sourceRoot":"","sources":["../../../src/integration-engine/workers/ChmuWorker.ts"],"names":[],"mappings":";;;AAAA,kCAA2C;AAC3C,sEAA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 export default interface IDownloadOpendataHistoricalMessage {
2
+ /** ISO 8601 timestamp - inclusive start of the range to download. Required; no default. */
3
+ from: string;
4
+ /** ISO 8601 timestamp - exclusive end of the range to download. Required; no default. */
5
+ to: string;
6
+ /** Station ID from chmu.stations. When set together with wsi, task runs in single-station mode. */
7
+ station_id?: string;
8
+ /** WSI identifier of the station. When set together with station_id, task runs in single-station mode. */
9
+ wsi?: string;
10
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IDownloadOpendataHistoricalMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IDownloadOpendataHistoricalMessage.js","sourceRoot":"","sources":["../../../../src/integration-engine/workers/interfaces/IDownloadOpendataHistoricalMessage.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export default interface IDownloadOpendataMessage {
2
+ /** ISO 8601 date to fetch opendata for. Defaults to today when omitted. */
3
+ date?: string;
4
+ /** WSI identifier of the station. When set together with station_id, task runs in single-station mode. */
5
+ wsi?: string;
6
+ /** Station ID from chmu.stations. Required when wsi is set. */
7
+ station_id?: string;
8
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IDownloadOpendataMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IDownloadOpendataMessage.js","sourceRoot":"","sources":["../../../../src/integration-engine/workers/interfaces/IDownloadOpendataMessage.ts"],"names":[],"mappings":""}
@@ -20,12 +20,12 @@ const ChmuDatasource_1 = __importDefault(require("../../datasources/ChmuDatasour
20
20
  const ModuleContainerToken_1 = require("../../ioc/ModuleContainerToken");
21
21
  const MeasurementsTransformation_1 = require("../../transformations/MeasurementsTransformation");
22
22
  const integration_engine_1 = require("@golemio/core/dist/integration-engine");
23
- const ContainerToken_1 = require("@golemio/core/dist/integration-engine/ioc/ContainerToken");
24
23
  const QueueManager_1 = require("@golemio/core/dist/integration-engine/queueprocessors/QueueManager");
25
24
  const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
26
25
  const luxon_1 = require("@golemio/core/dist/shared/luxon");
27
26
  const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
28
27
  const DownloadMeasurementsMessageSchema_1 = require("./DownloadMeasurementsMessageSchema");
28
+ const CoreToken_1 = require("@golemio/core/dist/helpers/ioc/CoreToken");
29
29
  let DownloadMeasurementsTask = class DownloadMeasurementsTask extends integration_engine_1.AbstractTask {
30
30
  constructor(datasource, transformation, repository, logger) {
31
31
  super(""); // done in worker
@@ -88,7 +88,7 @@ DownloadMeasurementsTask = __decorate([
88
88
  __param(0, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.ChmuDatasource)),
89
89
  __param(1, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.MeasurementsTransformation)),
90
90
  __param(2, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.MeasurementsRepository)),
91
- __param(3, (0, tsyringe_1.inject)(ContainerToken_1.ContainerToken.Logger)),
91
+ __param(3, (0, tsyringe_1.inject)(CoreToken_1.CoreToken.Logger)),
92
92
  __metadata("design:paramtypes", [ChmuDatasource_1.default,
93
93
  MeasurementsTransformation_1.MeasurementsTransformation,
94
94
  MeasurementsRepository_1.MeasurementsRepository, Object])
@@ -1 +1 @@
1
- {"version":3,"file":"DownloadMeasurementsTask.js","sourceRoot":"","sources":["../../../../src/integration-engine/workers/tasks/DownloadMeasurementsTask.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qFAAgF;AAChF,sFAA4D;AAC5D,yEAAoE;AACpE,iGAA4F;AAE5F,8EAAqE;AACrE,6FAA0F;AAC1F,qGAAkG;AAClG,6EAAgF;AAChF,2DAA2D;AAC3D,iEAAwE;AAGxE,2FAAwF;AAGzE,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,iCAA0C;IAI5F,YACiD,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,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QAEhH,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IACxB,CAAC;CAaJ,CAAA;AAnEoB,wBAAwB;IAD5C,IAAA,qBAAU,GAAE;IAMJ,WAAA,IAAA,iBAAM,EAAC,2CAAoB,CAAC,cAAc,CAAC,CAAA;IAC3C,WAAA,IAAA,iBAAM,EAAC,2CAAoB,CAAC,0BAA0B,CAAC,CAAA;IACvD,WAAA,IAAA,iBAAM,EAAC,2CAAoB,CAAC,sBAAsB,CAAC,CAAA;IACnD,WAAA,IAAA,iBAAM,EAAC,+BAAc,CAAC,MAAM,CAAC,CAAA;qCAHmC,wBAAc;QACE,uDAA0B;QAClC,+CAAsB;GAPlF,wBAAwB,CAmE5C;kBAnEoB,wBAAwB"}
1
+ {"version":3,"file":"DownloadMeasurementsTask.js","sourceRoot":"","sources":["../../../../src/integration-engine/workers/tasks/DownloadMeasurementsTask.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qFAAgF;AAChF,sFAA4D;AAC5D,yEAAoE;AACpE,iGAA4F;AAE5F,8EAAqE;AACrE,qGAAkG;AAClG,6EAAgF;AAChF,2DAA2D;AAC3D,iEAAwE;AAGxE,2FAAwF;AACxF,wEAAqE;AAGtD,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,iCAA0C;IAI5F,YACiD,UAAkC,EACtB,cAAkD,EACtD,UAA0C,EACrE,MAAuB;QAEjD,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB;QALyB,eAAU,GAAV,UAAU,CAAgB;QACd,mBAAc,GAAd,cAAc,CAA4B;QAC9C,eAAU,GAAV,UAAU,CAAwB;QAC7D,WAAM,GAAN,MAAM,CAAS;QAP9C,cAAS,GAAW,0BAA0B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IAAA,qBAAU,GAAE;IAMJ,WAAA,IAAA,iBAAM,EAAC,2CAAoB,CAAC,cAAc,CAAC,CAAA;IAC3C,WAAA,IAAA,iBAAM,EAAC,2CAAoB,CAAC,0BAA0B,CAAC,CAAA;IACvD,WAAA,IAAA,iBAAM,EAAC,2CAAoB,CAAC,sBAAsB,CAAC,CAAA;IACnD,WAAA,IAAA,iBAAM,EAAC,qBAAS,CAAC,MAAM,CAAC,CAAA;qCAHwC,wBAAc;QACE,uDAA0B;QAClC,+CAAsB;GAPlF,wBAAwB,CAmE5C;kBAnEoB,wBAAwB"}
@@ -0,0 +1,26 @@
1
+ import { StationsRepository } from "../../data-access/StationsRepository";
2
+ import { MeasurementsRepository } from "../../data-access/MeasurementsRepository";
3
+ import OpendataHistoricalDatasource from "../../datasources/OpendataHistoricalDatasource";
4
+ import { OpendataMeasurementsTransformation } from "../../transformations/OpendataMeasurementsTransformation";
5
+ import { ILogger } from "@golemio/core/dist/helpers/logger/LoggerProvider";
6
+ import { AbstractTask } from "@golemio/core/dist/integration-engine";
7
+ import IDownloadOpendataHistoricalMessage from "../interfaces/IDownloadOpendataHistoricalMessage";
8
+ import { DownloadOpendataHistoricalMessageSchema } from "./DownloadOpendataHistoricalMessageSchema";
9
+ export default class DownloadOpendataHistoricalMeasurementsTask extends AbstractTask<IDownloadOpendataHistoricalMessage> {
10
+ private stationsRepository;
11
+ private datasource;
12
+ private transformation;
13
+ private repository;
14
+ private logger;
15
+ queueName: string;
16
+ protected schema: typeof DownloadOpendataHistoricalMessageSchema;
17
+ constructor(stationsRepository: StationsRepository, datasource: OpendataHistoricalDatasource, transformation: OpendataMeasurementsTransformation, repository: MeasurementsRepository, logger: ILogger);
18
+ protected execute: (data: IDownloadOpendataHistoricalMessage) => Promise<void>;
19
+ private generateSubtasks;
20
+ private processStation;
21
+ private generateStationMonthSubtasks;
22
+ private processStationMeasurements;
23
+ private validateRange;
24
+ /** Splits [from, to) into calendar-month intervals (UTC, matching DT's format); clips the first/last interval. */
25
+ private static generateMonthIntervals;
26
+ }
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ var DownloadOpendataHistoricalMeasurementsTask_1;
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ const StationsRepository_1 = require("../../data-access/StationsRepository");
20
+ const MeasurementsRepository_1 = require("../../data-access/MeasurementsRepository");
21
+ const OpendataHistoricalDatasource_1 = __importDefault(require("../../datasources/OpendataHistoricalDatasource"));
22
+ const ModuleContainerToken_1 = require("../../ioc/ModuleContainerToken");
23
+ const OpendataMeasurementsTransformation_1 = require("../../transformations/OpendataMeasurementsTransformation");
24
+ const integration_engine_1 = require("@golemio/core/dist/integration-engine");
25
+ const QueueManager_1 = require("@golemio/core/dist/integration-engine/queueprocessors/QueueManager");
26
+ const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
27
+ const luxon_1 = require("@golemio/core/dist/shared/luxon");
28
+ const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
29
+ const DownloadOpendataHistoricalMessageSchema_1 = require("./DownloadOpendataHistoricalMessageSchema");
30
+ const CoreToken_1 = require("@golemio/core/dist/helpers/ioc/CoreToken");
31
+ let DownloadOpendataHistoricalMeasurementsTask = DownloadOpendataHistoricalMeasurementsTask_1 = class DownloadOpendataHistoricalMeasurementsTask extends integration_engine_1.AbstractTask {
32
+ constructor(stationsRepository, datasource, transformation, repository, logger) {
33
+ super(""); // queue prefix is set by the worker
34
+ this.stationsRepository = stationsRepository;
35
+ this.datasource = datasource;
36
+ this.transformation = transformation;
37
+ this.repository = repository;
38
+ this.logger = logger;
39
+ this.queueName = "downloadOpendataHistoricalMeasurementsTask";
40
+ this.schema = DownloadOpendataHistoricalMessageSchema_1.DownloadOpendataHistoricalMessageSchema;
41
+ this.execute = async (data) => {
42
+ const { from, to } = this.validateRange(data);
43
+ try {
44
+ if (data.station_id && data.wsi) {
45
+ await this.processStation(data.station_id, data.wsi, from, to);
46
+ }
47
+ else {
48
+ await this.generateSubtasks(from, to);
49
+ }
50
+ }
51
+ catch (error) {
52
+ if (error instanceof golemio_errors_1.AbstractGolemioError) {
53
+ throw error;
54
+ }
55
+ throw new golemio_errors_1.GeneralError(`Unable to download chmu opendata historical measurements data.`, this.constructor.name, error);
56
+ }
57
+ };
58
+ }
59
+ async generateSubtasks(from, to) {
60
+ const stations = await this.stationsRepository.getStationsWithWsi();
61
+ if (stations.length === 0) {
62
+ this.logger.warn(`${this.constructor.name}: no stations with WSI found - skipping. Populate chmu.stations.wsi first.`);
63
+ return;
64
+ }
65
+ for (const station of stations) {
66
+ await this.generateStationMonthSubtasks(station.station_id, station.wsi, from, to);
67
+ }
68
+ }
69
+ async processStation(stationId, wsi, from, to) {
70
+ const intervals = DownloadOpendataHistoricalMeasurementsTask_1.generateMonthIntervals(from, to);
71
+ if (intervals.length === 1) {
72
+ await this.processStationMeasurements(stationId, wsi, intervals[0]);
73
+ }
74
+ else {
75
+ await this.generateStationMonthSubtasks(stationId, wsi, from, to);
76
+ }
77
+ }
78
+ async generateStationMonthSubtasks(stationId, wsi, from, to) {
79
+ const intervals = DownloadOpendataHistoricalMeasurementsTask_1.generateMonthIntervals(from, to);
80
+ for (const interval of intervals) {
81
+ await QueueManager_1.QueueManager.sendMessageToExchange(this.queuePrefix, this.queueName, {
82
+ station_id: stationId,
83
+ wsi,
84
+ from: interval.from.toISO(),
85
+ to: interval.to.toISO(),
86
+ });
87
+ }
88
+ this.logger.debug(`${this.constructor.name}: dispatched ${intervals.length} month subtasks for station ${stationId}.`);
89
+ }
90
+ async processStationMeasurements(stationId, wsi, interval) {
91
+ const rangeLabel = `${interval.from.toISO()} - ${interval.to.toISO()}`;
92
+ let stationRecords;
93
+ try {
94
+ stationRecords = await this.datasource.getData(wsi, interval.from.toJSDate());
95
+ }
96
+ catch (error) {
97
+ throw new golemio_errors_1.GeneralError(`${this.constructor.name}: failed to fetch data for station ${stationId} (WSI: ${wsi}, range ${rangeLabel}).`);
98
+ }
99
+ if (stationRecords.length === 0) {
100
+ this.logger.warn(`${this.constructor.name}: no records fetched for station ${stationId} (WSI: ${wsi}), range ${rangeLabel}.`);
101
+ return;
102
+ }
103
+ const withinRange = stationRecords.filter((r) => {
104
+ const dt = luxon_1.DateTime.fromISO(r.DT, { zone: "utc" });
105
+ return dt >= interval.from && dt < interval.to;
106
+ });
107
+ if (withinRange.length === 0) {
108
+ this.logger.warn(`${this.constructor.name}: all records for station ${stationId} fall outside the requested range ${rangeLabel}.`);
109
+ return;
110
+ }
111
+ const records = withinRange.map((r) => ({ ...r, station_id: stationId }));
112
+ const transformed = await this.transformation.transform(records);
113
+ await this.repository.bulkUpdate(transformed);
114
+ this.logger.debug(`${this.constructor.name}: upserted ${transformed.length} measurements for station ${stationId}, range ${rangeLabel}.`);
115
+ }
116
+ validateRange(data) {
117
+ const from = luxon_1.DateTime.fromISO(data.from, { zone: "utc" });
118
+ const to = luxon_1.DateTime.fromISO(data.to, { zone: "utc" });
119
+ if (to <= from) {
120
+ throw new golemio_errors_1.GeneralError(`"to" (${data.to}) must be after "from" (${data.from}).`, this.constructor.name);
121
+ }
122
+ return { from, to };
123
+ }
124
+ /** Splits [from, to) into calendar-month intervals (UTC, matching DT's format); clips the first/last interval. */
125
+ static generateMonthIntervals(from, to) {
126
+ const intervals = [];
127
+ let cursor = from;
128
+ while (cursor < to) {
129
+ const nextMonth = cursor.startOf("month").plus({ months: 1 });
130
+ intervals.push({ from: cursor, to: luxon_1.DateTime.min(nextMonth, to) });
131
+ cursor = nextMonth;
132
+ }
133
+ return intervals;
134
+ }
135
+ };
136
+ DownloadOpendataHistoricalMeasurementsTask = DownloadOpendataHistoricalMeasurementsTask_1 = __decorate([
137
+ (0, tsyringe_1.injectable)(),
138
+ __param(0, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.StationsRepository)),
139
+ __param(1, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.OpendataHistoricalDatasource)),
140
+ __param(2, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.OpendataMeasurementsTransformation)),
141
+ __param(3, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.MeasurementsRepository)),
142
+ __param(4, (0, tsyringe_1.inject)(CoreToken_1.CoreToken.Logger)),
143
+ __metadata("design:paramtypes", [StationsRepository_1.StationsRepository,
144
+ OpendataHistoricalDatasource_1.default,
145
+ OpendataMeasurementsTransformation_1.OpendataMeasurementsTransformation,
146
+ MeasurementsRepository_1.MeasurementsRepository, Object])
147
+ ], DownloadOpendataHistoricalMeasurementsTask);
148
+ exports.default = DownloadOpendataHistoricalMeasurementsTask;
149
+ //# sourceMappingURL=DownloadOpendataHistoricalMeasurementsTask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DownloadOpendataHistoricalMeasurementsTask.js","sourceRoot":"","sources":["../../../../src/integration-engine/workers/tasks/DownloadOpendataHistoricalMeasurementsTask.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,6EAAwE;AACxE,qFAAgF;AAChF,kHAAwF;AACxF,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ageSchema implements IDownloadOpendataHistoricalMessage {
3
+ from: string;
4
+ to: string;
5
+ station_id?: string;
6
+ wsi?: string;
7
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DownloadOpendataHistoricalMessageSchema = void 0;
13
+ const class_validator_1 = require("@golemio/core/dist/shared/class-validator");
14
+ const ISO8601_WITH_TIMEZONE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
15
+ class DownloadOpendataHistoricalMessageSchema {
16
+ }
17
+ exports.DownloadOpendataHistoricalMessageSchema = DownloadOpendataHistoricalMessageSchema;
18
+ __decorate([
19
+ (0, class_validator_1.IsString)(),
20
+ (0, class_validator_1.IsISO8601)({ strict: true }),
21
+ (0, class_validator_1.Matches)(ISO8601_WITH_TIMEZONE, { message: "from must be a full ISO 8601 timestamp with a timezone (e.g. Z or +01:00)" }),
22
+ __metadata("design:type", String)
23
+ ], DownloadOpendataHistoricalMessageSchema.prototype, "from", void 0);
24
+ __decorate([
25
+ (0, class_validator_1.IsString)(),
26
+ (0, class_validator_1.IsISO8601)({ strict: true }),
27
+ (0, class_validator_1.Matches)(ISO8601_WITH_TIMEZONE, { message: "to must be a full ISO 8601 timestamp with a timezone (e.g. Z or +01:00)" }),
28
+ __metadata("design:type", String)
29
+ ], DownloadOpendataHistoricalMessageSchema.prototype, "to", void 0);
30
+ __decorate([
31
+ (0, class_validator_1.IsOptional)(),
32
+ (0, class_validator_1.IsString)(),
33
+ __metadata("design:type", String)
34
+ ], DownloadOpendataHistoricalMessageSchema.prototype, "station_id", void 0);
35
+ __decorate([
36
+ (0, class_validator_1.IsOptional)(),
37
+ (0, class_validator_1.IsString)(),
38
+ __metadata("design:type", String)
39
+ ], DownloadOpendataHistoricalMessageSchema.prototype, "wsi", void 0);
40
+ //# sourceMappingURL=DownloadOpendataHistoricalMessageSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DownloadOpendataHistoricalMessageSchema.js","sourceRoot":"","sources":["../../../../src/integration-engine/workers/tasks/DownloadOpendataHistoricalMessageSchema.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+EAAqG;AAGrG,MAAM,qBAAqB,GAAG,kEAAkE,CAAC;AAEjG,MAAa,uCAAuC;CAkBnD;AAlBD,0FAkBC;AAdG;IAHC,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC3B,IAAA,yBAAO,EAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,2EAA2E,EAAE,CAAC;;qEAC3G;AAKd;IAHC,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC3B,IAAA,yBAAO,EAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,yEAAyE,EAAE,CAAC;;mEAC3G;AAIZ;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;2EACS;AAIpB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oEACE"}
@@ -0,0 +1,22 @@
1
+ import { StationsRepository } from "../../data-access/StationsRepository";
2
+ import { MeasurementsRepository } from "../../data-access/MeasurementsRepository";
3
+ import OpendataDatasource from "../../datasources/OpendataDatasource";
4
+ import { OpendataMeasurementsTransformation } from "../../transformations/OpendataMeasurementsTransformation";
5
+ import { ILogger } from "@golemio/core/dist/helpers/logger/LoggerProvider";
6
+ import { AbstractTask } from "@golemio/core/dist/integration-engine";
7
+ import IDownloadOpendataMessage from "../interfaces/IDownloadOpendataMessage";
8
+ import { DownloadOpendataMessageSchema } from "./DownloadOpendataMessageSchema";
9
+ export default class DownloadOpendataMeasurementsTask extends AbstractTask<IDownloadOpendataMessage> {
10
+ private stationsRepository;
11
+ private datasource;
12
+ private transformation;
13
+ private repository;
14
+ private logger;
15
+ queueName: string;
16
+ protected schema: typeof DownloadOpendataMessageSchema;
17
+ constructor(stationsRepository: StationsRepository, datasource: OpendataDatasource, transformation: OpendataMeasurementsTransformation, repository: MeasurementsRepository, logger: ILogger);
18
+ protected execute: (data: IDownloadOpendataMessage) => Promise<void>;
19
+ private generateSubtasks;
20
+ private processStationMeasurements;
21
+ private validateDate;
22
+ }
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const StationsRepository_1 = require("../../data-access/StationsRepository");
19
+ const MeasurementsRepository_1 = require("../../data-access/MeasurementsRepository");
20
+ const OpendataDatasource_1 = __importDefault(require("../../datasources/OpendataDatasource"));
21
+ const ModuleContainerToken_1 = require("../../ioc/ModuleContainerToken");
22
+ const OpendataMeasurementsTransformation_1 = require("../../transformations/OpendataMeasurementsTransformation");
23
+ const integration_engine_1 = require("@golemio/core/dist/integration-engine");
24
+ const QueueManager_1 = require("@golemio/core/dist/integration-engine/queueprocessors/QueueManager");
25
+ const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
26
+ const luxon_1 = require("@golemio/core/dist/shared/luxon");
27
+ const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
28
+ const DownloadOpendataMessageSchema_1 = require("./DownloadOpendataMessageSchema");
29
+ const CoreToken_1 = require("@golemio/core/dist/helpers/ioc/CoreToken");
30
+ let DownloadOpendataMeasurementsTask = class DownloadOpendataMeasurementsTask extends integration_engine_1.AbstractTask {
31
+ constructor(stationsRepository, datasource, transformation, repository, logger) {
32
+ super(""); // queue prefix is set by the worker
33
+ this.stationsRepository = stationsRepository;
34
+ this.datasource = datasource;
35
+ this.transformation = transformation;
36
+ this.repository = repository;
37
+ this.logger = logger;
38
+ this.queueName = "downloadOpendataMeasurementsTask";
39
+ this.schema = DownloadOpendataMessageSchema_1.DownloadOpendataMessageSchema;
40
+ this.execute = async (data) => {
41
+ const { date } = this.validateDate(data);
42
+ try {
43
+ if (data.wsi && data.station_id) {
44
+ await this.processStationMeasurements(data.station_id, data.wsi, new Date(date));
45
+ }
46
+ else {
47
+ await this.generateSubtasks(date);
48
+ }
49
+ }
50
+ catch (error) {
51
+ if (error instanceof golemio_errors_1.AbstractGolemioError) {
52
+ throw error;
53
+ }
54
+ throw new golemio_errors_1.GeneralError(`Unable to download chmu opendata measurements data.`, this.constructor.name, error);
55
+ }
56
+ };
57
+ }
58
+ async generateSubtasks(date) {
59
+ const stations = await this.stationsRepository.getStationsWithWsi();
60
+ if (stations.length === 0) {
61
+ this.logger.warn(`${this.constructor.name}: no stations with WSI found - skipping. Populate chmu.stations.wsi first.`);
62
+ return;
63
+ }
64
+ for (const station of stations) {
65
+ await QueueManager_1.QueueManager.sendMessageToExchange(this.queuePrefix, this.queueName, {
66
+ date,
67
+ station_id: station.station_id,
68
+ wsi: station.wsi,
69
+ });
70
+ }
71
+ this.logger.debug(`${this.constructor.name}: dispatched ${stations.length} subtasks for date ${date}.`);
72
+ }
73
+ async processStationMeasurements(stationId, wsi, date) {
74
+ let stationRecords;
75
+ try {
76
+ stationRecords = await this.datasource.getData(wsi, date);
77
+ }
78
+ catch (error) {
79
+ throw new golemio_errors_1.GeneralError(`${this.constructor.name}: failed to fetch data for station ${stationId} (WSI: ${wsi}).`);
80
+ }
81
+ if (stationRecords.length === 0) {
82
+ this.logger.warn(`${this.constructor.name}: no records fetched for station ${stationId} (WSI: ${wsi}).`);
83
+ return;
84
+ }
85
+ const records = stationRecords.map((r) => ({ ...r, station_id: stationId }));
86
+ const transformed = await this.transformation.transform(records);
87
+ await this.repository.bulkUpdate(transformed);
88
+ this.logger.debug(`${this.constructor.name}: upserted ${transformed.length} measurements for station ${stationId}.`);
89
+ }
90
+ validateDate(data) {
91
+ const dt = data.date ? luxon_1.DateTime.fromISO(data.date) : luxon_1.DateTime.now();
92
+ const ageInDays = luxon_1.DateTime.now().startOf("day").diff(dt.startOf("day"), "days").days;
93
+ if (ageInDays > 2) {
94
+ throw new golemio_errors_1.GeneralError(`Date "${data.date}" is outside the 3-day retention window`, this.constructor.name);
95
+ }
96
+ return { date: dt.toISODate() };
97
+ }
98
+ };
99
+ DownloadOpendataMeasurementsTask = __decorate([
100
+ (0, tsyringe_1.injectable)(),
101
+ __param(0, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.StationsRepository)),
102
+ __param(1, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.OpendataDatasource)),
103
+ __param(2, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.OpendataMeasurementsTransformation)),
104
+ __param(3, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.MeasurementsRepository)),
105
+ __param(4, (0, tsyringe_1.inject)(CoreToken_1.CoreToken.Logger)),
106
+ __metadata("design:paramtypes", [StationsRepository_1.StationsRepository,
107
+ OpendataDatasource_1.default,
108
+ OpendataMeasurementsTransformation_1.OpendataMeasurementsTransformation,
109
+ MeasurementsRepository_1.MeasurementsRepository, Object])
110
+ ], DownloadOpendataMeasurementsTask);
111
+ exports.default = DownloadOpendataMeasurementsTask;
112
+ //# sourceMappingURL=DownloadOpendataMeasurementsTask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DownloadOpendataMeasurementsTask.js","sourceRoot":"","sources":["../../../../src/integration-engine/workers/tasks/DownloadOpendataMeasurementsTask.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6EAAwE;AACxE,qFAAgF;AAChF,8FAAoE;AACpE,yEAAoE;AACpE,iHAA4G;AAE5G,8EAAqE;AACrE,qGAAkG;AAClG,6EAA8F;AAC9F,2DAA2D;AAC3D,iEAAwE;AAExE,mFAAgF;AAChF,wEAAqE;AAGtD,IAAM,gCAAgC,GAAtC,MAAM,gCAAiC,SAAQ,iCAAsC;IAIhG,YACqD,kBAA8C,EAC9C,UAAsC,EAEvF,cAA0D,EACL,UAA0C,EACrE,MAAuB;QAEjD,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,oCAAoC;QAPU,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,eAAU,GAAV,UAAU,CAAoB;QAE/E,mBAAc,GAAd,cAAc,CAAoC;QACG,eAAU,GAAV,UAAU,CAAwB;QAC7D,WAAM,GAAN,MAAM,CAAS;QAT9C,cAAS,GAAW,kCAAkC,CAAC;QACpD,WAAM,GAAG,6D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