Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 0e31930

Browse files
authored
Add sample_project field to imaging metadata (#275)
1 parent 0dc500e commit 0e31930

File tree

9 files changed

+38
-1088
lines changed

9 files changed

+38
-1088
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ on:
44
push:
55
branches:
66
- main
7-
- gh-readonly-queue/dev/**
87
pull_request:
98
branches: [ main ]
9+
merge_group:
1010
workflow_dispatch:
1111

1212
jobs:

.github/workflows/codeql-analysis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
pull_request:
99
# The branches below must be a subset of the branches above
1010
branches: [ main ]
11+
merge_group:
1112
schedule:
1213
- cron: '11 0 * * 5'
1314

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ release: install buildweb
8484
goreleaser --clean
8585

8686
.PHONY: run-live
87-
run: ## go run
87+
run-live: ## go run
8888
@go run -race ./cmd/pslive
8989

9090
.PHONY: run-local

internal/app/pslive/routes/instruments/planktoscope.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func replaceImagerStream(
393393
}
394394

395395
func handleImagerSettings(
396-
sampleID, imagingRaw, direction, stepVolumeRaw, stepDelayRaw, stepsRaw string,
396+
sampleProjectID, sampleID, imagingRaw, direction, stepVolumeRaw, stepDelayRaw, stepsRaw string,
397397
pc *planktoscope.Client,
398398
) (err error) {
399399
imaging := strings.ToLower(imagingRaw) == "start"
@@ -425,7 +425,7 @@ func handleImagerSettings(
425425
if err != nil {
426426
return echo.NewHTTPError(http.StatusBadRequest, errors.Wrap(err, "couldn't parse steps"))
427427
}
428-
if token, err = pc.SetMetadata(sampleID, time.Now()); err != nil {
428+
if token, err = pc.SetMetadata(sampleProjectID, sampleID, time.Now()); err != nil {
429429
return err
430430
}
431431
// TODO: instead of waiting forever, have a timeout before redirecting and displaying a
@@ -542,7 +542,7 @@ func (h *Handlers) HandleImagerPost() auth.HTTPHandlerFunc {
542542
)
543543
}
544544
if err = handleImagerSettings(
545-
instrument.Name, c.FormValue("imaging"), c.FormValue("direction"),
545+
instrument.Name, "gui", c.FormValue("imaging"), c.FormValue("direction"),
546546
c.FormValue("step-volume"), c.FormValue("step-delay"), c.FormValue("steps"), pc,
547547
); err != nil {
548548
return err

internal/clients/planktoscope/actions.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ func (c *Client) RunStopPumpAction(ctx context.Context) error {
5050
// Imager Actions
5151

5252
type PlanktoscopeImagingParams struct {
53-
SampleID string `hcl:"sample_id"` // TODO: move the sample ID somewhere else?
54-
Forward bool `hcl:"forward"`
55-
StepVolume float64 `hcl:"step_volume"`
56-
StepDelay float64 `hcl:"step_delay"`
57-
Steps uint64 `hcl:"steps"`
53+
SampleProjectID string `hcl:"sample_project_id"` // TODO: move the project ID somewhere else?
54+
SampleID string `hcl:"sample_id"` // TODO: move the sample ID somewhere else?
55+
Forward bool `hcl:"forward"`
56+
StepVolume float64 `hcl:"step_volume"`
57+
StepDelay float64 `hcl:"step_delay"`
58+
Steps uint64 `hcl:"steps"`
5859
}
5960

6061
func (c *Client) RunImagingAction(ctx context.Context, p PlanktoscopeImagingParams) error {
61-
token, err := c.SetMetadata(p.SampleID, time.Now())
62+
token, err := c.SetMetadata(p.SampleProjectID, p.SampleID, time.Now())
6263
if err != nil {
6364
return err
6465
}

internal/clients/planktoscope/metadata.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ package planktoscope
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"time"
67

78
"github.com/eclipse/paho.mqtt.golang"
89
)
910

1011
// Send Commands
1112

12-
func (c *Client) SetMetadata(sampleID string, acquisitionTime time.Time) (mqtt.Token, error) {
13+
func (c *Client) SetMetadata(
14+
sampleProjectID, sampleID string, acquisitionTime time.Time,
15+
) (mqtt.Token, error) {
1316
type Metadata struct {
17+
SampleProjectID string `json:"sample_project"`
1418
SampleID string `json:"sample_id"`
1519
SampleCollectionDate string `json:"object_date"`
1620
SampleCollectionTime string `json:"object_time"`
@@ -22,7 +26,8 @@ func (c *Client) SetMetadata(sampleID string, acquisitionTime time.Time) (mqtt.T
2226
}{
2327
Action: "update_config",
2428
Metadata: Metadata{
25-
SampleID: sampleID,
29+
SampleProjectID: sampleProjectID,
30+
SampleID: fmt.Sprintf("%s_%s", sampleProjectID, sampleID),
2631
SampleCollectionDate: acquisitionTime.Format("2006-01-02"),
2732
SampleCollectionTime: acquisitionTime.Format("15:04:05"),
2833
AcquisitionID: acquisitionTime.Format(time.RFC3339),

internal/clients/planktoscope/models.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type ImagerSettings struct {
7979
}
8080

8181
func DefaultImagerSettings() ImagerSettings {
82-
const defaultStepVolume = 0.4
82+
const defaultStepVolume = 0.04
8383
const defaultStepDelay = 0.5
8484
const defaultSteps = 100
8585
return ImagerSettings{

tools/go.mod

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
module github.com/sargassum-world/pslive/build
1+
module github.com/sargassum-world/pslive/tools
22

33
go 1.19
44

55
require (
66
github.com/deepmap/oapi-codegen v1.12.4
77
github.com/golangci/golangci-lint v1.52.2
8-
github.com/goreleaser/goreleaser v1.16.2
8+
github.com/goreleaser/goreleaser v1.17.2
99
github.com/hairyhenderson/gomplate/v3 v3.11.4
1010
github.com/open-policy-agent/opa v0.51.0
1111
mvdan.cc/gofumpt v0.5.0
@@ -101,7 +101,7 @@ require (
101101
github.com/butuzov/ireturn v0.1.1 // indirect
102102
github.com/bytecodealliance/wasmtime-go/v3 v3.0.2 // indirect
103103
github.com/caarlos0/ctrlc v1.2.0 // indirect
104-
github.com/caarlos0/env/v7 v7.0.0 // indirect
104+
github.com/caarlos0/env/v8 v8.0.0 // indirect
105105
github.com/caarlos0/go-reddit/v3 v3.0.1 // indirect
106106
github.com/caarlos0/go-shellwords v1.0.12 // indirect
107107
github.com/caarlos0/log v0.2.2 // indirect
@@ -196,12 +196,13 @@ require (
196196
github.com/golangci/misspell v0.4.0 // indirect
197197
github.com/golangci/revgrep v0.0.0-20220804021717-745bb2f7c2e6 // indirect
198198
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 // indirect
199+
github.com/google/btree v1.1.2 // indirect
199200
github.com/google/flatbuffers v22.11.23+incompatible // indirect
200201
github.com/google/go-cmp v0.5.9 // indirect
201202
github.com/google/go-containerregistry v0.14.0 // indirect
202203
github.com/google/go-github/v50 v50.1.0 // indirect
203204
github.com/google/go-querystring v1.1.0 // indirect
204-
github.com/google/ko v0.12.0 // indirect
205+
github.com/google/ko v0.13.0 // indirect
205206
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
206207
github.com/google/uuid v1.3.0 // indirect
207208
github.com/google/wire v0.5.0 // indirect
@@ -345,7 +346,7 @@ require (
345346
github.com/securego/gosec/v2 v2.15.0 // indirect
346347
github.com/sergi/go-diff v1.2.0 // indirect
347348
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c // indirect
348-
github.com/sigstore/cosign v1.13.1 // indirect
349+
github.com/sigstore/cosign/v2 v2.0.0 // indirect
349350
github.com/sigstore/rekor v1.0.1 // indirect
350351
github.com/sigstore/sigstore v1.5.1 // indirect
351352
github.com/sirupsen/logrus v1.9.0 // indirect

0 commit comments

Comments
 (0)