Skip to content

Commit

Permalink
Merge pull request #2021 from AllenInstitute/feature/2021-dont-show-e…
Browse files Browse the repository at this point in the history
…mpty-keys-in-lbv-browser

Don't show empty labnotebook entries in the LogbookViewer
  • Loading branch information
timjarsky authored Feb 23, 2024
2 parents dd1d93a + 1abab43 commit 5bb3ee1
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 27 deletions.
33 changes: 33 additions & 0 deletions Packages/MIES/MIES_Labnotebook.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,36 @@ threadsafe Function/WAVE LBN_GetTextWave([string defValue])

return data
End

/// @brief Return all labnotebook entries which are at least written once
threadsafe Function/WAVE LBV_GetFilledLabnotebookEntries(WAVE/Z values)

if(!WaveExists(values))
return $""
endif

Make/FREE/N=(DimSize(values, COLS))/T keys

Multithread keys[] = LBV_IsLabnotebookColumnFilled(values, p)

RemoveTextWaveEntry1D(keys, "", all = 1)

if(DimSize(keys, ROWS) == 0)
return $""
endif

return keys
End

/// @brief Return the name of the given labnotebook column if it was written into
/// at least once, an empty string otherwise
threadsafe static Function/S LBV_IsLabnotebookColumnFilled(WAVE values, variable col)

WAVE/Z indizes = FindIndizes(values, col=col, prop=PROP_NON_EMPTY, startLayer = 0, endLayer = LABNOTEBOOK_LAYER_COUNT - 1)

if(WaveExists(indizes))
return GetDimLabel(values, COLS, col)
endif

return ""
End
61 changes: 38 additions & 23 deletions Packages/MIES/MIES_LogbookViewer.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ Function/WAVE LBV_PopupExtGetLBKeys(string win)
return $""
endif

WAVE/T/Z textualKeys = BSP_GetLogbookWave(win, LBT_LABNOTEBOOK, LBN_TEXTUAL_KEYS, selectedExpDevice = 1)
WAVE/T/Z numericalKeys = BSP_GetLogbookWave(win, LBT_LABNOTEBOOK, LBN_NUMERICAL_KEYS, selectedExpDevice = 1)
WAVE/Z textualValues = BSP_GetLogbookWave(win, LBT_LABNOTEBOOK, LBN_TEXTUAL_VALUES, selectedExpDevice = 1)
WAVE/Z numericalValues = BSP_GetLogbookWave(win, LBT_LABNOTEBOOK, LBN_NUMERICAL_VALUES, selectedExpDevice = 1)

WAVE/T textualNames = LBV_GetFilledLabnotebookEntries(textualValues)
WAVE/T numericalNames = LBV_GetFilledLabnotebookEntries(numericalValues)

WAVE/Z entries = LBV_GetAllLogbookKeys(textualKeys, numericalKeys)
WAVE/Z entries = LBV_GetAllLogbookParamNames(textualNames, numericalNames)

return LBV_PopupExtFormatEntries(entries)
End
Expand All @@ -78,50 +81,62 @@ Function/WAVE LBV_PopupExtGetResultsKeys(string win)
return $""
endif

WAVE/T/Z textualKeys = BSP_GetLogbookWave(win, LBT_RESULTS, LBN_TEXTUAL_KEYS, selectedExpDevice = 1)
WAVE/T/Z numericalKeys = BSP_GetLogbookWave(win, LBT_RESULTS, LBN_NUMERICAL_KEYS, selectedExpDevice = 1)
WAVE/Z textualValues = BSP_GetLogbookWave(win, LBT_RESULTS, LBN_TEXTUAL_VALUES, selectedExpDevice = 1)
WAVE/Z numericalValues = BSP_GetLogbookWave(win, LBT_RESULTS, LBN_NUMERICAL_VALUES, selectedExpDevice = 1)

WAVE/T textualNames = LBV_GetFilledLabnotebookEntries(textualValues)
WAVE/T numericalNames = LBV_GetFilledLabnotebookEntries(numericalValues)

