From 40b6adc2c454c406260659a2ed670ca495013fce Mon Sep 17 00:00:00 2001 From: juliecoust Date: Tue, 1 Oct 2024 17:17:11 +0200 Subject: [PATCH] DEV list importable lpm samples uvp5 --- src/domain/entities/sample.ts | 10 ++-- .../repositories/sample-repository.ts | 2 +- src/domain/repositories/sample-repository.ts | 50 ++++++++++++++----- .../sample/list-importable-samples.ts | 2 +- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/domain/entities/sample.ts b/src/domain/entities/sample.ts index baebbd5..a92cdec 100644 --- a/src/domain/entities/sample.ts +++ b/src/domain/entities/sample.ts @@ -43,9 +43,9 @@ export interface HeaderSampleModel { endImg: string; yoyo: string; stationId: string; - sampleType: string; - integrationTime: string; - argoId: string; - pixelSize: string; - sampleDateTime: string; + sampleType: string | undefined; + integrationTime: string | undefined; + argoId: string | undefined; + pixelSize: string | undefined; + sampleDateTime: string | undefined; } \ No newline at end of file diff --git a/src/domain/interfaces/repositories/sample-repository.ts b/src/domain/interfaces/repositories/sample-repository.ts index 65db504..97ac927 100644 --- a/src/domain/interfaces/repositories/sample-repository.ts +++ b/src/domain/interfaces/repositories/sample-repository.ts @@ -2,5 +2,5 @@ import { PublicSampleResponseModel } from "../../entities/sample"; export interface SampleRepository { ensureFolderExists(root_folder_path: string): Promise; - listImportableSamples(root_folder_path: string): Promise; + listImportableSamples(root_folder_path: string, instrument_model: string): Promise; } \ No newline at end of file diff --git a/src/domain/repositories/sample-repository.ts b/src/domain/repositories/sample-repository.ts index ef59359..68ab3b2 100644 --- a/src/domain/repositories/sample-repository.ts +++ b/src/domain/repositories/sample-repository.ts @@ -6,7 +6,6 @@ // import { PreparedSearchOptions, SearchResult } from "../entities/search"; // import { SampleRepository } from "../interfaces/repositories/sample-repository"; -import { head } from "shelljs"; import { HeaderSampleModel, PublicHeaderSampleResponseModel } from "../entities/sample"; import { SampleRepository } from "../interfaces/repositories/sample-repository"; @@ -37,38 +36,49 @@ export class SampleRepositoryImpl implements SampleRepository { } } - async listImportableSamples(root_folder_path: string): Promise { + async listImportableSamples(root_folder_path: string, instrument_model: string): Promise { + let samples: PublicHeaderSampleResponseModel[] = []; const folderPath = path.join(root_folder_path); // read from folderPath/meta/*header*.txt and return the list of samples const meta_header_samples = await this.getSamplesFromHeaders(folderPath); - // read from folderPath/ecodata and return the list of samples - const ecodata_samples = await this.getSamplesFromEcodata(folderPath); + if (instrument_model.startsWith('UVP6')) { + // read from folderPath/ecodata and return the list of samples + const samples_ecodata = await this.getSamplesFromEcodata(folderPath); + samples = await this.setupSamples(meta_header_samples, samples_ecodata, "ecodata"); + } else if (instrument_model.startsWith('UVP5')) { + // read from folderPath/work and return the list of samples + const samples_work = await this.getSamplesFromWork(folderPath); + samples = await this.setupSamples(meta_header_samples, samples_work, "work"); + } + + return samples; + } + // Function to setup samples + async setupSamples(meta_header_samples: HeaderSampleModel[], samples: string[], folder: string): Promise { // flag qc samples to flase if not in both lists, and add qc message - const samples: PublicHeaderSampleResponseModel[] = []; + const samples_response: PublicHeaderSampleResponseModel[] = []; for (const sample of meta_header_samples) { - samples.push({ - sample_name: sample.filename, + samples_response.push({ + sample_name: sample.profileId, raw_file_name: sample.filename, station_id: sample.stationId, first_image: sample.firstImage, last_image: sample.endImg, comment: sample.comment, - qc_lvl1: ecodata_samples.includes(sample.filename) ? true : false, - qc_lvl1_comment: ecodata_samples.includes(sample.filename) ? '' : 'Sample not found in ecodata folder' + qc_lvl1: samples.includes(sample.profileId) ? true : false, + qc_lvl1_comment: samples.includes(sample.profileId) ? '' : 'Sample not found in ' + folder + ' folder' }); } - return samples; + return samples_response; } - // Function to read and return samples from header.txt files async getSamplesFromHeaders(folderPath: string): Promise { const samples: HeaderSampleModel[] = []; try { const header_path = path.join(folderPath, 'meta'); const files = await fs.readdir(header_path); - console.log('header files', files); for (const file of files) { if (file.includes('header') && file.endsWith('.txt')) { const filePath = path.join(header_path, file); @@ -138,6 +148,22 @@ export class SampleRepositoryImpl implements SampleRepository { return samples; } + // Function to read and return samples from work folder names + async getSamplesFromWork(folderPath: string): Promise { + const samples: string[] = []; + try { + const files = await fs.readdir(path.join(folderPath, 'work')); + + for (const file of files) { + samples.push(file); + } + } catch (err) { + throw new Error(`Error reading files: ${err.message}`); + } + + return samples; + } + // async createSample(sample: SampleRequestCreationModel): Promise { diff --git a/src/domain/use-cases/sample/list-importable-samples.ts b/src/domain/use-cases/sample/list-importable-samples.ts index f3acf27..6f39dce 100644 --- a/src/domain/use-cases/sample/list-importable-samples.ts +++ b/src/domain/use-cases/sample/list-importable-samples.ts @@ -40,7 +40,7 @@ export class ListImportableSamples implements ListImportableSamplesUseCase { private async listImportableSamples(project: ProjectResponseModel): Promise { await this.sampleRepository.ensureFolderExists(project.root_folder_path); - const samples = await this.sampleRepository.listImportableSamples(project.root_folder_path); + const samples = await this.sampleRepository.listImportableSamples(project.root_folder_path, project.instrument_model); return samples; }