-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
170 lines (132 loc) · 4.71 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# pf
<!-- badges: start -->
<!-- badges: end -->
The goal of pf_app is to provide tools for working with ProjectFacts data and easy reporting of the data.
## Installation
You can install `pf` with `remotes` via
``` r
remotes::install_github("CTU-Bern/pf")
```
Once it's installed, it can be updated via
``` r
pf::update_pf()
```
## Example
```{r example}
library(pf)
```
The following code is used to update the data on the R drive.
```{r updateR, eval = FALSE}
# load the data from R
all_tabs <- getPFData()
# download data via ODBC
all_tabs <- getPFData(NULL)
all_tabs$customer <- decodeCustomFields(all_tabs$customer, all_tabs$customfields)
all_tabs$project <- decodeCustomFields(all_tabs$project, all_tabs$customfields)
all_tabs$ticket <- decodeCustomFields(all_tabs$ticket, all_tabs$customfields)
all_tabs$worker <- decodeCustomFields(all_tabs$worker, all_tabs$customfields)
# save the data to R
savePFdata(all_tabs)
```
Regular usage would be e.g.:
```{r load, eval = FALSE}
# load the data from R
all_tabs2 <- getPFData()
dat <- prepTime(all_tabs2)
```
Hours spent by DM for set up and STA for analysis:
```{r dm_sta, eval = FALSE}
library(tidyverse)
d <- dat %>%
dplyr::mutate(
tokeep = stringr::str_detect(.$finart_Name, "Database [Ss]et-up|Data [Aa]nalysis|Statist") |
stringr::str_detect(.$finart_Name1, "Stat")) %>%
dplyr::select(ctu_projectName, starts_with("finart"), starts_with("ProjectName"), tokeep) |> #View()
dplyr::filter(tokeep) %>%
dplyr::mutate(div = stringr::word(finart_Name, end = 2),
div = stringr::str_to_sentence(div),
div = case_when(div == "Regular reports" ~ "Data analysis",
div == "Study planning" ~ "Data analysis",
TRUE ~ div)) %>%
dplyr::group_by(ctu_projectName, div) %>%
dplyr::summarize(billable_time = sum(billable_time),
nonbillable_time = sum(nonbillable_time)) %>%
dplyr::mutate(billable_time = billable_time/60,
nonbillable_time = nonbillable_time/60)
writexl::write_xlsx(d, "../DBsetup_STA_time_may2022.xlsx")
d %>%
ggplot(aes(x = billable_time)) +
geom_histogram() +
facet_wrap(~div)
```
#### Monthly billable time at CTU and division level
```{r}
library(lubridate)
monthly_billable_div <- dat |>
mutate(month = month(BookedDate)) |>
group_by(ctu_division, year, month) |>
filter(billable == "Billable") |>
filter(!str_detect(CaseId, "^I")) |>
summarize(Timespent_billable = sum(Timespent_billable)) |> #View()
mutate(year_month = ym(paste0(year, "-", month)),
hours = Timespent_billable/60) |>
filter(year > 2020)
monthly_billable_ctu <- monthly_billable_div |>
filter(ctu_division != "CI") |>
group_by(year, month) |>
summarize(Timespent_billable = sum(Timespent_billable)) |> #View()
mutate(year_month = ym(paste0(year, "-", month)),
hours = Timespent_billable/60)
ggplot(monthly_billable_div,
aes(x = year_month,
y = hours,
col = ctu_division)) +
geom_line() +
labs(x = "Month",
y = "Billable hours",
col = "Division")
writexl::write_xlsx(list(divisions = monthly_billable_div, ctu = monthly_billable_ctu), paste0("Monthly_billable_", Sys.Date(), ".xlsx"))
```
### Reports
#### CTU quarterly report
```{r, eval = FALSE}
rmarkdown::render(input = "R:/Projectfacts/ODBC/pf_app/vignettes/quarterly.Rmd",
output_file=file.path('R:/Projectfacts/ODBC/reports',
paste0("CTUQuarterly_",
Sys.Date(),
".html")))
```
### Miscellaneous other things
#### Email addresses of project contacts
```{r, eval = FALSE}
library(tidyverse)
View(all_tabs$project)
View(all_tabs$contactfield)
tmp <- all_tabs$project %>%
filter(!is.na(FK_CUSTOMERCONTACT)) %>%
left_join(all_tabs$crmkontakt,
by = c("FK_CUSTOMERCONTACT" = "PK_CRMKONTAKT")) %>%
left_join(all_tabs$customer %>%
select(PK_CUSTOMER, Path) %>%
rename(customer_name = Path),
by = c("FK_CUSTOMER.x" = "PK_CUSTOMER")) %>%
left_join(all_tabs$contactfield %>%
filter(TYPE == 30),
by = c("FK_CUSTOMERCONTACT" = "FK_CONTACT")) %>%
select(Vorname, Nachname, VALUE, customer_name) %>%
rename(Email = VALUE) %>%
distinct(Vorname, Nachname, Email, .keep_all = TRUE)
writexl::write_xlsx(tmp, "../reports/emailaddresses.xlsx")
```