diff --git a/api/dataimport/internal/converters/pixlfm/import.go b/api/dataimport/internal/converters/pixlfm/import.go index 049ca4d5..5538323c 100644 --- a/api/dataimport/internal/converters/pixlfm/import.go +++ b/api/dataimport/internal/converters/pixlfm/import.go @@ -304,7 +304,7 @@ func (p PIXLFM) Import(importPath string, pseudoIntensityRangesPath string, data } // Stop after first file log.Infof("Extracting metadata from file name: %v", file) - log.Infof("Meta extracted: %v", housekeepingFileNameMeta.ToString()) + log.Infof("Meta extracted: %v", housekeepingFileNameMeta.ToString(false, false)) break } case "pseudoIntensityDir": diff --git a/api/ws/wsHelpers/image.go b/api/ws/wsHelpers/image.go index 22d404f8..952173dc 100644 --- a/api/ws/wsHelpers/image.go +++ b/api/ws/wsHelpers/image.go @@ -93,9 +93,8 @@ func GetLatestImagesOnly(images []*protos.ScanImage) ([]*protos.ScanImage, error meta.SetVersionStr("__") // Preserve the path - l := path.Dir(img.ImagePath) - if len(l) > 0 { - imagePath := path.Join(img.ImagePath[0:len(l)], meta.ToString()) + if len(meta.FilePath) > 0 { + imagePath := meta.ToString(true, false) // If it doesn't exist, just add it if existingImg, ok := latestImage[imagePath]; ok { @@ -146,7 +145,7 @@ func GetDBImageFilter(imageName string) bson.D { imagePath := imageName if len(root) > 0 { meta.SetVersionStr("..") - imagePath = path.Join(root, meta.ToString()) + imagePath = meta.ToString(true, false) } filter = bson.D{{"_id", primitive.Regex{Pattern: imagePath, Options: ""}}} diff --git a/core/gdsfilename/fmFileNameMeta.go b/core/gdsfilename/fmFileNameMeta.go index 5252a37e..0105aef8 100644 --- a/core/gdsfilename/fmFileNameMeta.go +++ b/core/gdsfilename/fmFileNameMeta.go @@ -21,6 +21,7 @@ package gdsfilename import ( "errors" "fmt" + "path" "path/filepath" "strconv" "strings" @@ -52,6 +53,10 @@ type FileNameMeta struct { versionStr string // 01-99=1-9, A0-A9=100-109, AA-AZ=110-135, B0-B9=136-145, __=out of range // . always before... // EXT - file extension, which we get through conventional Go filepath.Ext() + + // Non-PDS fields that exist in our own file name conventions + FilePath string // We store images with the RTT as a folder + Extension string // see EXT above } func (m *FileNameMeta) SetColourFilter(colourFilter string) { @@ -118,7 +123,7 @@ func (m FileNameMeta) Version() (int32, error) { return stringToVersion(m.versionStr) } -func (m FileNameMeta) ToString() string { +func (m FileNameMeta) ToString(includePath bool, includeExt bool) string { var s strings.Builder s.WriteString(m.Instrument) @@ -141,7 +146,23 @@ func (m FileNameMeta) ToString() string { s.WriteString(m.Producer) s.WriteString(m.versionStr) - return s.String() + fileName := s.String() + + if includePath { + // We may have a path too + if len(m.FilePath) > 0 { + fileName = path.Join(m.FilePath, fileName) + } + } + + if includeExt { + // Add the extension + if len(m.Extension) > 0 { + fileName = fileName + "." + m.Extension + } + } + + return fileName } func (m *FileNameMeta) SetInstrumentType(instrumentType string) { @@ -158,11 +179,16 @@ func (m FileNameMeta) Timestamp() (int32, error) { } */ -func ParseFileName(fileName string) (FileNameMeta, error) { +func ParseFileName(fileNameOptPathPrefix string) (FileNameMeta, error) { + result := FileNameMeta{} + // We often get passed paths so here we ensure we're just dealing with the file name at the end - fileName = filepath.Base(fileName) + fileName := filepath.Base(fileNameOptPathPrefix) - result := FileNameMeta{} + if len(fileNameOptPathPrefix) > len(fileName) { + // Something got snipped... that's our path + result.FilePath = fileNameOptPathPrefix[0 : len(fileNameOptPathPrefix)-len(fileName)-1] + } if len(fileName) != 58 { return result, errors.New("Failed to parse meta from file name") @@ -189,8 +215,8 @@ func ParseFileName(fileName string) (FileNameMeta, error) { result.compression = fileName[49:51] result.Producer = fileName[51:52] result.versionStr = fileName[52:54] - // "." = fileName[53:54] - // EXT = fileName[54:57] + // "." = fileName[54:55] + result.Extension = fileName[55:58] // Length 58 chars return result, nil diff --git a/core/gdsfilename/fmFileNameMeta_test.go b/core/gdsfilename/fmFileNameMeta_test.go index 9ab3719f..8183e262 100644 --- a/core/gdsfilename/fmFileNameMeta_test.go +++ b/core/gdsfilename/fmFileNameMeta_test.go @@ -60,6 +60,12 @@ func Example_parseFileName() { fmt.Printf("%v|%v\n", e, m) printFNValues(m) + // context image with path + fmt.Println("Context image with path:") + m, e = ParseFileName("01234/PCR_D078T0637741562_000FDR_N00100360009835610066000J01.PNG") + fmt.Printf("%v|%v\n", e, m) + printFNValues(m) + // bulk MSA fmt.Println("MSA (bulk) file:") m, e = ParseFileName("PS__D077T0637746318_000RBS_N001003600098356103760__J01.MSA") @@ -100,7 +106,7 @@ func Example_parseFileName() { // Output: // Field test: - // |{IN C S PRIM V SECONDARYT TER PRO G T SIT DRIV SEQNUMRTT CAMS D CO P VE} + // |{IN C S PRIM V SECONDARYT TER PRO G T SIT DRIV SEQNUMRTT CAMS D CO P VE EXT} // PMC=0|PMC only stored for PIXL files // RTT=SEQNUMRTT| // SCLK=0|Failed to get SCLK from: SECONDARYT @@ -110,56 +116,63 @@ func Example_parseFileName() { // Failed to parse meta from file name // // Pseudo-intensity file: - // |{PS _ _ D077 T 0637741109 000 RPM _ N 001 0036 000983561 0064 0 __ J 01} + // |{PS _ _ D077 T 0637741109 000 RPM _ N 001 0036 000983561 0064 0 __ J 01 CSV} // PMC=64| // RTT=000983561| // SCLK=637741109| // SOL=D077| // // Context image file: - // |{PC R _ D077 T 0637741562 000 EDR _ N 001 0036 000983561 0066 0 00 J 01} + // |{PC R _ D077 T 0637741562 000 EDR _ N 001 0036 000983561 0066 0 00 J 01 PNG} // PMC=66| // RTT=000983561| // SCLK=637741562| // SOL=D077| // + // Context image with path: + // |{PC R _ D078 T 0637741562 000 FDR _ N 001 0036 000983561 0066 0 00 J 01 01234 PNG} + // PMC=66| + // RTT=000983561| + // SCLK=637741562| + // SOL=D078| + // // MSA (bulk) file: - // |{PS _ _ D077 T 0637746318 000 RBS _ N 001 0036 000983561 0376 0 __ J 01} + // |{PS _ _ D077 T 0637746318 000 RBS _ N 001 0036 000983561 0376 0 __ J 01 MSA} // PMC=376| // RTT=000983561| // SCLK=637746318| // SOL=D077| // // Housekeeping (RSI) file: - // |{PE _ _ D077 T 0637741109 000 RSI _ N 001 0036 000983561 0066 0 __ J 01} + // |{PE _ _ D077 T 0637741109 000 RSI _ N 001 0036 000983561 0066 0 __ J 01 CSV} // PMC=66| // RTT=000983561| // SCLK=637741109| // SOL=D077| // // All spectra CSV file: - // |{PS _ _ D077 T 0637741109 000 RFS _ N 001 0036 000983561 0064 0 __ J 01} + // |{PS _ _ D077 T 0637741109 000 RFS _ N 001 0036 000983561 0064 0 __ J 01 CSV} // PMC=64| // RTT=000983561| // SCLK=637741109| // SOL=D077| // // Testing SCLK and SOL fields: - // |{PS _ _ 1033 _ 0012345678 000 RFS _ N 001 0036 000983561 0064 0 __ J 01} + // |{PS _ _ 1033 _ 0012345678 000 RFS _ N 001 0036 000983561 0064 0 __ J 01 CSV} // PMC=64| // RTT=000983561| // SCLK=12345678| // SOL=1033| // // Watson file: - // |{SI F _ 0614 _ 0721455441 734 RAS _ N 030 1172 SRLC00643 _000 0 LM J 01} + // |{SI F _ 0614 _ 0721455441 734 RAS _ N 030 1172 SRLC00643 _000 0 LM J 01 PNG} // PMC=0|PMC only stored for PIXL files // RTT=SRLC00643| // SCLK=721455441| // SOL=0614| // // Sherloc file: - // |{SS _ _ 0614 _ 0721475157 600 RRS _ _ 030 1172 SRLC11360 W208 C GN J 01} + // |{SS _ _ 0614 _ 0721475157 600 RRS _ _ 030 1172 SRLC11360 W208 C GN J 01 CSV} // PMC=0|PMC only stored for PIXL files // RTT=SRLC11360| // SCLK=721475157| @@ -189,9 +202,27 @@ func Example_makeComparableName() { func Example_stringFileName() { name := "PS__D077T0637741109_000RPM_N001003600098356100640__J01.CSV" m, e := ParseFileName(name) - fmt.Printf("%v|%v\n", e, m.ToString()) + fmt.Printf("%v|%v\n", e, m.ToString(false, false)) + fmt.Printf("%v|%v\n", e, m.ToString(true, false)) + fmt.Printf("%v|%v\n", e, m.ToString(false, true)) + fmt.Printf("%v|%v\n", e, m.ToString(true, true)) + + name = "0987654321/PS__D077T0637741109_000RPM_N001003600098356100640__J01.CSV" + m, e = ParseFileName(name) + fmt.Printf("%v|%v\n", e, m.ToString(false, false)) + fmt.Printf("%v|%v\n", e, m.ToString(true, false)) + fmt.Printf("%v|%v\n", e, m.ToString(false, true)) + fmt.Printf("%v|%v\n", e, m.ToString(true, true)) + // Output: // |PS__D077T0637741109_000RPM_N001003600098356100640__J01 + // |PS__D077T0637741109_000RPM_N001003600098356100640__J01 + // |PS__D077T0637741109_000RPM_N001003600098356100640__J01.CSV + // |PS__D077T0637741109_000RPM_N001003600098356100640__J01.CSV + // |PS__D077T0637741109_000RPM_N001003600098356100640__J01 + // |0987654321/PS__D077T0637741109_000RPM_N001003600098356100640__J01 + // |PS__D077T0637741109_000RPM_N001003600098356100640__J01.CSV + // |0987654321/PS__D077T0637741109_000RPM_N001003600098356100640__J01.CSV } func Example_stringToIDSimpleCase() {