WAVE/Z entries = LBV_GetAllLogbookKeys(textualKeys, numericalKeys)
WAVE/Z entries = LBV_GetAllLogbookParamNames(textualNames, numericalNames)

return LBV_PopupExtFormatEntries(entries)
End

/// @brief Returns the combined keys from the numerical and textual MD key loogbook waves as 1D text wave
static Function/WAVE LBV_GetAllLogbookKeys(WAVE/T/Z textualKeys, WAVE/T/Z numericalKeys)
/// @brief Returns the combined parameter names from the numerical and textual MD key loogbook waves as 1D text wave
static Function/WAVE LBV_GetAllLogbookParamNames(WAVE/T/Z textualNames, WAVE/T/Z numericalNames)
variable existText, existNum

WAVE/Z/T textualKeys1D = LBV_GetLogbookKeys(textualKeys)
WAVE/Z/T numericalKeys1D = LBV_GetLogbookKeys(numericalKeys)
WAVE/Z/T textualNamesClean = LBV_CleanLogbookParamNames(textualNames)
WAVE/Z/T numericalNamesClean = LBV_CleanLogbookParamNames(numericalNames)

existText = WaveExists(textualKeys1D)
existNum = WaveExists(numericalKeys1D)
existText = WaveExists(textualNamesClean)
existNum = WaveExists(numericalNamesClean)
if(existText && existNum)
return GetSetUnion(textualKeys1D, numericalKeys1D)
return GetSetUnion(textualNamesClean, numericalNamesClean)
elseif(existText && !existNum)
return textualKeys1D
return textualNamesClean
elseif(!existText && existNum)
return numericalKeys1D
return numericalNamesClean
endif

return $""
End

/// @brief Return a wave with all keys in the logbook key wave
static Function/WAVE LBV_GetLogbookKeys(WAVE/Z/T keyWave)
/// @brief Return a wave with all parameter names in the logbook key wave
static Function/WAVE LBV_GetLogbookParamNames(WAVE/Z/T keys)
variable row

if(!WaveExists(keyWave))
if(!WaveExists(keys))
return $""
endif

row = FindDimLabel(keyWave, ROWS, "Parameter")
row = FindDimLabel(keys, ROWS, "Parameter")

Duplicate/FREE/RMD=[row][] keyWave, keys
Redimension/N=(numpnts(keys))/E=1 keys
Duplicate/FREE/RMD=[row][] keys, names
Redimension/N=(numpnts(keys))/E=1 names

return LBV_CleanLogbookParamNames(names)
End

static Function/WAVE LBV_CleanLogbookParamNames(WAVE/Z/T names)

if(!WaveExists(names))
return $""
endif

WAVE/T hiddenDefaultKeys = ListToTextWave(LABNOTEBOOK_KEYS_INITIAL, ";")

return GetSetDifference(keys, hiddenDefaultKeys)
return GetSetDifference(names, hiddenDefaultKeys)
End

