Skip to content

Commit

Permalink
Merge pull request #329 from pixlise/development
Browse files Browse the repository at this point in the history
Release 4.37.0
  • Loading branch information
pnemere authored Oct 2, 2024
2 parents eb3637e + d3c9959 commit 9c70a1b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
29 changes: 29 additions & 0 deletions api/piquant/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ package piquant

import (
"context"
"fmt"
"strconv"
"strings"

"github.com/pixlise/core/v4/api/dbCollections"
"github.com/pixlise/core/v4/api/filepaths"
Expand Down Expand Up @@ -79,3 +82,29 @@ func GetDetectorConfig(name string, db *mongo.Database) (*protos.DetectorConfig,

return &cfg, nil
}

func ReadFieldFromPIQUANTConfigMSA(msaContents string, fieldName string) (float32, error) {
piquantCfgLines := strings.Split(msaContents, "\n")
for _, line := range piquantCfgLines {
idx := strings.Index(line, fieldName)
if idx >= 0 {
line := line[idx+len(fieldName):]
idx = strings.Index(line, ":")

if idx >= 0 {
line = line[idx+1:]
line = strings.TrimLeft(line, " ")

// Now snip off anything after it
idx = strings.Index(line, " ")
if idx >= 0 {
line = line[0:idx]
val, err := strconv.ParseFloat(line, 32)
return float32(val), err
}
}
}
}

return 0, fmt.Errorf("Failed to find field %v", fieldName)
}
34 changes: 33 additions & 1 deletion api/ws/handlers/detector-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package wsHandler

import (
"context"
"fmt"

"github.com/pixlise/core/v4/api/dbCollections"
"github.com/pixlise/core/v4/api/filepaths"
"github.com/pixlise/core/v4/api/piquant"
"github.com/pixlise/core/v4/api/ws/wsHelpers"
protos "github.com/pixlise/core/v4/generated-protos"
Expand All @@ -21,9 +23,39 @@ func HandleDetectorConfigReq(req *protos.DetectorConfigReq, hctx wsHelpers.Handl
return nil, err
}

// Read versions
versions := piquant.GetPiquantConfigVersions(hctx.Svcs, req.Id)
if len(versions) <= 0 {
return nil, fmt.Errorf("DetectorConfig %v has no versions defined", req.Id)
}

latestVersion := versions[len(versions)-1]

// Read PIQUANT config file
piquantCfg, err := piquant.GetPIQUANTConfig(hctx.Svcs, req.Id, latestVersion)
if err != nil {
return nil, err
}

// Retrieve elevAngle
cfgPath := filepaths.GetDetectorConfigPath(req.Id, latestVersion, piquantCfg.ConfigFile)
piquantCfgFile, err := hctx.Svcs.FS.ReadObject(hctx.Svcs.Config.ConfigBucket, cfgPath)
if err != nil {
return nil, err
}

// Find the value
piquantCfgFileStr := string(piquantCfgFile)
angle, err := piquant.ReadFieldFromPIQUANTConfigMSA(piquantCfgFileStr, "#ELEVANGLE")
if err != nil {
return nil, fmt.Errorf("Failed to read ELEVANGLE from Piquant config file: %v", cfgPath)
}

cfg.ElevAngle = angle

return &protos.DetectorConfigResp{
Config: cfg,
PiquantConfigVersions: piquant.GetPiquantConfigVersions(hctx.Svcs, req.Id),
PiquantConfigVersions: versions,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion data-formats
16 changes: 13 additions & 3 deletions generated-protos/detector-config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ func testDetectorConfig(apiHost string) {
"xrfeVResolution": 230,
"windowElement": 14,
"tubeElement": 45,
"mmBeamRadius": 0.06
"mmBeamRadius": 0.06,
"elevAngle": 70
},
"piquantConfigVersions": [
"v5",
Expand Down

0 comments on commit 9c70a1b

Please sign in to comment.