-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdash_prototype.py
190 lines (161 loc) · 6.43 KB
/
dash_prototype.py
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
# %%
import dash
from dash import dcc
import dash_bootstrap_components as dbc
import warnings
warnings.filterwarnings('ignore')
from dash import html
from dash.dependencies import Input, Output, State
from datetime import date
from kamaeleon.objects.learning_path import LearningPath
from kamaeleon.objects.learning_plan import LearningPlan
from kamaeleon.objects.learning_indicator import LearningIndicator
# %% load learning path
# learning_path_id = "581110fd-158a-4f2a-b6f4-45c52fb7fbf7" # Data Reporting
# language = "en"
learning_path_id = "d1a84c51-962a-4f18-bccf-a0f66796060f" # Grundlagen agiles Management
language = "de"
# learning_path_id = "e55a6b40-94c7-4084-af11-b6118d10ed31" # Führung in der Praxis
# language = "de"
learning_path = LearningPath()
learning_path.initialize_from_id(
id=learning_path_id,
language=language
)
learning_plan = LearningPlan(learning_path=learning_path)
learning_plan.round_base = 5
learning_plan.round_mode = "best"
learning_indicator = LearningIndicator(learning_plan=learning_plan)
def get_learning_path_materials_options(learning_path: LearningPath) -> dict:
opts = []
for material in learning_path.materials:
opts.append({
"label": material.title,
"value": material.id,
"disabled": True if material.is_finished or material.is_skipped else False
})
return opts
def get_learning_path_materials_values(learning_path: LearningPath) -> dict:
vals = []
for material in learning_path.materials:
if material.is_skipped or material.is_finished:
vals.append(material.id)
return vals
def split_message(msg: str) -> list:
msg_split = msg.split("\n")
output_msg = []
for s in msg_split:
output_msg.append(s)
output_msg.append(html.Br())
return output_msg
#%%
# ============================================== #
# the app itself
app = dash.Dash(__name__, external_stylesheets = [dbc.themes.BOOTSTRAP])
app.layout = html.Div([
dcc.Store(id='update-store'),
html.Div([
dbc.Row([
dbc.Col([
html.Div([
html.H3("Learning path:"),
]),
html.Div([
html.Div(id="learning-path"),
dcc.Checklist(
id="learning-path-checklist",
options=get_learning_path_materials_options(learning_path),
value=get_learning_path_materials_values(learning_path),
labelStyle = dict(display='block')
)
])
]),
dbc.Col(
html.Div([
html.Div([
html.H3("Settings"),
]),
html.Div([
dcc.DatePickerSingle(
id='start-date-picker',
min_date_allowed=date(2000, 1, 1),
max_date_allowed=date(2025, 12, 31),
date=date(2022, 12, 2)
),
dcc.DatePickerSingle(
id='end-date-picker',
min_date_allowed=date(2000, 1, 1),
max_date_allowed=date(2025, 12, 31),
date=date(2023, 1, 2)
),
html.Button("Set deadline", id="deadline-button", n_clicks=0),
html.Div(id="deadline-div")
]),
html.H3("Learning indicator"),
dcc.DatePickerSingle(
id='current-date-picker',
min_date_allowed=date(2000, 1, 1), # add current learning plan date here
max_date_allowed=date(2025, 12, 31),
date=date(2022, 12, 5)
),
html.Button("Update", id="update-button", n_clicks=0),
html.Div(id="learning-indicator-output"),
html.Div(id="learning-plan-summary"),
html.Div(id="learning-plan-output")
])
)
]
),
])
])
@app.callback(
Output('update-store', 'data'),
Input('update-button', 'n_clicks'),
State('current-date-picker', 'date')
)
def update_output(n_clicks, date):
if n_clicks > 0:
learning_plan.set_new_date(date)
return "Trigger"
@app.callback(
Output("deadline-div", "children"),
[
State('start-date-picker', 'date'),
State('end-date-picker', 'date')
],
Input("deadline-button", "n_clicks")
)
def initialize_learning_plan(start_date, end_date, n_button_clicked):
if n_button_clicked == 0:
return ""
else:
learning_plan.initialize(start_date=start_date, end_date=end_date)
return "Deadline set"
@app.callback(
[
Output("learning-indicator-output", "children"),
Output("learning-plan-summary", "children"),
Output("learning-plan-output", "children"),
Output("learning-path-checklist", "options"),
Output("learning-path-checklist", "value")
],
[
Input('learning-path-checklist', 'value'),
Input('update-store', 'data')
]
)
def update_learning_plan_and_indicator(finished_material_ids, trigger):
if learning_plan.start_date is None:
lpc_options = get_learning_path_materials_options(learning_path)
lpc_values = get_learning_path_materials_values(learning_path)
return "", "", "", lpc_options, lpc_values
else:
for material in learning_plan.learning_path.materials:
if material.id in finished_material_ids and not (material.is_finished or material.is_skipped):
learning_plan.make_progress_by_material_id(material_id=material.id)
msg = learning_indicator.display()
lpc_options = get_learning_path_materials_options(learning_path)
lpc_values = get_learning_path_materials_values(learning_path)
return split_message(msg), split_message(learning_plan.summary_msg()), split_message(learning_plan.current_week_workload.__str__()), lpc_options, lpc_values
if __name__ == "__main__":
app.run(debug=True)