-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
87 lines (71 loc) · 3.06 KB
/
app.py
File metadata and controls
87 lines (71 loc) · 3.06 KB
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
import json
import dash_bootstrap_components as dbc
import plotly.express as px
import pandas as pd
from dash import dash, Output, Input, State
import settings
import utils.analyzer
from dashboard import dashboard
app = dash.Dash(
__name__,
external_stylesheets=[
dbc.themes.BOOTSTRAP,
'/assets/css/styles.css',
'/assets/css/all.min.css'
],
meta_tags=[{'name': 'viewport', 'content': 'width=device-width, initial-scale=1'}]
)
dashboard.setup(app)
@app.callback(
[
Output(component_id='total-events', component_property='value'),
Output(component_id='total-meetings', component_property='value'),
Output(component_id='total-meetings', component_property='max'),
Output(component_id='total-personal', component_property='value'),
Output(component_id='total-personal', component_property='max'),
Output(component_id='sum-meetings', component_property='value'),
Output(component_id='sum-personal', component_property='value'),
Output(component_id='distribution', component_property='figure'),
Output(component_id='attendees-table', component_property='data'),
Output(component_id='event-analysis-wordcloud', component_property='src'),
],
[
Input(component_id='btn-submit', component_property='n_clicks'),
State(component_id='date-picker-range', component_property='start_date'),
State(component_id='date-picker-range', component_property='end_date'),
])
def update_charts(_, start_date, end_date):
df = pd.json_normalize(json.load(open(f'{settings.JSON_DIR}events.json', 'r')))
df = df[(df['start'] >= start_date) & (df['start'] <= end_date)]
df['duration'] = (pd.to_datetime(df['end']) - pd.to_datetime(df['start'])).astype('timedelta64[m]')
meetings_df = df[df['attendees'].notnull()]
personal_df = df[df['attendees'].isnull()]
cats = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
agg_df = meetings_df.groupby(pd.to_datetime(df['start'], utc=True).dt.day_name()).sum()
agg_df = agg_df.reindex(cats).reset_index()
attendees_df = df.explode('attendees').groupby(['attendees'])['belongs_to'].count().reset_index(name='count').sort_values('count', ascending=False)
fig = px.bar(
data_frame=agg_df,
x='start',
y='duration',
color_discrete_sequence=['#2596be']
)
fig.update_layout({
'plot_bgcolor': 'rgba(0, 0, 0, 0)',
'paper_bgcolor': 'rgba(0, 0, 0, 0)',
'font_color': '#fff',
})
return [
len(df),
len(meetings_df), # meetings are events with attendees
len(df),
len(personal_df), # personal events are the ones without attendees
len(df),
round(meetings_df['duration'].sum()),
round(personal_df['duration'].sum()) if len(personal_df) else 0.0,
fig,
[record for record in attendees_df[1:settings.TOPN + 1].to_dict('records')],
utils.analyzer.generate_wordcloud(df, 'summary')
]
if __name__ == '__main__':
app.run_server(host='0.0.0.0')