@justair/justair-library 4.7.14 → 4.7.15-beta

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justair/justair-library",
3
- "version": "4.7.14",
3
+ "version": "4.7.15-beta",
4
4
  "description": "JustAir Internal Library",
5
5
 
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -53,6 +53,7 @@ import {
53
53
  DataCompleteness,
54
54
  dataCompletenessSchema,
55
55
  } from "./models/dataCompleteness.js";
56
+ import { NetworkMetrics, networkMetricsSchema } from "./models/networkMetrics.js";
56
57
  import Database from "./config/db.js"; // Import the new Database class
57
58
  import CustomLogger from "./config/logger.js";
58
59
 
@@ -110,4 +111,6 @@ export {
110
111
  featuresSchema,
111
112
  dataCompletenessSchema,
112
113
  DataCompleteness,
114
+ networkMetricsSchema,
115
+ NetworkMetrics,
113
116
  };
@@ -73,7 +73,6 @@ const auditSchema = mongoose.Schema(
73
73
  measurements: Object,
74
74
  monitorState: String,
75
75
  monitorSupplier: String,
76
- rawNormalizedMeasurements: Object,
77
76
  normalizedMeasurements: Object,
78
77
  flags: Object,
79
78
  appliedCorrections: {
@@ -81,6 +80,7 @@ const auditSchema = mongoose.Schema(
81
80
  of: correctionSnapshotSchema,
82
81
  default: {},
83
82
  },
83
+ correctedNormalizedMeasurements: Object,
84
84
  annotations: [annotationSchema], // Include annotations in audit trail
85
85
  },
86
86
  {
@@ -99,7 +99,6 @@ const measurementsSchema = mongoose.Schema(
99
99
  measurements: Object,
100
100
  monitorState: String,
101
101
  monitorSupplier: String,
102
- rawNormalizedMeasurements: Object,
103
102
  normalizedMeasurements: Object,
104
103
  flags: Object,
105
104
  appliedCorrections: {
@@ -107,6 +106,7 @@ const measurementsSchema = mongoose.Schema(
107
106
  of: correctionSnapshotSchema,
108
107
  default: {},
109
108
  },
109
+ correctedNormalizedMeasurements: Object,
110
110
  annotations: {
111
111
  type: [annotationSchema],
112
112
  default: [],
@@ -150,9 +150,10 @@ measurementsSchema.pre("findOneAndDelete", async function () {
150
150
  monitorState: docToDelete.monitorState,
151
151
  monitorSupplier: docToDelete.monitorSupplier,
152
152
  normalizedMeasurements: docToDelete.normalizedMeasurements,
153
- rawNormalizedMeasurements: docToDelete.rawNormalizedMeasurements,
154
153
  flags: docToDelete.flags,
155
154
  appliedCorrections: docToDelete.appliedCorrections,
155
+ correctedNormalizedMeasurements:
156
+ docToDelete.correctedNormalizedMeasurements,
156
157
  annotations: docToDelete.annotations, // Include annotations in audit
157
158
  deletedAt: new Date(),
158
159
  });
@@ -175,9 +176,9 @@ measurementsSchema.pre("deleteMany", async function () {
175
176
  monitorState: doc.monitorState,
176
177
  monitorSupplier: doc.monitorSupplier,
177
178
  normalizedMeasurements: doc.normalizedMeasurements,
178
- rawNormalizedMeasurements: doc.rawNormalizedMeasurements,
179
179
  flags: doc.flags,
180
180
  appliedCorrections: doc.appliedCorrections,
181
+ correctedNormalizedMeasurements: doc.correctedNormalizedMeasurements,
181
182
  annotations: doc.annotations, // Include annotations in audit
182
183
  deletedAt: new Date(),
183
184
  }));
@@ -201,9 +202,10 @@ measurementsSchema.pre("deleteOne", async function () {
201
202
  monitorState: docToDelete.monitorState,
202
203
  monitorSupplier: docToDelete.monitorSupplier,
203
204
  normalizedMeasurements: docToDelete.normalizedMeasurements,
204
- rawNormalizedMeasurements: docToDelete.rawNormalizedMeasurements,
205
205
  flags: docToDelete.flags,
206
206
  appliedCorrections: docToDelete.appliedCorrections,
207
+ correctedNormalizedMeasurements:
208
+ docToDelete.correctedNormalizedMeasurements,
207
209
  annotations: docToDelete.annotations, // Include annotations in audit
208
210
  deletedAt: new Date(),
209
211
  });
@@ -224,9 +226,10 @@ measurementsSchema.pre("findOneAndUpdate", async function () {
224
226
  monitorState: docToUpdate.monitorState,
225
227
  monitorSupplier: docToUpdate.monitorSupplier,
226
228
  normalizedMeasurements: docToUpdate.normalizedMeasurements,
227
- rawNormalizedMeasurements: docToUpdate.rawNormalizedMeasurements,
228
229
  flags: docToUpdate.flags,
229
230
  appliedCorrections: docToUpdate.appliedCorrections,
231
+ correctedNormalizedMeasurements:
232
+ docToUpdate.correctedNormalizedMeasurements,
230
233
  annotations: docToUpdate.annotations, // Include annotations in audit
231
234
  deletedAt: null, // No deletion happening, so set it to null or undefined
232
235
  });
@@ -247,9 +250,9 @@ measurementsSchema.pre("updateMany", async function () {
247
250
  monitorState: doc.monitorState,
248
251
  monitorSupplier: doc.monitorSupplier,
249
252
  normalizedMeasurements: doc.normalizedMeasurements,
250
- rawNormalizedMeasurements: doc.rawNormalizedMeasurements,
251
253
  flags: doc.flags,
252
254
  appliedCorrections: doc.appliedCorrections,
255
+ correctedNormalizedMeasurements: doc.correctedNormalizedMeasurements,
253
256
  annotations: doc.annotations, // Include annotations in audit
254
257
  deletedAt: null, // No deletion happening
255
258
  }));
@@ -201,6 +201,7 @@ const monitorsSchema = mongoose.Schema(
201
201
  isActive: { type: Boolean, default: true },
202
202
  parameterThresholds: Object,
203
203
  completionPercentageThresholds: Object,
204
+ networkAnomalyThresholds: Object,
204
205
  // A Map, keyed by pollutant (e.g. "PM2_5"), storing Correction sub-docs
205
206
  corrections: {
206
207
  type: Map,
@@ -0,0 +1,18 @@
1
+ import mongoose from "mongoose";
2
+
3
+ const networkMetricsSchema = mongoose.Schema({
4
+ monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
5
+ orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
6
+ parameter: String,
7
+ parameterValue: Number,
8
+ networkMean: Number,
9
+ networkMonitorCount: Number,
10
+ percentDeviationFromMean: Number,
11
+ measurementsStartTime: Date,
12
+ measurementsEndTime: Date,
13
+ flags: Object
14
+ }, { timestamps: true });
15
+
16
+ const NetworkMetrics = mongoose.model("NetworkMetrics", networkMetricsSchema);
17
+
18
+ export { networkMetricsSchema, NetworkMetrics };
@@ -1,40 +0,0 @@
1
- import mongoose from "mongoose";
2
-
3
- const parametersEnum = [
4
- "NO2",
5
- "SO2",
6
- "PM2.5",
7
- "PM10",
8
- "Temperature",
9
- "Humidity",
10
- "OZONE",
11
- "VOC",
12
- "CO",
13
- "NO",
14
- "PM1",
15
- "WS And Direction",
16
- ];
17
-
18
- const monitorTypeSchema = mongoose.Schema(
19
- {
20
- model: {
21
- type: String,
22
- required: true,
23
- },
24
-
25
- supplier: {
26
- type: mongoose.Types.ObjectId,
27
- required: true,
28
- ref: "MonitorSuppliers",
29
- },
30
-
31
- parameters: {
32
- type: String,
33
- enum: parametersEnum,
34
- required: true,
35
- },
36
- },
37
- { timestamps: true }
38
- );
39
-
40
- const monitorType = mongoose.model("MonitorType", monitorTypeSchema);