-
Notifications
You must be signed in to change notification settings - Fork 1
/
quantification-retrieval.go
103 lines (84 loc) · 3.32 KB
/
quantification-retrieval.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package wsHandler
import (
"fmt"
"path"
"github.com/pixlise/core/v4/api/dbCollections"
"github.com/pixlise/core/v4/api/filepaths"
"github.com/pixlise/core/v4/api/quantification"
"github.com/pixlise/core/v4/api/ws/wsHelpers"
protos "github.com/pixlise/core/v4/generated-protos"
)
func HandleQuantListReq(req *protos.QuantListReq, hctx wsHelpers.HandlerContext) (*protos.QuantListResp, error) {
items, idToOwner, err := quantification.ListUserQuants(req.SearchParams, hctx)
if err != nil {
return nil, err
}
quants := []*protos.QuantificationSummary{}
for _, item := range items {
if owner, ok := idToOwner[item.Id]; ok {
item.Owner = wsHelpers.MakeOwnerSummary(owner, hctx.SessUser, hctx.Svcs.MongoDB, hctx.Svcs.TimeStamper)
}
quants = append(quants, item)
}
return &protos.QuantListResp{
Quants: quants,
}, nil
}
func HandleQuantGetReq(req *protos.QuantGetReq, hctx wsHelpers.HandlerContext) (*protos.QuantGetResp, error) {
dbItem, ownerItem, err := wsHelpers.GetUserObjectById[protos.QuantificationSummary](false, req.QuantId, protos.ObjectType_OT_QUANTIFICATION, dbCollections.QuantificationsName, hctx)
if err != nil {
return nil, err
}
// TODO: something with owner? Should we add it to the outgoing item?
// If they want data too, retrieve it
var quant *protos.Quantification
if !req.SummaryOnly {
//quantPath := filepaths.GetQuantPath(hctx.SessUser.User.Id, dbItem.Params.Params.DatasetID, req.QuantId+".bin")
quantPath := path.Join(dbItem.Status.OutputFilePath, req.QuantId+".bin")
quant, err = wsHelpers.ReadQuantificationFile(req.QuantId, quantPath, hctx.Svcs)
if err != nil {
return nil, err
}
}
// We seem to have some old quants where the status struct says start time was 0, but there is another start time in quant params, so
// substitute a non-zero value in this case
if dbItem.Status.StartUnixTimeSec == 0 && dbItem.Params.StartUnixTimeSec > 0 {
dbItem.Status.StartUnixTimeSec = dbItem.Params.StartUnixTimeSec
}
dbItem.Owner = wsHelpers.MakeOwnerSummary(ownerItem, hctx.SessUser, hctx.Svcs.MongoDB, hctx.Svcs.TimeStamper)
return &protos.QuantGetResp{
Summary: dbItem,
Data: quant,
}, nil
}
func HandleQuantLastOutputGetReq(req *protos.QuantLastOutputGetReq, hctx wsHelpers.HandlerContext) (*protos.QuantLastOutputGetResp, error) {
if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil {
return nil, err
}
if req.PiquantCommand != "quant" {
return nil, fmt.Errorf("PiquantCommand must be quant") // for now!
}
if req.OutputType != protos.QuantOutputType_QO_DATA && req.OutputType != protos.QuantOutputType_QO_LOG {
return nil, fmt.Errorf("Invalid OutputType")
}
// Get the file name
fileName := ""
if req.OutputType == protos.QuantOutputType_QO_DATA {
fileName = filepaths.QuantLastOutputFileName + ".csv" // quant only supplies this
} else {
fileName = filepaths.QuantLastOutputLogName
}
// Get the path to stream
s3Path := filepaths.GetUserLastPiquantOutputPath(hctx.SessUser.User.Id, req.ScanId, req.PiquantCommand, fileName)
result, err := hctx.Svcs.FS.ReadObject(hctx.Svcs.Config.UsersBucket, s3Path)
if err != nil {
if hctx.Svcs.FS.IsNotFoundError(err) {
// Just return empty
result = []byte{}
err = nil
} else {
return nil, err
}
}
return &protos.QuantLastOutputGetResp{Output: string(result)}, nil
}