@@ -419,7 +419,6 @@ augment_standard_calendar <- function(.data,.date){
419419
420420 out <- augment_standard_calendar_dbi(.data = .data ,.date = .date_var )
421421
422- return (out )
423422
424423 }
425424
@@ -428,9 +427,11 @@ augment_standard_calendar <- function(.data,.date){
428427
429428 out <- augment_standard_calendar_tbl(.data = .data ,.date = !! .date_var )
430429
431- return (out )
432430 }
433431
432+
433+
434+
434435}
435436
436437
@@ -465,7 +466,7 @@ closest_sunday_feb1 <- function(year) {
465466# ' @returns DBI object
466467# '
467468# ' @keywords internal
468- create_ns_month <- function (.data ,pattern ){
469+ create_non_standard_month <- function (.data ,pattern ){
469470
470471
471472 valid_colnames <- c(" week_ns" ," year_ns" )
@@ -491,21 +492,21 @@ create_ns_month <- function(.data,pattern){
491492 out <-
492493 .data | >
493494 dplyr :: mutate(
494- .by = year_ns
495- ,month_ns = dplyr :: case_when(
495+ .by = year
496+ ,month = dplyr :: case_when(
496497 # either framing it in advance or somehow passing a arg to it
497- week_ns < = !! valid_cumulative_months [[1 ]]~ 1
498- ,week_ns < = !! valid_cumulative_months [[2 ]]~ 2
499- ,week_ns < = !! valid_cumulative_months [[3 ]]~ 3
500- ,week_ns < = !! valid_cumulative_months [[4 ]]~ 4
501- ,week_ns < = !! valid_cumulative_months [[5 ]]~ 5
502- ,week_ns < = !! valid_cumulative_months [[6 ]]~ 6
503- ,week_ns < = !! valid_cumulative_months [[7 ]]~ 7
504- ,week_ns < = !! valid_cumulative_months [[8 ]]~ 8
505- ,week_ns < = !! valid_cumulative_months [[9 ]]~ 9
506- ,week_ns < = !! valid_cumulative_months [[10 ]]~ 10
507- ,week_ns < = !! valid_cumulative_months [[11 ]]~ 11
508- ,week_ns < = !! valid_cumulative_months [[12 ]]~ 12
498+ week < = !! valid_cumulative_months [[1 ]]~ 1
499+ ,week < = !! valid_cumulative_months [[2 ]]~ 2
500+ ,week < = !! valid_cumulative_months [[3 ]]~ 3
501+ ,week < = !! valid_cumulative_months [[4 ]]~ 4
502+ ,week < = !! valid_cumulative_months [[5 ]]~ 5
503+ ,week < = !! valid_cumulative_months [[6 ]]~ 6
504+ ,week < = !! valid_cumulative_months [[7 ]]~ 7
505+ ,week < = !! valid_cumulative_months [[8 ]]~ 8
506+ ,week < = !! valid_cumulative_months [[9 ]]~ 9
507+ ,week < = !! valid_cumulative_months [[10 ]]~ 10
508+ ,week < = !! valid_cumulative_months [[11 ]]~ 11
509+ ,week < = !! valid_cumulative_months [[12 ]]~ 12
509510 ,.default = 13
510511 )
511512 )
@@ -517,21 +518,21 @@ create_ns_month <- function(.data,pattern){
517518
518519 out <- .data | >
519520 dplyr :: mutate(
520- .by = year_ns
521- ,month_ns = dplyr :: case_when(
521+ .by = year
522+ ,month = dplyr :: case_when(
522523 # either framing it in advance or somehow passing a arg to it
523- week_ns < = !! valid_cumulative_months [[1 ]]~ 1
524- ,week_ns < = !! valid_cumulative_months [[2 ]]~ 2
525- ,week_ns < = !! valid_cumulative_months [[3 ]]~ 3
526- ,week_ns < = !! valid_cumulative_months [[4 ]]~ 4
527- ,week_ns < = !! valid_cumulative_months [[5 ]]~ 5
528- ,week_ns < = !! valid_cumulative_months [[6 ]]~ 6
529- ,week_ns < = !! valid_cumulative_months [[7 ]]~ 7
530- ,week_ns < = !! valid_cumulative_months [[8 ]]~ 8
531- ,week_ns < = !! valid_cumulative_months [[9 ]]~ 9
532- ,week_ns < = !! valid_cumulative_months [[10 ]]~ 10
533- ,week_ns < = !! valid_cumulative_months [[11 ]]~ 11
534- ,week_ns < = !! valid_cumulative_months [[12 ]]~ 12
524+ week < = !! valid_cumulative_months [[1 ]]~ 1
525+ ,week < = !! valid_cumulative_months [[2 ]]~ 2
526+ ,week < = !! valid_cumulative_months [[3 ]]~ 3
527+ ,week < = !! valid_cumulative_months [[4 ]]~ 4
528+ ,week < = !! valid_cumulative_months [[5 ]]~ 5
529+ ,week < = !! valid_cumulative_months [[6 ]]~ 6
530+ ,week < = !! valid_cumulative_months [[7 ]]~ 7
531+ ,week < = !! valid_cumulative_months [[8 ]]~ 8
532+ ,week < = !! valid_cumulative_months [[9 ]]~ 9
533+ ,week < = !! valid_cumulative_months [[10 ]]~ 10
534+ ,week < = !! valid_cumulative_months [[11 ]]~ 11
535+ ,week < = !! valid_cumulative_months [[12 ]]~ 12
535536 ,.default = 13
536537 )
537538 )
@@ -544,21 +545,21 @@ create_ns_month <- function(.data,pattern){
544545
545546 out <- .data | >
546547 dplyr :: mutate(
547- .by = year_ns
548- ,month_ns = dplyr :: case_when(
548+ .by = year
549+ ,month = dplyr :: case_when(
549550 # either framing it in advance or somehow passing a arg to it
550- week_ns < = !! valid_cumulative_months [[1 ]]~ 1
551- ,week_ns < = !! valid_cumulative_months [[2 ]]~ 2
552- ,week_ns < = !! valid_cumulative_months [[3 ]]~ 3
553- ,week_ns < = !! valid_cumulative_months [[4 ]]~ 4
554- ,week_ns < = !! valid_cumulative_months [[5 ]]~ 5
555- ,week_ns < = !! valid_cumulative_months [[6 ]]~ 6
556- ,week_ns < = !! valid_cumulative_months [[7 ]]~ 7
557- ,week_ns < = !! valid_cumulative_months [[8 ]]~ 8
558- ,week_ns < = !! valid_cumulative_months [[9 ]]~ 9
559- ,week_ns < = !! valid_cumulative_months [[10 ]]~ 10
560- ,week_ns < = !! valid_cumulative_months [[11 ]]~ 11
561- ,week_ns < = !! valid_cumulative_months [[12 ]]~ 12
551+ week < = !! valid_cumulative_months [[1 ]]~ 1
552+ ,week < = !! valid_cumulative_months [[2 ]]~ 2
553+ ,week < = !! valid_cumulative_months [[3 ]]~ 3
554+ ,week < = !! valid_cumulative_months [[4 ]]~ 4
555+ ,week < = !! valid_cumulative_months [[5 ]]~ 5
556+ ,week < = !! valid_cumulative_months [[6 ]]~ 6
557+ ,week < = !! valid_cumulative_months [[7 ]]~ 7
558+ ,week < = !! valid_cumulative_months [[8 ]]~ 8
559+ ,week < = !! valid_cumulative_months [[9 ]]~ 9
560+ ,week < = !! valid_cumulative_months [[10 ]]~ 10
561+ ,week < = !! valid_cumulative_months [[11 ]]~ 11
562+ ,week < = !! valid_cumulative_months [[12 ]]~ 12
562563 ,.default = 13
563564 )
564565 )
@@ -572,6 +573,64 @@ create_ns_month <- function(.data,pattern){
572573
573574
574575
576+ # ' Augment non-standard calendar
577+ # '
578+ # ' @param .data data
579+ # ' @param pattern 554,445 or 545
580+ # '
581+ # ' @returns DBI object
582+ # '
583+ augment_non_standard_calendar <- function (.data ,pattern ){
584+
585+ # test inputs
586+ # pattern <- "544"
587+
588+ # assign variables
589+ days_in_week = 7
590+ weeks_in_quarter = 13
591+ quarters_in_year = 4
592+ # start_year <- closest_sunday_feb1(min_year)
593+
594+
595+ #
596+ # new_cal <- seq_date_sql(start_date = start_year,end_date=x@datum@max_date,time_unit = "day",con =con ) |>
597+ # augment_standard_calendar(.date = date) |>
598+ # dplyr::select(date,day_of_week)
599+
600+ out <-
601+ .data | >
602+ dbplyr :: window_order(date ) | >
603+ dplyr :: mutate(
604+ year_index = dplyr :: if_else(dplyr :: row_number()%% (days_in_week * weeks_in_quarter * quarters_in_year )== 1 ,1 ,0 )
605+ ,year = cumsum(year_index )
606+ ) | >
607+ dplyr :: mutate(
608+ week_index = dplyr :: if_else(dplyr :: row_number()%% 7 == 1 ,1 ,0 )
609+ ,week = cumsum(week_index )
610+ ,.by = year
611+ ) | >
612+ create_non_standard_month(pattern = pattern ) | >
613+ dplyr :: mutate(
614+ quarter = dplyr :: case_when(
615+ month < = 3 ~ 1
616+ ,month < = 6 ~ 2
617+ ,month < = 9 ~ 3
618+ ,.default = 4
619+ )
620+ ) | >
621+ dplyr :: mutate(
622+ day = lubridate :: day(date )
623+ ) | >
624+ dplyr :: select(
625+ date ,day ,week ,month ,quarter ,year
626+ )
627+
628+ return (out )
629+
630+ }
631+
632+
633+
575634utils :: globalVariables(
576635 c(
577636 " desc" ,
0 commit comments