Skip to content

Commit 4f0a8ed

Browse files
committed
final fixes to not do team-based stuff if not grouping by teams.
1 parent 2767ade commit 4f0a8ed

File tree

3 files changed

+90
-47
lines changed

3 files changed

+90
-47
lines changed

inst/downloads.Rmd

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,20 @@ queryData <- res %>%
107107
### Web access usage statistics from `r min(monthBreaksDf$beginTime)` to `r max(monthBreaksDf$endTime)`.
108108

109109
```{r users}
110-
# Get users at project level
111-
aclUserList <- aclToUserList(paste0("syn", projectId))
112-
aclUserList$teamId <- factor(aclUserList$teamId,
113-
levels=aclTeamOrder,
114-
ordered=TRUE)
115-
116-
aclUserList <- aclUserList %>%
117-
group_by(userId) %>%
118-
arrange(teamId) %>%
119-
slice(1) %>%
120-
ungroup()
121-
110+
if (useTeamGrouping) {
111+
112+
# Get users at project level
113+
aclUserList <- aclToUserList(paste0("syn", projectId))
114+
aclUserList$teamId <- factor(aclUserList$teamId,
115+
levels=aclTeamOrder,
116+
ordered=TRUE)
117+
118+
aclUserList <- aclUserList %>%
119+
group_by(userId) %>%
120+
arrange(teamId) %>%
121+
slice(1) %>%
122+
ungroup()
123+
}
122124
```
123125

