Skip to content

period channelinfo function#122

Open
verenaaur wants to merge 2 commits intomainfrom
period_chinfo
Open

period channelinfo function#122
verenaaur wants to merge 2 commits intomainfrom
period_chinfo

Conversation

@verenaaur
Copy link

  • I added a 'period_channelinfo' function to the legend_data.jl file.
  • This function takes a period as an argument instead of a filekey.
  • It then creates a combined channelinfo of all runs in this period. It first merges all channelinfos, then creates arrays in each column for each detector (besides 'detector') with all entries from the different runs. These arrays are filtered in the next step: in columns with constant entries, only one entry remains. In columns with changing flags, e.g. "valid" or "present" in "low_aoe_status" the 'best' flag is chosen (implemented in the 'get_hierarchies' function).
  • kwargs and filters ( "|> filterby...") can be used as usual.

@verenaaur verenaaur requested a review from theHenks June 3, 2025 11:42
@verenaaur verenaaur added the enhancement New feature or request label Jun 3, 2025
@codecov
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

Attention: Patch coverage is 0% with 65 lines in your changes missing coverage. Please review.

Project coverage is 43.64%. Comparing base (42b0cdb) to head (37dd1a7).

Files with missing lines Patch % Lines
src/legend_data.jl 0.00% 65 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #122      +/-   ##
==========================================
- Coverage   44.95%   43.64%   -1.32%     
==========================================
  Files          27       27              
  Lines        2160     2225      +65     
==========================================
  Hits          971      971              
- Misses       1189     1254      +65     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@theHenks theHenks removed their assignment Jun 3, 2025
Copy link
Contributor

@theHenks theHenks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a first look, this looks good. However, I suggest the following:

  • Let's not introduce a new function named period_channelinfo. I highly recommend the dispatch on the existing function so that the argument is a PeriodSelLike.
  • All helper functions should start with a _ so that it is clear that they are not meant to be used outside of the module
  • Try to add types and comments to all arguments and function. Type safety and stability is important when this function will later be called very often.
  • A way to cache also this channelinfo with the help of the LRUCache should definitely be done
  • I think a lot of the code can be simplified and reduced by using more Tables and NamedTuple operations. I will try to help and support here once I had a look into the code in more details

make sure to include "Tables" by "using Tables" before using this function
"""

function period_channelinfo(data::LegendData, period::DataPeriod; kwargs...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is great as a first draft, however this should become a dispatch onto the existing channelinfo

Suggested change
function period_channelinfo(data::LegendData, period::DataPeriod; kwargs...)
function channelinfo(data::LegendData, sel::PeriodSelLike; kwargs...)

"""

function period_channelinfo(data::LegendData, period::DataPeriod; kwargs...)
filekey_array = get_filekey_array(data, period)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions all need comments; otherwise, this is not maintainable.

end

function get_filekey_array(l200, period)
rinfo = runinfo(l200, period) |> filterby(@pf $cal.is_analysis_run)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are actively filtering here by cal analysis runs. This is not a good idea. Usually, the category is given to load the channelinfo, e.g.

channelinfo(l200, :p03, :r000, :cal)

In the case where you load the channelinfo for a specific DataRun. This category should also be used in the case of a DataPeriod channelinfo, by allowing the DataCategory as an additional argument


function get_filekey_array(l200, period)
rinfo = runinfo(l200, period) |> filterby(@pf $cal.is_analysis_run)
return [i.cal.startkey for i in rinfo]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to

Suggested change
return [i.cal.startkey for i in rinfo]
rinfo.cal.startkey

return final_chinfo
end

function get_filekey_array(l200, period)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your function arguments need types.

return [channelinfo(l200, fk; kwargs...) for fk in filekey_array]
end

function merge_and_reduce_chinfo(merged_chinfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this function doing? This looks like it could be simplified a lot with standard Tables operations. In particular the pushing into empty Dict or Vector is not necessary here.

return red_chinfo
end

function sort_chinfo(red_chinfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you want to achieve with this function?
Can you not just do

sort(red_chinfo

Types are also missing.

return sorted_chinfo
end

function apply_hierarchies(sorted_chinfo, hierarchies, column_order)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types to the arguments

return final_chinfo
end

function get_hierarchies(extended::Bool)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the base_hierarchies are static and do not need to be changed?
In that case you can just make them a const

Suggested change
function get_hierarchies(extended::Bool)
const _base_hierarchies = Dict{Symbol, Vector{Union{Symbol, Bool}}}(
:usability => [:on, :ac, :off],
:is_blinded => [true, false],
:psd_usability => [:on, :off],
:low_aoe_status => [:valid, :present, :missing, :unknown],
:high_aoe_status => [:valid, :present, :missing, :unknown],
:lq_status => [:valid, :present, :missing, :unknown],
:ann_status => [:valid, :present, :missing, :unknown],
:coax_rt_status => [:valid, :present, :missing, :unknown]
)

return base_hierarchies
end

function get_column_order(extended::Bool)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this function doing and can you not move this to the outer function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of the columns was changed in the prior steps and I wanted to keep the original order (as in the usual channelinfo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants