@bradtech/sensor 1.1.0
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/HOWTO.md +121 -0
- package/LICENSE +620 -0
- package/README.md +29 -0
- package/dist/BaseSensorConverter.d.ts +42 -0
- package/dist/BaseSensorConverter.d.ts.map +1 -0
- package/dist/BaseSensorConverter.js +47 -0
- package/dist/BaseSensorConverter.js.map +1 -0
- package/dist/ConverterRegistry.d.ts +39 -0
- package/dist/ConverterRegistry.d.ts.map +1 -0
- package/dist/ConverterRegistry.js +53 -0
- package/dist/ConverterRegistry.js.map +1 -0
- package/dist/ReplayEngine.d.ts +78 -0
- package/dist/ReplayEngine.d.ts.map +1 -0
- package/dist/ReplayEngine.js +47 -0
- package/dist/ReplayEngine.js.map +1 -0
- package/dist/Sensor.d.ts +50 -0
- package/dist/Sensor.d.ts.map +1 -0
- package/dist/Sensor.js +75 -0
- package/dist/Sensor.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +86 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +63 -0
- package/src/BaseSensorConverter.ts +76 -0
- package/src/ConverterRegistry.ts +55 -0
- package/src/ReplayEngine.ts +133 -0
- package/src/Sensor.ts +90 -0
- package/src/index.ts +5 -0
- package/src/types.ts +97 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ConversionContext, ConversionOutput, SensorConverterInterface } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract foundation class for all sensor converters.
|
|
4
|
+
* Implements defensive physical clamping and automated confidence score degradation.
|
|
5
|
+
*
|
|
6
|
+
* @template TRaw - Raw sensor payload type.
|
|
7
|
+
* @template TContext - Environmental and spatial context type.
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class BaseSensorConverter<TRaw = any, TContext extends ConversionContext = ConversionContext> implements SensorConverterInterface<TRaw, TContext> {
|
|
10
|
+
/** Domain sensor family classification (e.g. 'air', 'soil', 'weather', 'power', 'acoustic') */
|
|
11
|
+
abstract readonly sensorFamily: string;
|
|
12
|
+
/** Unique machine-readable algorithmic identifier */
|
|
13
|
+
abstract readonly modelCode: string;
|
|
14
|
+
/** Semantic version string of the algorithm implementation */
|
|
15
|
+
abstract readonly modelVersion: string;
|
|
16
|
+
/** Detailed description of conversion algorithm */
|
|
17
|
+
abstract readonly description: string;
|
|
18
|
+
/**
|
|
19
|
+
* Executes the mathematical conversion from raw sensor signals to normalized physical outputs.
|
|
20
|
+
*
|
|
21
|
+
* @param raw - The raw sensor reading or observation payload.
|
|
22
|
+
* @param context - Optional environmental, soil texture, or calibration parameters.
|
|
23
|
+
* @returns An array of normalized physical conversion outputs.
|
|
24
|
+
*/
|
|
25
|
+
abstract convert(raw: TRaw, context?: TContext): ConversionOutput[];
|
|
26
|
+
/**
|
|
27
|
+
* Clamps a numerical value within strict physical limits while calculating
|
|
28
|
+
* a continuous quality confidence score (between 0.0 and 1.0).
|
|
29
|
+
*
|
|
30
|
+
* @param value - The input numerical reading to evaluate.
|
|
31
|
+
* @param minPhysical - The absolute lower physical limit (e.g. -40°C for ambient air).
|
|
32
|
+
* @param maxPhysical - The absolute upper physical limit (e.g. +70°C for ambient air).
|
|
33
|
+
* @param minWarning - Optional soft lower warning threshold where confidence begins to degrade.
|
|
34
|
+
* @param maxWarning - Optional soft upper warning threshold where confidence begins to degrade.
|
|
35
|
+
* @returns Object containing the clamped value and the calculated confidence score.
|
|
36
|
+
*/
|
|
37
|
+
protected clampWithConfidence(value: number, minPhysical: number, maxPhysical: number, minWarning?: number, maxWarning?: number): {
|
|
38
|
+
value: number;
|
|
39
|
+
confidence: number;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=BaseSensorConverter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseSensorConverter.d.ts","sourceRoot":"","sources":["../src/BaseSensorConverter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAE5F;;;;;;GAMG;AACH,8BAAsB,mBAAmB,CAAC,IAAI,GAAG,GAAG,EAAE,QAAQ,SAAS,iBAAiB,GAAG,iBAAiB,CACzG,YAAW,wBAAwB,CAAC,IAAI,EAAE,QAAQ,CAAC;IAEnD,+FAA+F;IAC/F,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAEtC,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAEnC,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAEtC,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAErC;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,QAAQ,GAAG,gBAAgB,EAAE;IAEnE;;;;;;;;;;OAUG;IACH,SAAS,CAAC,mBAAmB,CAC1B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GACnB;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;CAyB1C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseSensorConverter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Abstract foundation class for all sensor converters.
|
|
6
|
+
* Implements defensive physical clamping and automated confidence score degradation.
|
|
7
|
+
*
|
|
8
|
+
* @template TRaw - Raw sensor payload type.
|
|
9
|
+
* @template TContext - Environmental and spatial context type.
|
|
10
|
+
*/
|
|
11
|
+
class BaseSensorConverter {
|
|
12
|
+
/**
|
|
13
|
+
* Clamps a numerical value within strict physical limits while calculating
|
|
14
|
+
* a continuous quality confidence score (between 0.0 and 1.0).
|
|
15
|
+
*
|
|
16
|
+
* @param value - The input numerical reading to evaluate.
|
|
17
|
+
* @param minPhysical - The absolute lower physical limit (e.g. -40°C for ambient air).
|
|
18
|
+
* @param maxPhysical - The absolute upper physical limit (e.g. +70°C for ambient air).
|
|
19
|
+
* @param minWarning - Optional soft lower warning threshold where confidence begins to degrade.
|
|
20
|
+
* @param maxWarning - Optional soft upper warning threshold where confidence begins to degrade.
|
|
21
|
+
* @returns Object containing the clamped value and the calculated confidence score.
|
|
22
|
+
*/
|
|
23
|
+
clampWithConfidence(value, minPhysical, maxPhysical, minWarning, maxWarning) {
|
|
24
|
+
if (isNaN(value) || !isFinite(value)) {
|
|
25
|
+
return { value: 0, confidence: 0.0 };
|
|
26
|
+
}
|
|
27
|
+
if (value < minPhysical) {
|
|
28
|
+
return { value: minPhysical, confidence: 0.1 };
|
|
29
|
+
}
|
|
30
|
+
if (value > maxPhysical) {
|
|
31
|
+
return { value: maxPhysical, confidence: 0.1 };
|
|
32
|
+
}
|
|
33
|
+
let confidence = 1.0;
|
|
34
|
+
if (minWarning !== undefined && value < minWarning) {
|
|
35
|
+
confidence = Math.max(0.3, 1.0 - (minWarning - value) / (minWarning - minPhysical));
|
|
36
|
+
}
|
|
37
|
+
else if (maxWarning !== undefined && value > maxWarning) {
|
|
38
|
+
confidence = Math.max(0.3, 1.0 - (value - maxWarning) / (maxPhysical - maxWarning));
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
value: Number(value.toFixed(4)),
|
|
42
|
+
confidence: Number(confidence.toFixed(2)),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.BaseSensorConverter = BaseSensorConverter;
|
|
47
|
+
//# sourceMappingURL=BaseSensorConverter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseSensorConverter.js","sourceRoot":"","sources":["../src/BaseSensorConverter.ts"],"names":[],"mappings":";;;AAEA;;;;;;GAMG;AACH,MAAsB,mBAAmB;IAwBtC;;;;;;;;;;OAUG;IACO,mBAAmB,CAC1B,KAAa,EACb,WAAmB,EACnB,WAAmB,EACnB,UAAmB,EACnB,UAAmB;QAEnB,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACpC,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,CAAA;QACvC,CAAC;QAED,IAAI,KAAK,GAAG,WAAW,EAAE,CAAC;YACvB,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,EAAE,CAAA;QACjD,CAAC;QACD,IAAI,KAAK,GAAG,WAAW,EAAE,CAAC;YACvB,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,EAAE,CAAA;QACjD,CAAC;QAED,IAAI,UAAU,GAAG,GAAG,CAAA;QAEpB,IAAI,UAAU,KAAK,SAAS,IAAI,KAAK,GAAG,UAAU,EAAE,CAAC;YAClD,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,GAAG,WAAW,CAAC,CAAC,CAAA;QACtF,CAAC;aAAM,IAAI,UAAU,KAAK,SAAS,IAAI,KAAK,GAAG,UAAU,EAAE,CAAC;YACzD,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,WAAW,GAAG,UAAU,CAAC,CAAC,CAAA;QACtF,CAAC;QAED,OAAO;YACJ,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC/B,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;SAC3C,CAAA;IACJ,CAAC;CACH;AAlED,kDAkEC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SensorConverterInterface } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Global registry for discovering and indexing sensor converter instances
|
|
4
|
+
* by sensor family and algorithmic model code.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConverterRegistry {
|
|
7
|
+
/** Internal lookup map indexed by `family:modelCode` */
|
|
8
|
+
private static _converters;
|
|
9
|
+
/**
|
|
10
|
+
* Registers an instantiated sensor converter into the global registry.
|
|
11
|
+
*
|
|
12
|
+
* @param converter - The sensor converter instance to index.
|
|
13
|
+
*/
|
|
14
|
+
static register(converter: SensorConverterInterface): void;
|
|
15
|
+
/**
|
|
16
|
+
* Looks up a converter by its sensor family and model code.
|
|
17
|
+
*
|
|
18
|
+
* @param sensorFamily - The domain family (e.g. 'soil', 'air').
|
|
19
|
+
* @param modelCode - The unique model code (e.g. 'soil-vwc-texture-calibrated').
|
|
20
|
+
* @returns The matching converter instance, or undefined if not found.
|
|
21
|
+
*/
|
|
22
|
+
static get(sensorFamily: string, modelCode: string): SensorConverterInterface | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves all converters registered under a specific sensor family.
|
|
25
|
+
*
|
|
26
|
+
* @param sensorFamily - The sensor family to filter by.
|
|
27
|
+
* @returns An array of registered converters for the family.
|
|
28
|
+
*/
|
|
29
|
+
static getByFamily(sensorFamily: string): SensorConverterInterface[];
|
|
30
|
+
/**
|
|
31
|
+
* Returns all currently registered converter instances.
|
|
32
|
+
*/
|
|
33
|
+
static getAll(): SensorConverterInterface[];
|
|
34
|
+
/**
|
|
35
|
+
* Clears all registered converters from the registry.
|
|
36
|
+
*/
|
|
37
|
+
static clear(): void;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=ConverterRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConverterRegistry.d.ts","sourceRoot":"","sources":["../src/ConverterRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAEvD;;;GAGG;AACH,qBAAa,iBAAiB;IAC3B,wDAAwD;IACxD,OAAO,CAAC,MAAM,CAAC,WAAW,CAAmD;IAE7E;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,wBAAwB,GAAG,IAAI;IAK1D;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS;IAIzF;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,wBAAwB,EAAE;IAIpE;;OAEG;IACH,MAAM,CAAC,MAAM,IAAI,wBAAwB,EAAE;IAI3C;;OAEG;IACH,MAAM,CAAC,KAAK,IAAI,IAAI;CAGtB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConverterRegistry = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Global registry for discovering and indexing sensor converter instances
|
|
6
|
+
* by sensor family and algorithmic model code.
|
|
7
|
+
*/
|
|
8
|
+
class ConverterRegistry {
|
|
9
|
+
/**
|
|
10
|
+
* Registers an instantiated sensor converter into the global registry.
|
|
11
|
+
*
|
|
12
|
+
* @param converter - The sensor converter instance to index.
|
|
13
|
+
*/
|
|
14
|
+
static register(converter) {
|
|
15
|
+
const key = `${converter.sensorFamily}:${converter.modelCode}`;
|
|
16
|
+
this._converters.set(key, converter);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Looks up a converter by its sensor family and model code.
|
|
20
|
+
*
|
|
21
|
+
* @param sensorFamily - The domain family (e.g. 'soil', 'air').
|
|
22
|
+
* @param modelCode - The unique model code (e.g. 'soil-vwc-texture-calibrated').
|
|
23
|
+
* @returns The matching converter instance, or undefined if not found.
|
|
24
|
+
*/
|
|
25
|
+
static get(sensorFamily, modelCode) {
|
|
26
|
+
return this._converters.get(`${sensorFamily}:${modelCode}`);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves all converters registered under a specific sensor family.
|
|
30
|
+
*
|
|
31
|
+
* @param sensorFamily - The sensor family to filter by.
|
|
32
|
+
* @returns An array of registered converters for the family.
|
|
33
|
+
*/
|
|
34
|
+
static getByFamily(sensorFamily) {
|
|
35
|
+
return Array.from(this._converters.values()).filter((c) => c.sensorFamily === sensorFamily);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns all currently registered converter instances.
|
|
39
|
+
*/
|
|
40
|
+
static getAll() {
|
|
41
|
+
return Array.from(this._converters.values());
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Clears all registered converters from the registry.
|
|
45
|
+
*/
|
|
46
|
+
static clear() {
|
|
47
|
+
this._converters.clear();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.ConverterRegistry = ConverterRegistry;
|
|
51
|
+
/** Internal lookup map indexed by `family:modelCode` */
|
|
52
|
+
ConverterRegistry._converters = new Map();
|
|
53
|
+
//# sourceMappingURL=ConverterRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConverterRegistry.js","sourceRoot":"","sources":["../src/ConverterRegistry.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,MAAa,iBAAiB;IAI3B;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAmC;QAChD,MAAM,GAAG,GAAG,GAAG,SAAS,CAAC,YAAY,IAAI,SAAS,CAAC,SAAS,EAAE,CAAA;QAC9D,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;IACvC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,YAAoB,EAAE,SAAiB;QAC/C,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,YAAY,IAAI,SAAS,EAAE,CAAC,CAAA;IAC9D,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,YAAoB;QACpC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,YAAY,CAAC,CAAA;IAC9F,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM;QACV,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAA;IAC/C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK;QACT,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;IAC3B,CAAC;;AA/CJ,8CAgDC;AA/CE,wDAAwD;AACzC,6BAAW,GAA0C,IAAI,GAAG,EAAE,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { CompanyUri, DeviceUri, InterfaceContractUri, OkfMetricUri, PlotUri } from '@bradtech/types';
|
|
2
|
+
import type { ConversionContext, SensorConverterInterface } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Input contract for historical raw data points to be replayed.
|
|
5
|
+
*/
|
|
6
|
+
export interface RawDataPointInput {
|
|
7
|
+
/** Unique UUID of the source raw data point */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Canonical device URI (e.g. 'probes/b25s004') */
|
|
10
|
+
device: DeviceUri | (string & {});
|
|
11
|
+
/** Canonical plot URI (e.g. 'plots/e5eadee3-...') */
|
|
12
|
+
plot?: PlotUri | (string & {});
|
|
13
|
+
/** Canonical company URI (e.g. 'companies/32c18f05-...') */
|
|
14
|
+
company?: CompanyUri | (string & {});
|
|
15
|
+
/** Raw metric identifier */
|
|
16
|
+
metric: OkfMetricUri | (string & {});
|
|
17
|
+
/** Raw numerical measurement value */
|
|
18
|
+
value: number;
|
|
19
|
+
/** Time of observation */
|
|
20
|
+
timestamp: string | Date;
|
|
21
|
+
/** Original measurement metadata */
|
|
22
|
+
metadata?: Record<string, any>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Output contract representing a newly computed data point with complete lineage and audit trail.
|
|
26
|
+
*/
|
|
27
|
+
export interface ComputedDataPointOutput {
|
|
28
|
+
/** Canonical device URI */
|
|
29
|
+
device: DeviceUri | (string & {});
|
|
30
|
+
/** Canonical plot URI */
|
|
31
|
+
plot?: PlotUri | (string & {});
|
|
32
|
+
/** Canonical company URI */
|
|
33
|
+
company?: CompanyUri | (string & {});
|
|
34
|
+
/** Computed metric identifier */
|
|
35
|
+
metric: OkfMetricUri | (string & {});
|
|
36
|
+
/** Derived calculated physical value */
|
|
37
|
+
value: number;
|
|
38
|
+
/** Physical unit symbol */
|
|
39
|
+
unit: string;
|
|
40
|
+
/** Fixed classification indicating algorithmic computation */
|
|
41
|
+
kind: 'computed';
|
|
42
|
+
/** Numerical confidence score */
|
|
43
|
+
confidence: number;
|
|
44
|
+
/** Timestamp matching the source observation */
|
|
45
|
+
timestamp: string | Date;
|
|
46
|
+
/** Comprehensive lineage metadata */
|
|
47
|
+
metadata: {
|
|
48
|
+
/** Quatrain metadata interface contract identifier */
|
|
49
|
+
interface: InterfaceContractUri | (string & {});
|
|
50
|
+
/** Algorithmic model code executed during replay */
|
|
51
|
+
modelCode: string;
|
|
52
|
+
/** Algorithm semver version executed during replay */
|
|
53
|
+
modelVersion: string;
|
|
54
|
+
/** Source raw data point UUID providing audit traceability */
|
|
55
|
+
sourceDataPointId: string;
|
|
56
|
+
/** Execution parameters, calibrations, or texture presets used */
|
|
57
|
+
executionParams?: Record<string, any>;
|
|
58
|
+
[key: string]: any;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Deterministic Replay Engine.
|
|
63
|
+
* Allows re-processing historical timeseries data points through updated or newly introduced
|
|
64
|
+
* agronomic algorithms while maintaining full provenance and audit traceability.
|
|
65
|
+
*/
|
|
66
|
+
export declare class ReplayEngine {
|
|
67
|
+
/**
|
|
68
|
+
* Re-evaluates an array of raw historical DataPoints using a specified SensorConverter
|
|
69
|
+
* and generates a set of fully traceable 'computed' DataPoints.
|
|
70
|
+
*
|
|
71
|
+
* @param dataPoints - Collection of raw input measurements.
|
|
72
|
+
* @param converter - The target conversion algorithm instance to execute.
|
|
73
|
+
* @param contextOverride - Optional contextual overrides (e.g. newly calibrated soil textures).
|
|
74
|
+
* @returns Array of transformed computed DataPoints.
|
|
75
|
+
*/
|
|
76
|
+
static replay(dataPoints: RawDataPointInput[], converter: SensorConverterInterface, contextOverride?: Partial<ConversionContext>): ComputedDataPointOutput[];
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=ReplayEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReplayEngine.d.ts","sourceRoot":"","sources":["../src/ReplayEngine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACT,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,YAAY,EACZ,OAAO,EACT,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAoB,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAE5F;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC/B,+CAA+C;IAC/C,EAAE,EAAE,MAAM,CAAA;IACV,mDAAmD;IACnD,MAAM,EAAE,SAAS,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;IACjC,qDAAqD;IACrD,IAAI,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;IAC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kE;QAClE,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QACrC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KACpB,CAAA;CACH;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACtB;;;;;;;;OAQG;IACH,MAAM,CAAC,MAAM,CACV,UAAU,EAAE,iBAAiB,EAAE,EAC/B,SAAS,EAAE,wBAAwB,EACnC,eAAe,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAC5C,uBAAuB,EAAE;CA2C9B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReplayEngine = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Deterministic Replay Engine.
|
|
6
|
+
* Allows re-processing historical timeseries data points through updated or newly introduced
|
|
7
|
+
* agronomic algorithms while maintaining full provenance and audit traceability.
|
|
8
|
+
*/
|
|
9
|
+
class ReplayEngine {
|
|
10
|
+
/**
|
|
11
|
+
* Re-evaluates an array of raw historical DataPoints using a specified SensorConverter
|
|
12
|
+
* and generates a set of fully traceable 'computed' DataPoints.
|
|
13
|
+
*
|
|
14
|
+
* @param dataPoints - Collection of raw input measurements.
|
|
15
|
+
* @param converter - The target conversion algorithm instance to execute.
|
|
16
|
+
* @param contextOverride - Optional contextual overrides (e.g. newly calibrated soil textures).
|
|
17
|
+
* @returns Array of transformed computed DataPoints.
|
|
18
|
+
*/
|
|
19
|
+
static replay(dataPoints, converter, contextOverride) {
|
|
20
|
+
const results = [];
|
|
21
|
+
for (const dp of dataPoints) {
|
|
22
|
+
const context = Object.assign({ deviceId: dp.device, plotId: dp.plot, companyId: dp.company, timestamp: dp.timestamp }, contextOverride);
|
|
23
|
+
const outputs = converter.convert(dp.value, context);
|
|
24
|
+
for (const out of outputs) {
|
|
25
|
+
results.push({
|
|
26
|
+
device: dp.device,
|
|
27
|
+
plot: dp.plot,
|
|
28
|
+
company: dp.company,
|
|
29
|
+
metric: out.metric,
|
|
30
|
+
value: out.value,
|
|
31
|
+
unit: out.unit,
|
|
32
|
+
kind: 'computed',
|
|
33
|
+
confidence: out.confidence,
|
|
34
|
+
timestamp: dp.timestamp,
|
|
35
|
+
metadata: Object.assign({ interface: '@bradtech/types:ComputedMetadataInterface', modelCode: converter.modelCode, modelVersion: converter.modelVersion, sourceDataPointId: dp.id, executionParams: {
|
|
36
|
+
replayedAt: new Date().toISOString(),
|
|
37
|
+
contextUsed: context,
|
|
38
|
+
rawInput: dp.value,
|
|
39
|
+
} }, out.metadata),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return results;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.ReplayEngine = ReplayEngine;
|
|
47
|
+
//# sourceMappingURL=ReplayEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReplayEngine.js","sourceRoot":"","sources":["../src/ReplayEngine.ts"],"names":[],"mappings":";;;AAsEA;;;;GAIG;AACH,MAAa,YAAY;IACtB;;;;;;;;OAQG;IACH,MAAM,CAAC,MAAM,CACV,UAA+B,EAC/B,SAAmC,EACnC,eAA4C;QAE5C,MAAM,OAAO,GAA8B,EAAE,CAAA;QAE7C,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;YAC3B,MAAM,OAAO,mBACV,QAAQ,EAAE,EAAE,CAAC,MAAM,EACnB,MAAM,EAAE,EAAE,CAAC,IAAI,EACf,SAAS,EAAE,EAAE,CAAC,OAAO,EACrB,SAAS,EAAE,EAAE,CAAC,SAAS,IACpB,eAAe,CACpB,CAAA;YAED,MAAM,OAAO,GAAuB,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;YAExE,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;gBACzB,OAAO,CAAC,IAAI,CAAC;oBACV,MAAM,EAAE,EAAE,CAAC,MAAM;oBACjB,IAAI,EAAE,EAAE,CAAC,IAAI;oBACb,OAAO,EAAE,EAAE,CAAC,OAAO;oBACnB,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,KAAK,EAAE,GAAG,CAAC,KAAK;oBAChB,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,IAAI,EAAE,UAAU;oBAChB,UAAU,EAAE,GAAG,CAAC,UAAU;oBAC1B,SAAS,EAAE,EAAE,CAAC,SAAS;oBACvB,QAAQ,kBACL,SAAS,EAAE,2CAA2C,EACtD,SAAS,EAAE,SAAS,CAAC,SAAS,EAC9B,YAAY,EAAE,SAAS,CAAC,YAAY,EACpC,iBAAiB,EAAE,EAAE,CAAC,EAAE,EACxB,eAAe,EAAE;4BACd,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;4BACpC,WAAW,EAAE,OAAO;4BACpB,QAAQ,EAAE,EAAE,CAAC,KAAK;yBACpB,IACE,GAAG,CAAC,QAAQ,CACjB;iBACH,CAAC,CAAA;YACL,CAAC;QACJ,CAAC;QAED,OAAO,OAAO,CAAA;IACjB,CAAC;CACH;AAzDD,oCAyDC"}
|
package/dist/Sensor.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Core } from '@quatrain/core';
|
|
2
|
+
import type { ConversionContext, ConversionOutput, SensorConverterInterface } from './types';
|
|
3
|
+
export type SensorAdapterRegistry = {
|
|
4
|
+
[alias: string]: SensorConverterInterface<any, any>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Sensor Micro-Framework Singleton Facade
|
|
8
|
+
* Extends Quatrain Core, manages instantiated sensor adapters and coordinates conversions.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Sensor extends Core {
|
|
11
|
+
/** Reference ID for the primary default sensor adapter. */
|
|
12
|
+
static defaultAdapter: string;
|
|
13
|
+
/** Domain-specific Core Logger. */
|
|
14
|
+
static logger: any;
|
|
15
|
+
/** Registry of bound, instantiated sensor adapters */
|
|
16
|
+
protected static _adapters: SensorAdapterRegistry;
|
|
17
|
+
/**
|
|
18
|
+
* Appends a new instantiated sensor adapter into the registry.
|
|
19
|
+
*
|
|
20
|
+
* @param adapter - The instantiated sensor converter/adapter.
|
|
21
|
+
* @param alias - The lookup alias (defaults to adapter.modelCode).
|
|
22
|
+
* @param setDefault - True to switch standard default adapter.
|
|
23
|
+
*/
|
|
24
|
+
static addAdapter(adapter: SensorConverterInterface<any, any>, alias?: string, setDefault?: boolean): typeof Sensor;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves an instantiated adapter by alias or model code.
|
|
27
|
+
*
|
|
28
|
+
* @param alias - Adapter alias or modelCode (defaults to defaultAdapter).
|
|
29
|
+
* @returns Instantiated sensor adapter.
|
|
30
|
+
* @throws When adapter is not found in registry.
|
|
31
|
+
*/
|
|
32
|
+
static getAdapter<T extends SensorConverterInterface<any, any> = SensorConverterInterface<any, any>>(alias?: string): T;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a sensor adapter is currently registered.
|
|
35
|
+
*/
|
|
36
|
+
static hasAdapter(alias: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the list of all registered adapter aliases.
|
|
39
|
+
*/
|
|
40
|
+
static listAdapters(): string[];
|
|
41
|
+
/**
|
|
42
|
+
* Clears all registered adapters (useful for test resets).
|
|
43
|
+
*/
|
|
44
|
+
static reset(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Direct conversion helper using a named adapter.
|
|
47
|
+
*/
|
|
48
|
+
static convert<TRaw = any, TContext extends ConversionContext = ConversionContext>(alias: string, raw: TRaw, context?: TContext): ConversionOutput[];
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=Sensor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sensor.d.ts","sourceRoot":"","sources":["../src/Sensor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,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
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Sensor = void 0;
|
|
5
|
+
const core_1 = require("@quatrain/core");
|
|
6
|
+
/**
|
|
7
|
+
* Sensor Micro-Framework Singleton Facade
|
|
8
|
+
* Extends Quatrain Core, manages instantiated sensor adapters and coordinates conversions.
|
|
9
|
+
*/
|
|
10
|
+
class Sensor extends core_1.Core {
|
|
11
|
+
/**
|
|
12
|
+
* Appends a new instantiated sensor adapter into the registry.
|
|
13
|
+
*
|
|
14
|
+
* @param adapter - The instantiated sensor converter/adapter.
|
|
15
|
+
* @param alias - The lookup alias (defaults to adapter.modelCode).
|
|
16
|
+
* @param setDefault - True to switch standard default adapter.
|
|
17
|
+
*/
|
|
18
|
+
static addAdapter(adapter, alias = adapter.modelCode, setDefault = false) {
|
|
19
|
+
var _b, _c;
|
|
20
|
+
this._adapters[alias] = adapter;
|
|
21
|
+
(_c = (_b = this.logger).debug) === null || _c === void 0 ? void 0 : _c.call(_b, `Registered sensor adapter: '${alias}' (${adapter.constructor.name})`);
|
|
22
|
+
if (setDefault) {
|
|
23
|
+
this.defaultAdapter = alias;
|
|
24
|
+
}
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves an instantiated adapter by alias or model code.
|
|
29
|
+
*
|
|
30
|
+
* @param alias - Adapter alias or modelCode (defaults to defaultAdapter).
|
|
31
|
+
* @returns Instantiated sensor adapter.
|
|
32
|
+
* @throws When adapter is not found in registry.
|
|
33
|
+
*/
|
|
34
|
+
static getAdapter(alias = this.defaultAdapter) {
|
|
35
|
+
if (this._adapters[alias]) {
|
|
36
|
+
return this._adapters[alias];
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`[Sensor] Unknown sensor adapter alias: '${alias}'. Registered adapters: [${Object.keys(this._adapters).join(', ')}]`);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Checks if a sensor adapter is currently registered.
|
|
42
|
+
*/
|
|
43
|
+
static hasAdapter(alias) {
|
|
44
|
+
return Boolean(this._adapters[alias]);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns the list of all registered adapter aliases.
|
|
48
|
+
*/
|
|
49
|
+
static listAdapters() {
|
|
50
|
+
return Object.keys(this._adapters);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Clears all registered adapters (useful for test resets).
|
|
54
|
+
*/
|
|
55
|
+
static reset() {
|
|
56
|
+
this._adapters = {};
|
|
57
|
+
this.defaultAdapter = '@default';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Direct conversion helper using a named adapter.
|
|
61
|
+
*/
|
|
62
|
+
static convert(alias, raw, context) {
|
|
63
|
+
const adapter = this.getAdapter(alias);
|
|
64
|
+
return adapter.convert(raw, context);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.Sensor = Sensor;
|
|
68
|
+
_a = Sensor;
|
|
69
|
+
/** Reference ID for the primary default sensor adapter. */
|
|
70
|
+
Sensor.defaultAdapter = '@default';
|
|
71
|
+
/** Domain-specific Core Logger. */
|
|
72
|
+
Sensor.logger = _a.addLogger('Sensor');
|
|
73
|
+
/** Registry of bound, instantiated sensor adapters */
|
|
74
|
+
Sensor._adapters = {};
|
|
75
|
+
//# sourceMappingURL=Sensor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sensor.js","sourceRoot":"","sources":["../src/Sensor.ts"],"names":[],"mappings":";;;;AAAA,yCAAqC;AAKrC;;;GAGG;AACH,MAAa,MAAO,SAAQ,WAAI;IAU7B;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CACd,OAA2C,EAC3C,QAAgB,OAAO,CAAC,SAAS,EACjC,aAAsB,KAAK;;QAE3B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,OAAO,CAAA;QAC/B,MAAA,MAAA,IAAI,CAAC,MAAM,EAAC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C;AAC5B,aAAM,GAAG,EAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,AAA3B,CAA2B;AAExC,sDAAsD;AACrC,gBAAS,GAA0B,EAAE,AAA5B,CAA4B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./BaseSensorConverter"), exports);
|
|
19
|
+
__exportStar(require("./ConverterRegistry"), exports);
|
|
20
|
+
__exportStar(require("./ReplayEngine"), exports);
|
|
21
|
+
__exportStar(require("./Sensor"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,wDAAqC;AACrC,sDAAmC;AACnC,iDAA8B;AAC9B,2CAAwB"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { CompanyUri, DeviceUri, OkfMetricUri, PlotUri, QudtUnitUri } from '@bradtech/types';
|
|
2
|
+
/**
|
|
3
|
+
* Standard output record produced by a sensor converter.
|
|
4
|
+
* Encapsulates the converted metric, physical value, standard unit, and quality index.
|
|
5
|
+
*/
|
|
6
|
+
export interface ConversionOutput {
|
|
7
|
+
/** Canonical OKF metric identifier (e.g. 'okf:soil/moisture/10cm', 'okf:agronomy/microclimate/canopy_temperature') */
|
|
8
|
+
metric: OkfMetricUri | (string & {});
|
|
9
|
+
/** Calibrated, normalized physical value */
|
|
10
|
+
value: number;
|
|
11
|
+
/** Human-readable unit symbol (e.g. '%', '°C', 'hPa', 'W/m²', 'V') */
|
|
12
|
+
unit: string;
|
|
13
|
+
/** QUDT Semantic Web ontology URI for strict physical unit interoperability */
|
|
14
|
+
qudtUri: QudtUnitUri | (string & {});
|
|
15
|
+
/** Quality and confidence score between 0.0 (erroneous/degraded) and 1.0 (nominal) */
|
|
16
|
+
confidence: number;
|
|
17
|
+
/** Supplementary calculation parameters, algorithm metadata, or intermediate variables */
|
|
18
|
+
metadata?: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Mathematical parameters for linear regression calibration models ($y = a \cdot x + b$).
|
|
22
|
+
*/
|
|
23
|
+
export interface LinearRegressionModel {
|
|
24
|
+
/** Slope coefficient ($a$ in $y = a \cdot x + b$) */
|
|
25
|
+
slope: number;
|
|
26
|
+
/** Y-intercept offset ($b$ in $y = a \cdot x + b$) */
|
|
27
|
+
intercept: number;
|
|
28
|
+
/** Optional coefficient of determination ($R^2$) representing model fit accuracy */
|
|
29
|
+
r2?: number;
|
|
30
|
+
/** Optional human-readable description or laboratory calibration certificate reference */
|
|
31
|
+
modelLabel?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Environmental, spatial, and device context supplied during sensor conversion.
|
|
35
|
+
*/
|
|
36
|
+
export interface ConversionContext {
|
|
37
|
+
/** Canonical device URI (e.g. 'probes/b25s004', 'weather-stations/b26w001') */
|
|
38
|
+
deviceId?: DeviceUri | (string & {});
|
|
39
|
+
/** Canonical plot URI (e.g. 'plots/e5eadee3-bb95-4cf0-b1f5-45db93bbfa81') */
|
|
40
|
+
plotId?: PlotUri | (string & {});
|
|
41
|
+
/** Canonical tenant/company URI */
|
|
42
|
+
companyId?: CompanyUri | (string & {});
|
|
43
|
+
/** Observation timestamp */
|
|
44
|
+
timestamp?: string | Date;
|
|
45
|
+
/** Soil USDA textural class preset */
|
|
46
|
+
soilTexture?: 'sand' | 'loam' | 'clay' | 'silt' | 'peat' | 'default';
|
|
47
|
+
/** Specific custom linear regression model calibrated for the target plot */
|
|
48
|
+
soilLinearRegression?: LinearRegressionModel;
|
|
49
|
+
/** Generic hardware or algorithm calibration key-value parameters */
|
|
50
|
+
calibration?: Record<string, any>;
|
|
51
|
+
/** Ambient air temperature in °C for thermal compensation */
|
|
52
|
+
ambientTemperature?: number;
|
|
53
|
+
/** Local atmospheric pressure in hPa */
|
|
54
|
+
atmosphericPressureHpa?: number;
|
|
55
|
+
/** Elevation above sea level in meters (used for QNH and barometric reduction) */
|
|
56
|
+
altitudeMeters?: number;
|
|
57
|
+
/** Battery chemistry classification */
|
|
58
|
+
batteryChemistry?: 'li_ion' | 'lifepo4' | 'alkaline' | 'supercap';
|
|
59
|
+
/** Arbitrary contextual parameters */
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Universal interface contract for all Brad sensor conversion adapters.
|
|
64
|
+
*
|
|
65
|
+
* @template TRaw - Input payload data type (raw number, binary buffer, or composite object).
|
|
66
|
+
* @template TContext - Environmental and spatial context type.
|
|
67
|
+
*/
|
|
68
|
+
export interface SensorConverterInterface<TRaw = any, TContext extends ConversionContext = ConversionContext> {
|
|
69
|
+
/** Sensor domain family classification (e.g. 'air', 'soil', 'weather', 'power', 'acoustic') */
|
|
70
|
+
readonly sensorFamily: string;
|
|
71
|
+
/** Unique machine-readable algorithmic model code (e.g. 'soil-vwc-texture-calibrated') */
|
|
72
|
+
readonly modelCode: string;
|
|
73
|
+
/** Semantic version string of the algorithm implementation (e.g. '1.0.0') */
|
|
74
|
+
readonly modelVersion: string;
|
|
75
|
+
/** Human-readable description of the conversion algorithm and its theoretical foundation */
|
|
76
|
+
readonly description: string;
|
|
77
|
+
/**
|
|
78
|
+
* Executes the mathematical conversion from raw sensor signals to normalized physical outputs.
|
|
79
|
+
*
|
|
80
|
+
* @param raw - The raw sensor reading or observation payload.
|
|
81
|
+
* @param context - Optional environmental, soil texture, or calibration parameters.
|
|
82
|
+
* @returns An array of normalized physical conversion outputs.
|
|
83
|
+
*/
|
|
84
|
+
convert(raw: TRaw, context?: TContext): ConversionOutput[];
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACT,UAAU,EACV,SAAS,EACT,YAAY,EACZ,OAAO,EACP,WAAW,EACb,MAAM,iBAAiB,CAAA;AAExB;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC9B,sHAAsH;IACtH,MAAM,EAAE,YAAY,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;IACpC,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAA;IACb,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAA;IACZ,+EAA+E;IAC/E,OAAO,EAAE,WAAW,GAAG,CAAC,MAAM,GAAG,EA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