Skip to content

Commit de89bbe

Browse files
author
hagan
committed
identified 55-4 issue
1 parent 675f317 commit de89bbe

File tree

9 files changed

+1407
-1271
lines changed

9 files changed

+1407
-1271
lines changed

R/methods.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ S7::method(create_calendar,ti) <- function(x){
3737
# before building the scaffold.
3838

3939

40-
41-
42-
4340
summary_dbi <- x@datum@data |>
4441
dplyr::ungroup() |>
4542
make_db_tbl() |>
@@ -83,17 +80,19 @@ S7::method(create_calendar,ti) <- function(x){
8380
# Create a single-column table of all possible dates in the range.
8481

8582
master_dates <- seq_date_sql(
86-
start_date = start_date,
87-
end_date = x@datum@max_date,
88-
time_unit = x@time_unit@value,
89-
.con = dbplyr::remote_con(x@datum@data)
83+
start_date = start_date,
84+
end_date = x@datum@max_date,
85+
calendar_type = x@datum@calendar_type,
86+
time_unit = x@time_unit@value,
87+
.con = dbplyr::remote_con(x@datum@data)
9088
)
9189

9290
# 5. Build the Scaffolding ------------------------------------------------
9391
# If groups exist, expand the calendar. We use an inner join to the bounds
9492
# to constrain the cross-join to only the "Active Life" of each group.
9593

9694
if (x@datum@group_indicator) {
95+
9796
calendar_dbi <- master_dates |>
9897
dplyr::cross_join(
9998
active_bounds |> dplyr::distinct(!!!x@datum@group_quo)

R/time_intelligence_fn.R

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,13 @@ yoy_fn <- function(x){
176176

177177

178178

179-
full_dbi <- create_full_dbi(x) |>
180-
dplyr::select(-c(year))
179+
full_dbi <- create_full_dbi(x)
180+
# dplyr::select(-c(year))
181181

182182
# create lag
183-
lag_dbi <- full_dbi |>
183+
lag_dbi <-
184+
full_dbi |>
185+
dplyr::select(-c(year)) |>
184186
dbplyr::window_order(date,!!!x@datum@group_quo) |>
185187
dplyr::mutate(
186188
date_lag=dplyr::lead(date,n = !!x@fn@lag_n)
@@ -192,18 +194,16 @@ yoy_fn <- function(x){
192194
dplyr::select(-c(date,!!x@value@value_quo,missing_date_indicator))
193195

194196
# bring tables together
195-
out_dbi <- dplyr::left_join(
197+
out_dbi <-
198+
dplyr::left_join(
196199
full_dbi
197200
,lag_dbi
198201
,by=dplyr::join_by(date==date_lag,!!!x@datum@group_quo)
199202
) |>
200-
dplyr::mutate(
201-
year=lubridate::year(date)
202-
,.after=date
203-
) |>
204203
dplyr::relocate(date,year) |>
205204
dplyr::relocate(dplyr::any_of("missing_date_indicator"),.after=dplyr::last_col())
206205

206+
207207
return(out_dbi)
208208

209209
}
@@ -429,11 +429,11 @@ qoq_fn <- function(x){
429429
# create calendar
430430
# full_dbi <- fpaR::create_calendar(x)
431431

432-
full_dbi <- create_full_dbi(x) |>
433-
dplyr::select(-c(year,quarter))
432+
full_dbi <- create_full_dbi(x)
434433

435434
# create lag
436435
lag_dbi <- full_dbi |>
436+
dplyr::select(-c(year,quarter)) |>
437437
dbplyr::window_order(date,!!!x@datum@group_quo) |>
438438
dplyr::mutate(
439439
date_lag=dplyr::lead(date,n = !!x@fn@lag_n)
@@ -448,10 +448,6 @@ qoq_fn <- function(x){
448448
,lag_dbi
449449
,by=dplyr::join_by(date==date_lag,!!!x@datum@group_quo)
450450
) |>
451-
dplyr::mutate(
452-
year=lubridate::year(date)
453-
,quarter=lubridate::quarter(date)
454-
) |>
455451
dplyr::relocate(date,year,quarter) |>
456452
dplyr::relocate(dplyr::any_of("missing_date_indicator"),.after=dplyr::last_col())
457453

@@ -680,14 +676,12 @@ mom_fn <- function(x){
680676

681677
# full_dbi <- create_calendar(x)
682678

683-
full_dbi <- create_full_dbi(x) |>
684-
dplyr::select(
685-
-c(year,month)
686-
)
679+
full_dbi <- create_full_dbi(x)
687680

688681

689682
# create lag
690683
lag_dbi <- full_dbi |>
684+
dplyr::select(-c(year,month)) |>
691685
dbplyr::window_order(date,!!!x@datum@group_quo) |>
692686
dplyr::mutate(
693687
date_lag=dplyr::lead(date,n = !!x@fn@lag_n)
@@ -706,11 +700,6 @@ mom_fn <- function(x){
706700
,lag_dbi
707701
,by=dplyr::join_by(date==date_lag,!!!x@datum@group_quo)
708702
) |>
709-
dplyr::mutate(
710-
year=lubridate::year(date)
711-
,month=lubridate::month(date)
712-
,.after=date
713-
) |>
714703
dplyr::relocate(date,year,month) |>
715704
dplyr::relocate(dplyr::any_of("missing_date_indicator"),.after=dplyr::last_col())
716705

@@ -952,12 +941,10 @@ wow_fn <- function(x){
952941

953942

954943

955-
full_dbi <- create_full_dbi(x) |>
956-
dplyr::select(
957-
-c(year,month,week)
958-
)
944+
full_dbi <- create_full_dbi(x)
959945

960946
lag_dbi <- full_dbi|>
947+
dplyr::select(-c(year,month,week)) |>
961948
dbplyr::window_order(date) |>
962949
dplyr::mutate(
963950
date_lag=dplyr::lead(date,n = !!x@fn@lag_n)
@@ -973,11 +960,6 @@ wow_fn <- function(x){
973960
,lag_dbi
974961
,by=dplyr::join_by(date==date_lag,!!!x@datum@group_quo)
975962
) |>
976-
dplyr::mutate(
977-
year=lubridate::year(date)
978-
,month=lubridate::month(date)
979-
,week=dplyr::sql("DATE_PART('week',date)")
980-
) |>
981963
dplyr::relocate(date,year,month,week) |>
982964
dplyr::relocate(dplyr::any_of("missing_date_indicator"),.after=dplyr::last_col())
983965

R/utils-misc.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ create_non_standard_month <- function(.data,pattern){
587587
complete_non_standard_calendar <- function(.data,x){
588588

589589

590+
# .data <- create_calendar(x)
591+
# complete_non_standard_calendar(x=x)
592+
590593
#test inputs
591594
# pattern <- "544"
592595

@@ -639,7 +642,8 @@ complete_non_standard_calendar <- function(.data,x){
639642
)
640643

641644

642-
out <- out |>
645+
out <-
646+
out |>
643647
dplyr::select(dplyr::any_of(new_cols))
644648

645649
return(out)
@@ -723,14 +727,16 @@ create_full_dbi <- function(x){
723727

724728
full_dbi <-
725729
create_calendar(x) |>
726-
complete_standard_calendar(x=x)
730+
731+
complete_standard_calendar(x=x)
727732

728733
}
729734

730735
if(x@datum@calendar_type!="standard"){
731736

732-
full_dbi <- create_calendar(x) |>
733-
complete_non_standard_calendar(x=x)
737+
full_dbi <- create_calendar(x)
738+
739+
734740
}
735741

736742
return(full_dbi)

0 commit comments

Comments
 (0)