-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #260 from pixlise/bugfix/autoquant
Bugfix/autoquant
- Loading branch information
Showing
9 changed files
with
371 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package notificationSender | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/pixlise/core/v4/api/dbCollections" | ||
"github.com/pixlise/core/v4/core/logger" | ||
"github.com/pixlise/core/v4/core/wstestlib" | ||
protos "github.com/pixlise/core/v4/generated-protos" | ||
) | ||
|
||
func Example_notificationDBSave() { | ||
db := wstestlib.GetDB() | ||
ctx := context.TODO() | ||
|
||
// Clear relevant collections | ||
db.Collection(dbCollections.NotificationsName).Drop(ctx) | ||
|
||
notif := &protos.Notification{ | ||
Id: "ajm5d5bjs4vq7bkc-auth0|5de45d85ca40070f421a3a34", | ||
DestUserId: "auth0|5de45d85ca40070f421a3a34", | ||
Subject: "Quantification Peters combined v4 test quant has completed with status: Complete", | ||
Contents: "A quantification named Peters combined v4 test quant (id: quant-wqp66sayhowj41ej) has completed with status Complete. This quantification is for the scan named: Castle Geyser", | ||
From: "Data Importer", | ||
TimeStampUnixSec: 1710831761, | ||
ActionLink: "?q=393871873&quant=quant-wqp66sayhowj41ej", | ||
NotificationType: protos.NotificationType_NT_USER_MESSAGE, | ||
} | ||
|
||
n := MakeNotificationSender("abc123", db, nil, nil, &logger.StdOutLoggerForTest{}, "unittest", nil, nil) | ||
fmt.Printf("Notification write to empty DB: %v\n", n.saveNotificationToDB("notif123", "destuser123", notif)) | ||
fmt.Printf("Notification overwrite: %v", n.saveNotificationToDB("notif123", "destuser123", notif)) | ||
|
||
// Output: | ||
// Notification write to empty DB: <nil> | ||
// Notification overwrite: <nil> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package quantification | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/pixlise/core/v4/api/dbCollections" | ||
"github.com/pixlise/core/v4/core/logger" | ||
"github.com/pixlise/core/v4/core/wstestlib" | ||
protos "github.com/pixlise/core/v4/generated-protos" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
func Example_getExistingAutoQuants() { | ||
db := wstestlib.GetDB() | ||
|
||
// Ensure none | ||
ctx := context.TODO() | ||
coll := db.Collection(dbCollections.QuantificationsName) | ||
fmt.Printf("Drop: %v\n", coll.Drop(ctx)) | ||
|
||
names := []string{"AutoQuant-PDS(AB)", "AutoQuant-PIXL(AB)", "AutoQuant-PDS(Combined)", "AutoQuant-PIXL(Combined)"} | ||
existing, err := getExistingAutoQuants("123", names, db) | ||
fmt.Println("Test missing") | ||
fmt.Printf("%v\n", err) | ||
fmt.Printf("Read:%v\n\n", strings.Join(existing, ",")) | ||
|
||
autoQuant := &protos.QuantificationSummary{ | ||
Id: "PIXLAB123", | ||
ScanId: "123", | ||
Params: &protos.QuantStartingParameters{ | ||
UserParams: &protos.QuantCreateParams{ | ||
Command: "map", | ||
Name: "AutoQuant-PIXL(AB)", | ||
ScanId: "123", | ||
Elements: []string{"Na", "Mg"}, | ||
DetectorConfig: "PIXL/PiquantConfigs/v7", | ||
Parameters: "-Fe,1", | ||
QuantMode: "Combined", | ||
}, | ||
PmcCount: 51, | ||
ScanFilePath: "Datasets/104202753/dataset.bin", | ||
}, | ||
Elements: []string{"Na2O", "MgO"}, | ||
Status: &protos.JobStatus{ | ||
JobId: "PIXLAB123", | ||
Status: 5, | ||
Message: "Nodes ran: 1", | ||
EndUnixTimeSec: 1670988052, | ||
OutputFilePath: "Quantifications/104202753/auth0|62eda29040fd995f305e2322", | ||
OtherLogFiles: []string{"node00001_piquant.log", "node00001_stdout.log"}, | ||
}, | ||
} | ||
|
||
_, err = coll.InsertOne(ctx, autoQuant, options.InsertOne()) | ||
fmt.Printf("Insert: %v\n", err) | ||
|
||
//names := []string{"AutoQuant-PIXL(AB)"} | ||
existing, err = getExistingAutoQuants("123", names, db) | ||
fmt.Println("Test exists") | ||
fmt.Printf("%v\n", err) | ||
fmt.Printf("%v\n", strings.Join(existing, ",")) | ||
|
||
// Output: | ||
// Drop: <nil> | ||
// Test missing | ||
// <nil> | ||
// Read: | ||
// | ||
// Insert: <nil> | ||
// Test exists | ||
// <nil> | ||
// AutoQuant-PIXL(AB) (id: PIXLAB123) | ||
} | ||
|
||
func Example_readQuantifiablePMCs() { | ||
expr, err := readDatasetFile("./testdata/LagunaSalinasdataset.bin") | ||
fmt.Printf("Read Laguna: %v\n", err) | ||
pmcs, err := readQuantifiablePMCs(expr, "123", &logger.StdOutLoggerForTest{}) | ||
fmt.Printf("PMCRead: %v\n", err) | ||
fmt.Printf("PMCs: %v\n", pmcs) | ||
|
||
expr, err = readDatasetFile("./testdata/Naltsosdataset.bin") | ||
fmt.Printf("Read Naltsos: %v\n", err) | ||
pmcs, err = readQuantifiablePMCs(expr, "123", &logger.StdOutLoggerForTest{}) | ||
fmt.Printf("PMCRead: %v\n", err) | ||
fmt.Printf("PMCs: %v\n", pmcs) | ||
|
||
// Output: | ||
// Read Laguna: <nil> | ||
// PMCRead: <nil> | ||
// PMCs: [] | ||
// Read Naltsos: <nil> | ||
// PMCRead: <nil> | ||
// PMCs: [93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 216] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package wsHelpers | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/pixlise/core/v4/api/dbCollections" | ||
"github.com/pixlise/core/v4/core/logger" | ||
"github.com/pixlise/core/v4/core/scan" | ||
protos "github.com/pixlise/core/v4/generated-protos" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
func UpdateScanImageDataTypes(scanId string, db *mongo.Database, logger logger.ILogger) error { | ||
if len(scanId) <= 0 { | ||
return errors.New("No scanId specified for UpdateScanImageDataTypes") | ||
} | ||
|
||
// Check how many RGBU images and normal images this scan has | ||
ctx := context.TODO() | ||
|
||
coll := db.Collection(dbCollections.ImagesName) | ||
filter := bson.M{"originscanid": scanId} | ||
opt := options.Find() | ||
cursor, err := coll.Find(ctx, filter, opt) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
images := []*protos.ScanImage{} | ||
err = cursor.All(ctx, &images) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
imageCount := uint32(0) | ||
rgbuCount := uint32(0) | ||
|
||
for _, img := range images { | ||
if img.Purpose == protos.ScanImagePurpose_SIP_MULTICHANNEL { | ||
rgbuCount++ | ||
} else { | ||
imageCount++ | ||
} | ||
} | ||
|
||
// Update the scan item | ||
summary, err := scan.ReadScanItem(scanId, db) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
saveDataTypes := []*protos.ScanItem_ScanTypeCount{} | ||
for _, item := range summary.DataTypes { | ||
if item.DataType == protos.ScanDataType_SD_XRF { | ||
saveDataTypes = append(saveDataTypes, item) | ||
} | ||
} | ||
|
||
// Add these if needed | ||
if imageCount > 0 { | ||
saveDataTypes = append(saveDataTypes, &protos.ScanItem_ScanTypeCount{ | ||
DataType: protos.ScanDataType_SD_IMAGE, | ||
Count: imageCount, | ||
}) | ||
} | ||
if rgbuCount > 0 { | ||
saveDataTypes = append(saveDataTypes, &protos.ScanItem_ScanTypeCount{ | ||
DataType: protos.ScanDataType_SD_RGBU, | ||
Count: rgbuCount, | ||
}) | ||
} | ||
|
||
summary.DataTypes = saveDataTypes | ||
|
||
coll = db.Collection(dbCollections.ScansName) | ||
filter = bson.M{"_id": scanId} | ||
replaceResult, err := coll.ReplaceOne(ctx, filter, summary, options.Replace()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if replaceResult.ModifiedCount != 1 { | ||
logger.Infof("UpdateScanImageDataTypes for scan: %v expected ModifiedCount 1, got: %v", scanId, replaceResult.ModifiedCount) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.