Dr-Swopt 4 timmar sedan
förälder
incheckning
3a04becb84

BIN
palm_history.db


+ 5 - 1
src/palm-oil/entities/history.entity.ts

@@ -1,4 +1,4 @@
-import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn } from 'typeorm';
+import { Entity, Column, Index, PrimaryGeneratedColumn, CreateDateColumn } from 'typeorm';
 
 @Entity()
 export class History {
@@ -8,6 +8,10 @@ export class History {
   @Column({ unique: true })
   archive_id: string;
 
+  @Index()
+  @Column({ nullable: true })
+  batch_id: string;
+
   @Column()
   filename: string;
 

+ 2 - 1
src/palm-oil/palm-oil.service.ts

@@ -25,7 +25,7 @@ export class PalmOilService {
     }
   }
 
-  async analyzeImage(imageBuffer: Buffer, originalFilename: string = 'unknown.jpg'): Promise<AnalysisResponse> {
+  async analyzeImage(imageBuffer: Buffer, originalFilename: string = 'unknown.jpg', batchId?: string): Promise<AnalysisResponse> {
     const processingStart = performance.now();
 
     // 1. Get original image dimensions
@@ -85,6 +85,7 @@ export class PalmOilService {
 
     history.inference_ms = parseFloat(inferenceMs.toFixed(2));
     history.processing_ms = parseFloat(processingMs.toFixed(2));
+    if (batchId) history.batch_id = batchId;
 
     await this.historyRepository.save(history);
 

+ 3 - 1
src/palm-oil/vision.gateway.ts

@@ -35,6 +35,8 @@ interface VisionStreamPayload {
   frame: string;
   /** Optional: lets the UI tag which camera source the frame came from */
   sourceLabel?: string;
+  /** UUID shared across all frames in a batch session — links DB rows for Vault grouping */
+  batchId?: string;
 }
 
 // ─── Payload shape Angular sends on chat:send ─────────────────────────────────
@@ -123,7 +125,7 @@ export class VisionGateway
     // to complete first. This is the intentional I/O bottleneck.
     let result: AnalysisResponse;
     try {
-      result = await this.palmOilService.analyzeImage(imageBuffer, sourceLabel);
+      result = await this.palmOilService.analyzeImage(imageBuffer, sourceLabel, payload.batchId);
     } catch (err: any) {
       this.logger.error(`❌ Inference failed for ${client.id}: ${err.message}`);
       client.emit('vision:error', { message: err.message });