Skip to content

Commit 0fd60aa

Browse files
authored
Merge pull request #436 from pixlise/fixes
Fixes
2 parents 0078aa5 + 4afeae8 commit 0fd60aa

99 files changed

Lines changed: 142748 additions & 259 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/dataimport/sdfToRSI/scanSDF.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ func scanSDF(sdfPath string) ([]EventEntry, error) {
115115
refs = append(refs, EventEntry{Line: lineNo, What: "science", Value: "end"})
116116
}
117117

118+
// For scans that are prematurely ended, we may not get the above, so treat the scan log printing out
119+
// less points than actual as a science end!
120+
if isPrematureEnd(lineData) {
121+
refs = append(refs, EventEntry{Line: lineNo, What: "science", Value: "end"})
122+
}
123+
118124
if strings.Contains(lineData, "Open the Dust Cover\"") {
119125
refs = append(refs, EventEntry{Line: lineNo, What: "dust-cover", Value: "opening"})
120126
}
@@ -142,6 +148,37 @@ func scanSDF(sdfPath string) ([]EventEntry, error) {
142148
return refs, nil
143149
}
144150

151+
func isPrematureEnd(lineData string) bool {
152+
// Example line:
153+
// Planned Points: 2339 Actual: 761
154+
plannedToken := "Planned Points:"
155+
actualToken := "Actual:"
156+
157+
plannedPtsIdx := strings.Index(lineData, plannedToken)
158+
actualPtsIdx := strings.Index(lineData, actualToken)
159+
160+
if plannedPtsIdx > -1 && actualPtsIdx > plannedPtsIdx {
161+
plannedPtsIdx += len(plannedToken)
162+
163+
// Check further... does the point count differ?
164+
plannedPtsStr := strings.Trim(lineData[plannedPtsIdx:actualPtsIdx], " \t")
165+
166+
actualPtsIdx += len(actualToken)
167+
actualPtsStr := strings.Trim(lineData[actualPtsIdx:], " \r\n\t")
168+
169+
plannedPts, err := strconv.Atoi(plannedPtsStr)
170+
if err == nil {
171+
actualPts, err := strconv.Atoi(actualPtsStr)
172+
if err == nil {
173+
// Both are ints, check!
174+
return plannedPts > actualPts
175+
}
176+
}
177+
}
178+
179+
return false
180+
}
181+
145182
func readRTT(tok string) (int64, error) {
146183
tok = strings.Trim(tok, "\t ")
147184
if len(tok) <= 0 {

api/dataimport/sdfToRSI/scanSDF_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,16 @@ func Example_scanSDF() {
4949
// 276000: science: 'end'
5050
//
5151
}
52+
53+
func Example_isPrematureEnd() {
54+
fmt.Printf("end: %v\n", isPrematureEnd(" Planned Points: 2339 Actual: 761"))
55+
fmt.Printf("end: %v\n", isPrematureEnd(" Planned Points: 2339 Actual: 761 "))
56+
fmt.Printf("end: %v\n", isPrematureEnd(" Planned Points: 2339 Actual: 761\n"))
57+
fmt.Printf("end: %v\n", isPrematureEnd(" Planned Points: 2339 Actual: 7611"))
58+
59+
// Output:
60+
// end: true
61+
// end: true
62+
// end: true
63+
// end: false
64+
}

api/dataimport/sdfToRSI/sdfToRSI.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,24 @@ func sdfToRSI(sdfPath string, rtt int64, startLine int, endLine int, outPath str
157157
out := strings.Builder{}
158158
err = nil
159159
if tok == "gv" {
160+
sliSpotlistFilenameToken := "Filename token: \"_MCC_SLI_SpotList_BF\""
160161
if state != "gv" {
161162
// NOTE: we ignore gv until we find startTok on the line - we then expect/read gv lines until they stop coming
162-
startTok := "Filename token: \"_MCC_SLI_SpotList_BF\""
163-
164-
if strings.HasSuffix(lineData, startTok) {
163+
if strings.HasSuffix(lineData, sliSpotlistFilenameToken) {
165164
state = "gv" // expect gv from now
166165
continue
167166
} else {
168167
// We're not interested in this gv
169168
continue
170169
}
170+
} else {
171+
// We're already in state=gv so reading lines for MCC_SLI_SpotList_BF already...
172+
// but there's a chance it's the start of another file name. Check for this
173+
startTok := "Filename token: \""
174+
if (strings.Contains(lineData, startTok)) && !strings.HasSuffix(lineData, sliSpotlistFilenameToken) {
175+
state = "" // yep we've ended our state reading, stop here
176+
continue
177+
}
171178
}
172179

173180
err = processGV(lineNo, line, lineData, sclk, rtt, pmc, &out)

api/dataimport/sdfToRSI/sdfToRSI_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"path/filepath"
1010
)
1111

12-
func Example_ConvertSDFtoRSI() {
12+
func Example_sdfToRSI_ConvertSDFtoRSI() {
1313
ensureSDFRawExists()
1414

1515
fmt.Printf("mkdir worked: %v\n", os.MkdirAll("./output", 0777) == nil) // other than 0777 fails in unit tests :(
@@ -25,6 +25,20 @@ func Example_ConvertSDFtoRSI() {
2525
// [RSI-208536069.csv HK-208536069.csv RSI-208601602.csv HK-208601602.csv], [208536069 208601602]: <nil>
2626
}
2727

28+
func Example_sdfToRSI_ConvertSDFtoRSI_EndingPrematurely() {
29+
fmt.Printf("mkdir worked: %v\n", os.MkdirAll("./output", 0777) == nil) // other than 0777 fails in unit tests :(
30+
wd, err := os.Getwd()
31+
fmt.Printf("Getwd: %v\n", err == nil)
32+
p := filepath.Join(wd, "output")
33+
files, rtts, err := ConvertSDFtoRSIs("./test-data/sdf_raw_premature_end.txt", p)
34+
fmt.Printf("%v, %v: %v\n", files, rtts, err)
35+
36+
// Output:
37+
// mkdir worked: true
38+
// Getwd: true
39+
// [RSI-453.csv HK-453.csv RSI-453.csv HK-453.csv], [453 453]: <nil>
40+
}
41+
2842
func ensureSDFRawExists() {
2943
// If it's not here, unzip it
3044
_, err := os.Stat("./test-data/sdf_raw.txt")

api/dataimport/sdfToRSI/test-data/sdf_raw_premature_end.txt

Lines changed: 142424 additions & 0 deletions
Large diffs are not rendered by default.

api/router/helpers.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ func logHandlerErrors(err error, log logger.ILogger, w http.ResponseWriter, r *h
5858
case errorwithstatus.Error:
5959
// We can retrieve the status here and write out a specific
6060
// HTTP status code.
61-
log.Errorf("Request: %v (%v), Result: status=%v, error=%v", r.URL, r.Method, e.Status(), e)
61+
// Memoisation spams this a lot, we can switch this to debug level for those
62+
err := fmt.Sprintf("Request: %v (%v), Result: status=%v, error=%v", r.URL, r.Method, e.Status(), e)
63+
if strings.HasPrefix(r.URL.String(), "/memoise?key=") && r.Method == "GET" {
64+
log.Debugf(err)
65+
} else {
66+
log.Errorf(err)
67+
}
6268
http.Error(w, e.Error(), e.Status())
6369
default:
6470
log.Errorf("Request: %v (%v), Result: status=%v, error=%v", r.URL, r.Method, http.StatusInternalServerError, e)

core/client/client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ func (c *APIClient) GetQuantColumnAsMap(quantId string, columnName string, detec
576576
columnType := protos.Quantification_QT_FLOAT
577577
for i, l := range quant.Data.Labels {
578578
if l == columnName {
579-
fmt.Println(l)
580579
// We've found our column!
581580
columnIdx = i
582581
columnType = quant.Data.Types[i]

generated-protos/detector-config-msgs.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated-protos/detector-config.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated-protos/diffraction-data.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)