-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.R
202 lines (166 loc) · 5.2 KB
/
server.R
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
library(pins)
library(tidyverse)
server <- function(input, output, session) {
# Reactive Vals -----------------------------------------------------------
# Should be pin_reactive, but datafile boards aren't
# handling ETAG cache well right now
raw <- reactiveVal(
pin_get('cl_hist', board = 'conscious_lang')
)
h <- reactiveVal()
d <- reactiveVal()
org_repo <- reactiveVal(list(org = 'All', repo = 'All'))
# ObserveEvents -----------------------------------------------------------
observeEvent(raw(), {
# if raw updates, reset d() and h()
h(raw())
d(raw() %>%
filter(date == max(date)) %>%
select(-date))
# now get the org list from raw()
orgs <- raw() %>%
filter(date == max(date)) %>%
pull(org) %>%
unique() %>%
sort()
orgs <- c('All',orgs)
updateSelectInput(session, 'side_org',
choices = orgs, selected = input$side_org)
})
observeEvent(input$side_org, {
repos <- if (input$side_org == 'All') {
raw() %>%
filter(date == max(date)) %>%
mutate(label = glue('{org}/{repo}')) %>%
pull(label) %>%
unique() %>%
sort()
} else {
raw() %>%
filter(date == max(date)) %>%
filter(org == input$side_org) %>%
pull(repo) %>%
unique() %>%
sort()
}
repos <- c('All',repos)
updateSelectInput(session, 'side_repo',
choices = repos, selected = 'All')
# Detected an update to Org, stash it
o <- org_repo()
o$org <- input$side_org ; o$repo <- 'All'
org_repo(o)
})
observeEvent(input$side_repo, {
# Cleanly store org/repo even when "all" selected
or <- org_repo()
if (str_detect(input$side_repo,'/')) {
split <- str_split_fixed(input$side_repo,'/',2)
or$org <- split[1]
or$repo <- split[2]
} else {
# Org should already be set in the other observer
or$repo <- input$side_repo
}
org_repo(or)
})
observeEvent(org_repo(),{
or <- org_repo()
tmp <- raw() %>%
filter(if (or$org == 'All') TRUE else org == or$org) %>%
filter(if (or$repo == 'All') TRUE else repo == or$repo)
h(tmp)
tmp <- tmp %>%
filter(date == max(date)) %>%
select(-date)
d(tmp)
})
# Bar graphs --------------------------------------------------------------
output$plot1 <- renderGirafe({
bar_plot(d(),blacklist)
})
output$plot2 <- renderGirafe({
bar_plot(d(),whitelist)
})
output$plot3 <- renderGirafe({
bar_plot(d(),master)
})
output$plot4 <- renderGirafe({
bar_plot(d(),slave)
})
# History Graphs ----------------------------------------------------------
output$hist1 <- renderGirafe({
line_plot(h(),blacklist)
})
output$hist2 <- renderGirafe({
line_plot(h(),whitelist)
})
output$hist3 <- renderGirafe({
line_plot(h(),master)
})
output$hist4 <- renderGirafe({
line_plot(h(),slave)
})
# Info Boxes --------------------------------------------------------------
output$blacklist <- renderInfoBox({
infoBox("Blacklist", sum(d()$blacklist),
subtitle = 'Total in all repos',
icon = icon('dice-one'), color = 'red')
})
output$whitelist <- renderInfoBox({
infoBox("Whitelist", sum(d()$whitelist),
subtitle = 'Total in all repos',
icon = icon('dice-two'), color = 'yellow')
})
output$master <- renderInfoBox({
infoBox("Master", sum(d()$master),
subtitle = 'Total in all repos',
icon = icon('dice-three'), color = 'blue')
})
output$slave <- renderInfoBox({
infoBox("Slave", sum(d()$slave),
subtitle = 'Total in all repos',
icon = icon('dice-four'), color = 'purple')
})
# Tables ------------------------------------------------------------------
output$table <- DT::renderDataTable({
d() %>%
arrange(url) %>%
rowwise() %>%
mutate(url = map_chr(url, ~ toString(htmltools::tags$a(href=url,url))),
total = sum(c_across(where(is.numeric)))) %>%
relocate(total, .after = url) %>%
ungroup() %>%
select(-org,-repo) %>% # redundant for display purposes
arrange(-total) %>%
DT::datatable(escape=F)
})
output$deltas <- DT::renderDataTable({
h() %>%
arrange(date) %>%
group_by(url) %>%
summarise(across(where(is.numeric), ~{last(.x) - nth(.x,-2L)},
.names = "delta_{.col}")) %>%
ungroup() %>%
rowwise() %>%
mutate(url = map_chr(url, ~ toString(htmltools::tags$a(href=url,url))),
total = sum(c_across(where(is.numeric)))) %>%
relocate(total, .after = url) %>%
arrange(total) %>%
DT::datatable(escape=F)
})
output$filetable <- DT::renderDataTable({
if (input$side_org == 'All') {
return(data.frame(message = 'Please select a specific Org'))
}
if (input$side_repo == 'All') {
return(data.frame(message = 'Please select a specific Repo'))
}
repo = paste(input$side_org, input$side_repo, sep = '/')
httr::GET(url = 'http://dev.stats.eng.ansible.com:7033',
path = '/search',
query = list(repo = repo, word = input$word)
) -> res
httr::content(res,'parsed')
})
}