Repository navigation
Add control parameters to analytics dashboard - #145
Conversation
| dplyr::filter( | ||
| # End date filter | ||
| if (!is.null(params$end_date) & | ||
| nzchar(params$end_date)) { # nolint |
There was a problem hiding this comment.
This was giving a circular lint and styler error.
jeancochrane
left a comment
There was a problem hiding this comment.
This is trending in the right direction, but some of the code is a bit confusing and I'm not sure if it's working as intended. Let's get the intended behavior sorted out and then we can iron out the details.
| ) | ||
| ), | ||
| if (is.null(params$refresh_today) || | ||
| isTRUE(params$refresh_today)) { # nolint |
There was a problem hiding this comment.
[Nitpick, required] Currently, this behavior makes it so that refresh_today controls whether we refresh the end date, regardless of whether that end date is the current day. Can we either adjust this behavior or change the name of the param? Regardless of what we choose, let's also make sure we add a comment above the param in the params section of the doc config so that the behavior is documented.
Our two options:
- Keep the current behavior and rename the param to
refresh_end_date - Keep the current param name and refactor the behavior to add an additional check such that we only apply the filter if the end date is today
I don't feel strongly about which approach to choose, so I leave it up to you!
There was a problem hiding this comment.
I have it so that it only uses the feature if the date is today's date, so that should help fix this behavior.
| # Start date filter | ||
| if (!is.null(params$start_date) & | ||
| nzchar(params$start_date)) { # nolint | ||
| date >= as.Date(params$start_date) | ||
| } else { | ||
| TRUE | ||
| }, | ||
|
|
||
| # Excluded dates filter | ||
| if (!is.null(params$excluded_dates) & | ||
| length(params$excluded_dates) > 0) { # nolint | ||
| !(date %in% as.Date(params$excluded_dates)) | ||
| } else { | ||
| TRUE | ||
| } |
There was a problem hiding this comment.
[Suggestion, optional] It strikes me that we're adding a lot of extra logic to this filter() call to account for the possibility that these parameters are missing/empty, when the convert_params block has already defined fallback values for the missing/empty case. Why not update the convert_params block to process excluded_dates, have emtpy_dates fall back to an empty vector, and then simplify this filter so that it incorporates the fallback values? Then the filter would look something like:
filter(
date >= start_date,
date <= end_date,
!(date %in% excluded_dates)
)There was a problem hiding this comment.
yup, I moved all the factoring up the the start to make everything work together. Good suggestion.
| setdiff( | ||
| all_dates[ | ||
| (all_dates != end_date) | | ||
| (is.null(params$refresh_today) || isTRUE(params$refresh_today)) |
There was a problem hiding this comment.
[Question, blocking] Am I right that this filter is duplicative with the logic on line 184? It seems to lead to duplicate end dates when I test it. Here's start_date == "2025-09-04" end_date == "2025-09-10" and refresh_today is null, note the two instances of 2025-09-10:
> dates_to_fetch
[1] "2025-09-04" "2025-09-05" "2025-09-06" "2025-09-07" "2025-09-08" "2025-09-09" "2025-09-10" "2025-09-10"| message("Target file: ", fs::path_abs(out_file)) | ||
|
|
||
| if (fs::file_exists(out_file) && d != today_local) { | ||
| if (fs::file_exists(out_file) & d != end_date) { |
There was a problem hiding this comment.
[Question, blocking] I'm finding it a bit confusing to wrap my head around how the filters in dates_to_fetch interact with this end_date filter. As far as I can tell, here's how it's currently working:
dates_to_fetchwill only includeend_dateifrefresh_todayis null or true- If
end_dateis present indates_to_fetch, it will always get refreshed, regardless of whether it is cached
Am I understanding the logic correctly? If so, I have two concerns about it:
- If
end_dateis not already in the logfile cache andrefresh_todayis false, we will not query data forend_date.- Perhaps this is intentional -- I could see an argument that it would be more intuitive for
refresh_todayto prevent us from querying data forend_dateif it doesn't exist -- but it feels like an extension of the parameter's behavior outside the scope that I was imagining for it. I was expecting us to userefresh_today == falseto fall back to cached data for the current date if we already have it, but if we don't have that cached data in the first place, then I don't think it makes sense forrefresh_todayto skip it.
- Perhaps this is intentional -- I could see an argument that it would be more intuitive for
dates_to_fetchdoes not fully own the logic for determining which dates of logs to fetch, and if a code maintainer wants to alter the way it is defined, they have to remember that there is an interaction withend_datedefined down here in the fetching logic itself.
I think there are a couple of ways we could resolve concern 2 to make the code easier to maintain, but the approach we choose will depend on the direction we want to take with the behavior described in concern 1. What do you think?
Co-authored-by: Jean Cochrane <jeancochrane@users.noreply.github.com>
Co-authored-by: Jean Cochrane <jeancochrane@users.noreply.github.com>
Co-authored-by: Jean Cochrane <jeancochrane@users.noreply.github.com>
|
Thanks for the feedback. There is still the nolint included in the file, but I think cleaning the params up the script improves and simplified it a lot. I moved the refresh_today, to not query the cached data for today if the param does not equal false. That means that NULL TRUE or a random string should still query it. |
|
Something weird popped up, let me take a look. |
| message("Target file: ", fs::path_abs(out_file)) | ||
|
|
||
| if (fs::file_exists(out_file) && d != today_local) { | ||
| message("Skipping ", format(d), " (already cached).") |
There was a problem hiding this comment.
This doesn't seem necessary.
This adds 5 params to the homeval report to help produce more refined queries.
They are implemented both in the initial download and caching stage as well as the report.
There is also a lintr styler circular error again which I just added #nolint to.