-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.jl
270 lines (236 loc) · 6.95 KB
/
app.jl
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
using Pkg
Pkg.activate(".")
#using Revise
using Dash, DashHtmlComponents, DashCoreComponents, DashBootstrapComponents
using Statistics, DataFrames, CSVFiles
using Dates
import TOML
include("utils.jl")
# App begins
df = load_dataframe()
app = dash(external_stylesheets = ["assets/style.css", dbc_themes.COSMO])
app.title = "Julia Packages Requests"
title = dbc_row(
dbc_col(
dbc_alert(
color = "primary",
html_center(
html_div(
style = Dict("vertical-alight" => "middle"),
html_h1("Julia Packages requests"),
),
),
className = "bmi-jumbotron",
),
),
className = "mt-3",
)
ttip =
dbc_tooltip("Enter a Julia package name and press the search button", target = "hola")
graph = dcc_graph(id = "graph", figure = plot_default())
graph_content = html_div([
dbc_row([dbc_col(graph, width = 12)]),
html_br(),
dbc_row([
dbc_col(html_div(id = "info-content1", ["Info1"]), width = 6),
dbc_col(html_div(id = "info-content2", ["Info2"]), width = 6),
]),
])
tabs = dbc_row([
dbc_col(
html_div([
dbc_tabs(
[
dbc_tab(label = "Users", tab_id = "user"),
dbc_tab(label = "CI runs", tab_id = "ci"),
],
id = "tabs",
active_tab = "user",
),
html_div(id = "graph-content", graph_content),
]),
width = 12,
),
],);
date_picker = dcc_datepickerrange(
id = "dates",
start_date = df."date"[begin],
end_date = df."date"[end],
)
date_input = dbc_inputgroup([
dbc_inputgrouptext(id = "date-range", "Date range"),
date_picker,
dbc_tooltip("Select a date range for the request's data", target = "date-range"),
])
search_input = dbc_inputgroup([
dbc_inputgrouptext("Package", id = "package-label"),
dbc_input(id = "search-input", placeholder = "name"),
dbc_tooltip(
"Enter a Julia package name and press the search button",
target = "package-label",
),
dbc_button("Search", color = "primary", id = "search-button"),
])
drop = dcc_dropdown(
id = "drop",
options = [(label = "PlotlyJS", value = "PlotlyJS")],
style = Dict("width" => "300px"),
multi = true,
value = nothing,
)
drop2 = dcc_dropdown(
id = "drop2",
options = [(label = "Regular", value = "REG"), (label = "Cumulative", value = "CMT")],
style = Dict("width" => "300px"),
value = "REG",
)
mode2 = dbc_inputgroup([
dbc_inputgrouptext("Mode", id = "mode2"),
drop2,
dbc_tooltip("Select plot type", target = "mode2"),
])
packages_input = dbc_row([
dbc_col(search_input, width = 4),
dbc_col(dbc_inputgroup([dbc_inputgrouptext("Select", id = "multi"), drop]), width = 8),
dbc_tooltip(
"Select one or more of the searched package(s) to render",
target = "multi",
),
])
drop_input = dbc_row(dbc_col(date_input, width = 6))
opts = []
callback!(
app,
Output("drop", "options"),
Output("drop", "value"),
Output("search-input", "value"),
Input("search-button", "n_clicks"),
State("search-input", "value"),
) do clicks, input_value
value = input_value
if value !== nothing
value = split(input_value, ".")[1] # To strip .jl part
end
package_df = package_dataframe(value)
if package_df === nothing
return opts, nothing, ""
end
append!(opts, [(label = value, value = value)])
opts_set = Set(opts)
opts_new = [o for o in opts_set]
opts_new, value, ""
end
checks = dbc_checklist(
id = "checks",
options = [
Dict("label" => "Regression Line", "value" => "RL"),
Dict("label" => "Seven days moving averages", "value" => "MA"),
],
value = [],
labelStyle = Dict("display" => "inline-block"),
)
function package_global_stats(name, stats)
total_requests = stats["total"]
interval = stats["interval"]
precision = 2
daily_average = round(total_requests / interval, digits = precision)
α = stats["α"]
β = stats["β"]
dbc_card(
[
dbc_cardbody([
html_h4("$(name) global statistics", className = "card-title"),
html_div(
[
html_p("Total requests: $total_requests"),
html_p("Time interval: $interval days"),
html_p("Daily average: $daily_average"),
html_p("Regression slope: $β"),
],
className = "card-text",
),
]),
],
style = Dict("width" => "12rem"),
)
end
function packages_info_table(packages, stats)
table_header = [
html_thead(
html_tr([
html_th("Package"),
html_th("Daily average"),
html_th("Regression slope"),
]),
),
]
rows = []
for (i, name) in enumerate(packages)
s = stats[i]
total = s["total"]
interval = s["interval"]
precision = 2
daily_average = round(total / interval, digits = precision)
β = s["β"]
row = html_tr([html_td(name), html_td("$daily_average"), html_td("$β")])
append!(rows, [row])
end
table_body = [html_tbody(rows)]
dbc_table([table_header; table_body], bordered = true)
end
callback!(
app,
Output("graph", "figure"),
Output("info-content1", "children"),
Output("info-content2", "children"),
Input("tabs", "active_tab"),
Input("drop", "value"),
Input("dates", "start_date"),
Input("dates", "end_date"),
Input("checks", "value"),
Input("drop2", "value"),
) do at, options, sd, ed, check_vals, drop2_val
println(options)
if (options === nothing) || (length(options) == 0)
return plot_default(), [""], [""]
end
if typeof(options) === String
options = [options]
end
figure, c_figure, stats_info =
plot_graphs(options, check_vals, at, start_date = sd, end_date = ed)
fout = figure
if drop2_val == "CMT"
fout = c_figure
end
info1 = [""]
info2 = [""]
if options !== nothing
if length(options) == 1
info1 = [package_global_stats(options[1], stats_info[1])]
else
vals = [s["total"] for s in stats_info]
figure = plot(pie(values = vals, labels = options, marker_colors = colors))
info1 = [dcc_graph(figure = figure)]
info2 = [packages_info_table(options, stats_info)]
end
end
return fout, info1, info2
end
app.layout = dbc_container(
[
title
html_br()
packages_input
html_br()
dbc_row([dbc_col(checks, width = 4), dbc_col(mode2, width = 8)])
html_br()
drop_input
html_br()
html_br()
dbc_spinner(tabs)
html_br()
html_br()
],
)
run_server(app, "0.0.0.0", debug = false)