/// @brief Return a text wave with all entries from all TPStorage waves which are candidates for plotting
Expand Down Expand Up @@ -1086,7 +1101,7 @@ Function LBV_PlotAllAnalysisFunctionLBNKeys(string browser, variable anaFuncType
WAVE/T/Z textualKeys = BSP_GetLogbookWave(browser, LBT_LABNOTEBOOK, LBN_TEXTUAL_KEYS, selectedExpDevice = 1)
WAVE/T/Z numericalKeys = BSP_GetLogbookWave(browser, LBT_LABNOTEBOOK, LBN_NUMERICAL_KEYS, selectedExpDevice = 1)

WAVE/T/Z allKeys = LBV_GetAllLogbookKeys(numericalkeys, textualKeys)
WAVE/T/Z allKeys = LBV_GetAllLogbookParamNames(numericalkeys, textualKeys)

if(!WaveExists(allKeys))
printf "Could not find any labnotebook keys.\r"
Expand Down
4 changes: 2 additions & 2 deletions Packages/MIES/MIES_Utilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -5042,8 +5042,8 @@ End
/// @param all [optional, defaults to false] removes all entries
///
/// @return 0 if at least one entry was found, 1 otherwise
Function RemoveTextWaveEntry1D(WAVE/T w, string entry, [variable options, variable all])
ASSERT(IsTextWave(w), "Input wave must be a text wave")
threadsafe Function RemoveTextWaveEntry1D(WAVE/T w, string entry, [variable options, variable all])
ASSERT_TS(IsTextWave(w), "Input wave must be a text wave")

variable start, foundOnce

Expand Down
34 changes: 34 additions & 0 deletions Packages/tests/Basic/UTF_Labnotebook.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1160,3 +1160,37 @@ Function GTW_WorksWithCustomDefault()
WAVE/T/Z result = GetUniqueEntries(values)
CHECK_EQUAL_TEXTWAVES(result, {"abcd"})
End

Function GFE_Works()

string device, key, keyTxt

device = "ABCD"

// handles null wave graciously
WAVE/Z null = LBV_GetFilledLabnotebookEntries($"")
CHECK_NO_RTE()
CHECK_WAVE(null, NULL_WAVE)

// no valid entries by default
WAVE numericalValues = GetLBNumericalValues(device)
CHECK_WAVE(numericalValues, NUMERIC_WAVE)

WAVE/Z null = LBV_GetFilledLabnotebookEntries(numericalValues)
CHECK_WAVE(null, NULL_WAVE)

WAVE textualValues = GetLBTextualValues(device)
CHECK_WAVE(textualValues, TEXT_WAVE)

WAVE/Z null = LBV_GetFilledLabnotebookEntries(textualValues)
CHECK_WAVE(null, NULL_WAVE)

// our fake LBNs have only valid entries
[key, keyTxt] = PrepareLBN_IGNORE(device)

WAVE/Z filled = LBV_GetFilledLabnotebookEntries(numericalValues)
CHECK_EQUAL_VAR(DimSize(filled, ROWS), DimSize(numericalValues, COLS))

WAVE/Z filled = LBV_GetFilledLabnotebookEntries(textualValues)
CHECK_EQUAL_VAR(DimSize(filled, ROWS), DimSize(textualValues, COLS))
End
10 changes: 8 additions & 2 deletions Packages/tests/UTF_HardwareHelperFunctions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,10 @@ static Function CheckForOtherUserLBNKeys(string device, variable type)
WAVE numericalKeys = GetLBNumericalKeys(device)
WAVE textualKeys = GetLBTextualKeys(device)

WAVE/Z entries = MIES_LBV#LBV_GetAllLogbookKeys(textualKeys, numericalKeys)
WAVE/Z numericalNames = MIES_LBV#LBV_GetLogbookParamNames(numericalKeys)
WAVE/Z textualNames = MIES_LBV#LBV_GetLogbookParamNames(textualKeys)

WAVE/Z entries = MIES_LBV#LBV_GetAllLogbookParamNames(textualNames, numericalNames)
CHECK_WAVE(entries, TEXT_WAVE)

// check that all user entries are from our analysis function
Expand Down Expand Up @@ -704,7 +707,10 @@ static Function CheckRangeOfUserLabnotebookKeys(string device, variable type, va
WAVE numericalKeys = GetLBNumericalKeys(device)
WAVE textualKeys = GetLBTextualKeys(device)

WAVE/Z entries = MIES_LBV#LBV_GetAllLogbookKeys(textualKeys, numericalKeys)
WAVE/Z numericalNames = MIES_LBV#LBV_GetLogbookParamNames(numericalKeys)
WAVE/Z textualNames = MIES_LBV#LBV_GetLogbookParamNames(textualKeys)

WAVE/Z entries = MIES_LBV#LBV_GetAllLogbookParamNames(textualNames, numericalNames)
CHECK_WAVE(entries, TEXT_WAVE)

WAVE/T/Z allUserEntries = GrepTextWave(entries, LABNOTEBOOK_USER_PREFIX + ".*")
Expand Down

0 comments on commit 5bb3ee1

Please sign in to comment.