@@ -8,7 +8,6 @@ create_calendar <- S7::new_generic("create_calendar","x")
88calculate <- S7 :: new_generic(" calculate" ," x" )
99
1010
11- complete_calendar <- S7 :: new_generic(" complete_calendar" ," x" )
1211
1312
1413# ' Create Calendar Table
@@ -39,7 +38,7 @@ S7::method(create_calendar,ti) <- function(x){
3938
4039 start_date <- closest_sunday_feb1(min_year )
4140
42- if (min_year < start_date ){
41+ if (min_year < lubridate :: year( start_date ) ){
4342
4443 start_date <- closest_sunday_feb1(min_year - 1 )
4544
@@ -99,6 +98,9 @@ S7::method(create_calendar,ti) <- function(x){
9998 ,!! x @ value @ value_vec : = dplyr :: coalesce(!! x @ value @ value_quo , 0 )
10099 )
101100
101+
102+
103+
102104 return (full_dbi )
103105}
104106
@@ -167,55 +169,6 @@ S7::method(calculate,segment_abc) <- function(x){
167169}
168170
169171
170- # ' @title complete_calendar
171- # ' @name complete_calendar
172- # ' @param x ti object
173- # ' @returns dbi object
174- # ' @keywords internal
175- S7 :: method(complete_calendar ,ti ) <- function (x ){
176-
177-
178- calendar_dbi <- x @ datum @ data | >
179- dplyr :: count(!! x @ datum @ date_quo ) | >
180- dplyr :: select(- n )
181-
182-
183- date_vec <- x @ datum @ date_vec
184-
185- out <- calendar_dbi | >
186- dplyr :: mutate(
187- year_start_date = lubridate :: floor_date(!! x @ datum @ date_quo ,unit = " year" )
188- ,year_end_date = dplyr :: sql(glue :: glue(" date_trunc('year', {date_vec}) + INTERVAL '1' YEAR" ))
189- ,quarter_start_date = lubridate :: floor_date(!! x @ datum @ date_quo ,unit = " quarter" )
190- ,quarter_end_date = dplyr :: sql(glue :: glue(" date_trunc('quarter', {date_vec}) + INTERVAL '1' quarter" ))
191- ,month_start_date = lubridate :: floor_date(!! x @ datum @ date_quo ,unit = " month" )
192- ,month_end_date = dplyr :: sql(glue :: glue(" date_trunc('month', {date_vec}) + INTERVAL '1' month" ))
193- ,week_start_date = lubridate :: floor_date(!! x @ datum @ date_quo ,unit = " week" )
194- ,week_end_date = dplyr :: sql(glue :: glue(" date_trunc('month', {date_vec}) + INTERVAL '1' month" ))
195- ,day_of_week = lubridate :: wday(!! x @ datum @ date_quo ,label = FALSE )
196- ,day_of_week_label = lubridate :: wday(!! x @ datum @ date_quo ,label = TRUE )
197- ,days_in_year = year_end_date - year_start_date
198- ,days_in_quarter = quarter_end_date - quarter_start_date
199- ,days_in_month = dplyr :: sql(glue :: glue(" last_day({date_vec})" ))
200- ,days_complete_in_week = !! x @ datum @ date_quo - week_start_date
201- ,days_remaining_in_week = week_end_date - !! x @ datum @ date_quo
202- ,days_remaining_in_quarter = quarter_end_date - !! x @ datum @ date_quo
203- ,days_remaining_in_month = month_end_date - !! x @ datum @ date_quo
204- ,days_remaining_in_year = year_end_date - !! x @ datum @ date_quo
205- ,days_complete_in_year = !! x @ datum @ date_quo - year_start_date
206- ,days_complete_in_quarter = !! x @ datum @ date_quo - quarter_start_date
207- ,days_complete_in_month = !! x @ datum @ date_quo - month_start_date
208- ,days_complete_in_year = !! x @ datum @ date_quo - year_start_date
209- ,weekend_indicator = dplyr :: if_else(day_of_week_label %in% c(" Saturday" ," Sunday" ),1 ,0 )
210- ) | >
211- dplyr :: mutate(
212- dplyr :: across(dplyr :: contains(" date" ),\(x ) as.Date(x ))
213- )
214-
215- return (out )
216-
217- }
218-
219172
220173
221174# ' @title Print ti objects
@@ -418,3 +371,55 @@ S7::method(print,segment_cohort) <- function(x,...){
418371 print_next_steps()
419372
420373}
374+
375+
376+
377+ # complete_calendar <- S7::new_generic("complete_calendar","x")
378+
379+
380+
381+ # S7::method(complete_calendar,ti) <- function(x){
382+ #
383+ #
384+ # calendar_dbi<- x@datum@data |>
385+ # dplyr::count(!!x@datum@date_quo) |>
386+ # dplyr::select(-n)
387+ #
388+ #
389+ # date_vec <- x@datum@date_vec
390+ #
391+ # out <- calendar_dbi |>
392+ # dplyr::mutate(
393+ # year_start_date=lubridate::floor_date(!!x@datum@date_quo,unit = "year")
394+ # ,year_end_date=dplyr::sql(glue::glue("date_trunc('year', {date_vec}) + INTERVAL '1' YEAR"))
395+ # ,quarter_start_date=lubridate::floor_date(!!x@datum@date_quo,unit = "quarter")
396+ # ,quarter_end_date=dplyr::sql(glue::glue("date_trunc('quarter', {date_vec}) + INTERVAL '1' quarter"))
397+ # ,month_start_date=lubridate::floor_date(!!x@datum@date_quo,unit = "month")
398+ # ,month_end_date=dplyr::sql(glue::glue("date_trunc('month', {date_vec}) + INTERVAL '1' month"))
399+ # ,week_start_date=lubridate::floor_date(!!x@datum@date_quo,unit = "week")
400+ # ,week_end_date=dplyr::sql(glue::glue("date_trunc('month', {date_vec}) + INTERVAL '1' month"))
401+ # ,day_of_week=lubridate::wday(!!x@datum@date_quo,label = FALSE)
402+ # ,day_of_week_label=lubridate::wday(!!x@datum@date_quo,label = TRUE)
403+ # ,days_in_year=year_end_date-year_start_date
404+ # ,days_in_quarter=quarter_end_date-quarter_start_date
405+ # ,days_in_month=dplyr::sql(glue::glue("last_day({date_vec})"))
406+ # ,days_complete_in_week=!!x@datum@date_quo-week_start_date
407+ # ,days_remaining_in_week=week_end_date-!!x@datum@date_quo
408+ # ,days_remaining_in_quarter=quarter_end_date-!!x@datum@date_quo
409+ # ,days_remaining_in_month=month_end_date-!!x@datum@date_quo
410+ # ,days_remaining_in_year=year_end_date-!!x@datum@date_quo
411+ # ,days_complete_in_year=!!x@datum@date_quo-year_start_date
412+ # ,days_complete_in_quarter=!!x@datum@date_quo-quarter_start_date
413+ # ,days_complete_in_month=!!x@datum@date_quo-month_start_date
414+ # ,days_complete_in_year=!!x@datum@date_quo-year_start_date
415+ # ,weekend_indicator=dplyr::if_else(day_of_week_label %in% c("Saturday","Sunday"),1,0)
416+ # ) |>
417+ # dplyr::mutate(
418+ # dplyr::across(dplyr::contains("date"),\(x) as.Date(x))
419+ # )
420+ #
421+ # return(out)
422+ #
423+ # }
424+
425+
0 commit comments