Skip to content

Commit 65c2a17

Browse files
committed
Rename convertible event content.data to content.vectors
Clearer naming for the N-D observation vector in convertible events (mood/5d-vectors, vulva-mucus-inspect/9d-vector). Updates convertMethodToEvent, convertEventToMethod, formatConvertible, and tests.
1 parent f4de9b4 commit 65c2a17

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

tests/converterEngine.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ describe('[MCVX] HDSModelConverters with loadPack', function () {
224224
const event = await converters.convertMethodToEvent('cervical-fluid', 'mira', 'Creamy');
225225
assert.strictEqual(event.type, 'vulva-mucus-inspect/9d-vector');
226226
assert.deepStrictEqual(event.streamIds, ['body-vulva-mucus-inspect']);
227-
assert.ok(event.content.data, 'should have data');
228-
assert.strictEqual(event.content.data.threadiness, 0.4);
227+
assert.ok(event.content.vectors, 'should have vectors');
228+
assert.strictEqual(event.content.vectors.threadiness, 0.4);
229229
assert.ok(event.content.source, 'should have source');
230230
assert.strictEqual(event.content.source.key, 'mira');
231231
assert.strictEqual(event.content.source.sourceData, 'Creamy');
@@ -255,7 +255,7 @@ describe('[MCVX] HDSModelConverters with loadPack', function () {
255255
const event = await converters.convertMethodToEvent('mood', 'mira', 'Sad');
256256
assert.strictEqual(event.type, 'mood/5d-vectors');
257257
assert.deepStrictEqual(event.streamIds, ['wellbeing-mood']);
258-
assert.strictEqual(event.content.data.valence, 0.15);
258+
assert.strictEqual(event.content.vectors.valence, 0.15);
259259
assert.strictEqual(event.content.source.key, 'mira');
260260
assert.strictEqual(event.content.source.sourceData, 'Sad');
261261
});

ts/HDSModel/HDSModel-Converters.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class HDSModelConverters {
9494
type: engine.eventType,
9595
streamIds: [itemDef.streamId],
9696
content: {
97-
data: vector,
97+
vectors: vector,
9898
source,
9999
},
100100
};
@@ -103,17 +103,17 @@ export class HDSModelConverters {
103103
/**
104104
* Convert a stored event to a target method observation.
105105
*
106-
* @param event - Pryv event with content.data (the N-D vector)
106+
* @param event - Pryv event with content.vectors (the N-D vector)
107107
* @param targetMethod - target method id
108108
* @returns { data, matchDistance }
109109
*/
110110
async convertEventToMethod (event: any, targetMethod: string): Promise<ConversionResult> {
111111
const itemKey = await this.#findItemKeyForEvent(event);
112112
const engine = await this.ensureEngine(itemKey);
113113

114-
const vector: ObservationVector = event.content?.data;
114+
const vector: ObservationVector = event.content?.vectors;
115115
if (!vector || typeof vector !== 'object') {
116-
throw new Error(`Event content.data is not a valid vector: ${JSON.stringify(event.content)}`);
116+
throw new Error(`Event content.vectors is not a valid vector: ${JSON.stringify(event.content)}`);
117117
}
118118

119119
return engine.fromVector(targetMethod, vector);

ts/HDSModel/eventToShortText.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function formatConvertible (_event: any, content: any, itemDef: any, model: any)
215215

216216
const itemKey = ce.models;
217217
const source = content?.source;
218-
const data = content?.data;
218+
const vectors = content?.vectors;
219219

220220
// If source block exists, show the source observation + method name
221221
if (source?.sourceData != null && source?.key) {
@@ -227,14 +227,14 @@ function formatConvertible (_event: any, content: any, itemDef: any, model: any)
227227
const truncated = sourceLabel.length > 40 ? sourceLabel.slice(0, 40) + '...' : sourceLabel;
228228

229229
// Check for autoConvert setting
230-
if (HDSSettings.isHooked && data) {
230+
if (HDSSettings.isHooked && vectors) {
231231
const settingKey = `autoConvert-${itemDef.key}`;
232232
try {
233233
const targetMethod = HDSSettings.get(settingKey as any);
234234
if (targetMethod && typeof targetMethod === 'string') {
235235
const engine = model.converters?.getEngine(itemKey);
236236
if (engine) {
237-
const result = engine.fromVector(targetMethod, data);
237+
const result = engine.fromVector(targetMethod, vectors);
238238
const resultLabel = typeof result.data === 'string' ? result.data : JSON.stringify(result.data);
239239
return `${resultLabel} (${targetMethod})`;
240240
}
@@ -246,8 +246,8 @@ function formatConvertible (_event: any, content: any, itemDef: any, model: any)
246246
}
247247

248248
// No source — RAW vector input, show dimension summary
249-
if (data && typeof data === 'object') {
250-
const dims = Object.entries(data).filter(([_, v]) => typeof v === 'number' && v > 0);
249+
if (vectors && typeof vectors === 'object') {
250+
const dims = Object.entries(vectors).filter(([_, v]) => typeof v === 'number' && v > 0);
251251
if (dims.length === 0) return 'empty';
252252
const top = dims.sort(([, a], [, b]) => (b as number) - (a as number)).slice(0, 3);
253253
return top.map(([k, v]) => `${k}:${(v as number).toFixed(1)}`).join(' ');

0 commit comments

Comments
 (0)