124126
```{r summaryuseraccess}
@@ -131,14 +133,20 @@ allUsersList <- ldply(accessUsers$children, as.data.frame) %>%
131133
mutate(userId=ownerId) %>%
132134
select(userId, userName)
133135
134-
allUsers <- left_join(allUsersList, aclUserList)
136+
if (useTeamGrouping) {
137+
allUsers <- left_join(allUsersList, aclUserList)
138+
} else{
139+
allUsers <- allUsersList
140+
allUsers$teamId <- "None"
141+
}
142+
135143
levels(allUsers$teamId) <- c(levels(allUsers$teamId), "None")
136144
allUsers$teamId[is.na(allUsers$teamId)] <- "None"
137145
138146
allUsers$group <- "Other"
139147
allUsers$teamName <- "None"
140148
141-
teamInfo <- ddply(allUsers %>% allUsers %>%
149+
teamInfo <- ddply(allUsers %>%
142150
filter(teamId != "None",
143151
!startsWith(as.character(allUsers$teamId),
144152
"syn")) %>%

inst/shiny-apps/UsageStats/app.R

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,25 @@ synapseLogin()
1919
checkForProject <- function(projectId) {
2020
length(synQuery(sprintf('select id from project where projectId=="syn%s" LIMIT 1', projectId))) == 1
2121
}
22-
renderMyDocument <- function(reportType, projectId, nMonths, aclTeamOrder, outputFile) {
22+
renderMyDocument <- function(reportType, projectId, nMonths, aclTeamOrder, useTeamGrouping, outputFile) {
2323
res <- rmarkdown::render(input=paste0("../../", reportType, ".Rmd"),
2424
output_file=outputFile,
25-
params = list(projectId=projectId, nMonths=nMonths, aclTeamOrder=aclTeamOrder))
25+
params = list(projectId=projectId, nMonths=nMonths,
26+
aclTeamOrder=aclTeamOrder,
27+
useTeamGrouping=useTeamGrouping))
2628
}
2729

2830
# Define UI for application that draws a histogram
2931
ui <- shinyUI(fluidPage(
3032

33+
tags$head(
34+
tags$style(HTML("
35+
.shiny-output-error-validation {
36+
color: red;
37+
}
38+
"))
39+
),
40+
3141
# Application title
3242
titlePanel("Synapse Project Usage"),
3343

@@ -40,6 +50,7 @@ ui <- shinyUI(fluidPage(
4050
uiOutput('teamList'),
4151
selectInput('reportType', "Report Type:", choices=c("webAccess", "downloads"),
4252
selected="downloads"),
53+
checkboxInput('useTeamGrouping', 'Group by teams', value=FALSE),
4354
sliderInput("months", "Months", min=1, max=12, value=2, step=1),
4455
actionButton('report', "Make Report")
4556
),
@@ -58,6 +69,7 @@ ui <- shinyUI(fluidPage(
5869
p("Then, click the 'Make Report' button, A 'Download' button will appear when the report has been generated."),
5970
br(),
6071
p("A PDF of this report can be generated in most browsers by printing the HTML to a PDF file."),
72+
hr(),
6173
uiOutput("results")
6274
)
6375
)
@@ -69,6 +81,11 @@ server <- shinyServer(function(input, output) {
6981
myVals <- reactiveValues()
7082

7183
teamACL <- eventReactive(input$lookup, {
84+
validate(
85+
need(try(checkForProject(isolate(input$projectId))),
86+
"That project doesn't exist. Please try again.")
87+
)
88+
7289
acl <- synGetEntityACL(paste0("syn", input$projectId))
7390
aclToMemberList(acl) %>%
7491
filter(userName != "PUBLIC", !isIndividual)
@@ -87,18 +104,26 @@ server <- shinyServer(function(input, output) {
87104
res <- eventReactive(input$report, {
88105
print("Making Report")
89106
withProgress(message = 'Making report', value = 0, {
90-
91-
validate(
107+
108+
validate(
92109
need(try(checkForProject(input$projectId)),
93110
"That project doesn't exist. Please try again.")
94-
)
95-
111+
)
112+
113+
if (input$useTeamGrouping) {
114+
validate(
115+
need(try(input$teamOrder != ""),
116+
"Please select a Team ordering before generating a report.")
117+
)
118+
}
119+
96120
myVals[['reportName']] <- 'myreport.html'
97121

98122
renderMyDocument(reportType=input$reportType,
99123
projectId = input$projectId,
100124
nMonths=input$months,
101125
aclTeamOrder = input$teamOrder,
126+
useTeamGrouping=input$useTeamGrouping,
102127
#outputFile=paste0(as.numeric(as.POSIXct(Sys.Date())), "_", reportType, ".html"),
103128
outputFile='myreport.html')
104129
})
@@ -120,7 +145,7 @@ server <- shinyServer(function(input, output) {
120145

121146
output$results <- renderUI({
122147
report <- res()
123-
downloadButton('download')
148+
list(h3("Results"), downloadButton('download'))
124149
})
125150
})
126151

inst/webAccess.Rmd

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,19 @@ queryData <- res %>%
108108
### Web access usage statistics from `r min(monthBreaksDf$beginTime)` to `r max(monthBreaksDf$endTime)`.
109109

110110
```{r users}
111-
# Get users at project level
112-
aclUserList <- aclToUserList(paste0("syn", projectId))
113-
aclUserList$teamId <- factor(aclUserList$teamId,
114-
levels=aclTeamOrder,
115-
ordered=TRUE)
116-
117-
aclUserList <- aclUserList %>%
118-
group_by(userId) %>%
119-
arrange(teamId) %>%
120-
slice(1) %>%
121-
ungroup()
122-
111+
if (useTeamGrouping) {
112+
# Get users at project level
113+
aclUserList <- aclToUserList(paste0("syn", projectId))
114+
aclUserList$teamId <- factor(aclUserList$teamId,
115+
levels=aclTeamOrder,
116+
ordered=TRUE)
117+
118+
aclUserList <- aclUserList %>%
119+
group_by(userId) %>%
120+
arrange(teamId) %>%
121+
slice(1) %>%
122+
ungroup()
123+
}
123124
```
124125

125126
```{r summaryuseraccess}
@@ -132,29 +133,38 @@ allUsersList <- ldply(accessUsers$children, as.data.frame) %>%
132133
mutate(userId=ownerId) %>%
133134
select(userId, userName)
134135
135-
allUsers <- left_join(allUsersList, aclUserList)
136+
if (useTeamGrouping) {
137+
allUsers <- left_join(allUsersList, aclUserList)
138+
} else{
139+
allUsers <- allUsersList
140+
allUsers$teamId <- "None"
141+
}
142+
136143
levels(allUsers$teamId) <- c(levels(allUsers$teamId), "None")
137144
allUsers$teamId[is.na(allUsers$teamId)] <- "None"
138145
139146
allUsers$group <- "Other"
140147
allUsers$teamName <- "None"
141148
142-
143-
teamInfo <- ddply(allUsers %>% filter(teamId != "None",
144-
!startsWith(as.character(allUsers$teamId),
145-
"syn")) %>%
146-
select(teamId) %>% unique(),
147-
.(teamId),
148-
function(x) {
149-
tmp <- synRestGET(sprintf("/team/%s", x$teamId));
150-
data.frame(teamId=x$teamId, teamName=tmp$name)
149+
if (useTeamGrouping) {
150+
teamInfo <- ddply(allUsers %>%
151+
filter(teamId != "None",
152+
!startsWith(as.character(allUsers$teamId),
153+
"syn")) %>%
154+
select(teamId) %>% unique(),
155+
.(teamId),
156+
function(x) {
157+
tmp <- synRestGET(sprintf("/team/%s", x$teamId));
158+
data.frame(teamId=x$teamId, teamName=tmp$name)
151159
}
152-
)
153-
154-
155-
allUsers <- left_join(allUsers, teamInfo, by="teamId")
160+
)
161+
162+
allUsers <- left_join(allUsers, teamInfo, by="teamId")
163+
}
156164
levels(allUsers$teamName) <- c(levels(allUsers$teamName), "None")
157165
allUsers$teamName[is.na(allUsers$teamName)] <- "None"
166+
167+
158168
```
159169

160170
```{r userJoin}

0 commit comments

Comments
 (0)