-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
175 lines (131 loc) · 6.55 KB
/
app.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
import dash
from dash import dcc
from dash import html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import dash_bootstrap_components as dbc
import pandas as pd
import datetime
from datetime import date, timedelta
import os
app = dash.Dash(__name__,external_stylesheets=[dbc.themes.VAPOR],meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=1"}
])
app.title = "Wrist Wearable's Data Monitor"
server = app.server
hr_data = os.path.join(os.path.dirname(os.path.abspath(__file__)),'data/HR-data-2021-12-08 20_37_23.csv')
notes_data = os.path.join(os.path.dirname(os.path.abspath(__file__)),'data/notes.csv')
df = pd.read_csv(notes_data)
df1 = pd.read_csv(hr_data)
df1.dropna(inplace=True)
df1['Date'] = pd.to_datetime(df1['Time']).dt.date
df1['Time'] = pd.to_datetime(df1['Time']).dt.time
df['mood'] = df['mood'].str.strip()
moods_list = {
'happy': '😃',
'content': '🙂',
'neutral': '😐',
'sad': '☹️',
'angry': '😡',
'bored': '😒',
'tired': '😫',
'grateful': '😇',
'stressed': '😓',
'motivated': '🧐',
'relieved': '😌',
'focused': '🤔',
'irritated': '😩',
'relaxed': '😎',
'hopeful': '😏',
'anxious': '😰',
'frustrated': '😖',
'inspired': '🤩',
'guilt': '🤥',
'ashamed': '😬',
'depressed': '😥',
'indifferent': '😕'
}
df['emojis'] = df['mood'].map(moods_list)
app.layout = dbc.Container(
[
html.H1(["Wrist Wearable's Data Monitor"],style={'text-align':'center'}),
html.Hr(),
dbc.Row(
[
dbc.Col(
[
dbc.Row(html.H3(['Hourly Activity'],style={'text-align':'center'})),
dbc.Row(id='card-content',style={'overflow':'scroll','overflow-x':'hidden','height':'800px'})
],style={'margin-bottom':'50px'},align='center',md=2
),
dbc.Col(
[
dbc.Row(
[
dcc.DatePickerSingle(
id='my-date-picker-single',
min_date_allowed=date(2021, 9, 2),
max_date_allowed=date(2021, 9, 19),
initial_visible_month=date(2021, 9, 1),
date=date(2021, 9, 10)
),
html.Div(id='output-container-date-picker-single')
]
),
dbc.Row(id='graph')
],align='center',md=10
)
]
)
],fluid=True
)
@app.callback(
[Output('output-container-date-picker-single', 'children'),Output('graph','children'),Output('card-content','children')],
[Input('my-date-picker-single', 'date')]
)
def update_output(date_value):
df1['Date'] = df1['Date'].astype('str')
df1['Time'] = df1['Time'].astype('str')
df_filtered = df[df['full_date'] == date_value]
df1_filtered = df1[df1['Date'] == date_value]
df_filtered['full_date'] = pd.to_datetime(df_filtered['full_date'] + ' ' + df_filtered['time'])
df_filtered['full_date'] = pd.to_datetime(df_filtered['full_date']) - timedelta(hours=5) #only for deployed version
df_filtered.sort_values('full_date',inplace=True)
df_filtered.reset_index(inplace=True,drop=True)
df1_filtered['Date'] = pd.to_datetime(df1_filtered['Date'] + ' ' + df1_filtered['Time'])
df1_filtered['Date'] = pd.to_datetime(df1_filtered['Date'])
df1_filtered.sort_values('Date',inplace=True)
df1_filtered.reset_index(drop=True,inplace=True)
string_prefix = 'You have selected: '
if date_value is not None:
date_object = date.fromisoformat(date_value)
date_string = date_object.strftime('%B %d, %Y')
fig = go.Figure()
fig.add_trace(go.Scatter(x=df1_filtered['Date'], y=df1_filtered['Empatica.mean'],
mode='lines'))
fig.update_layout(title_text='Heart Rate',title_font_size=24,font_color='#ffffff',paper_bgcolor="rgba(0,0,0,0)",plot_bgcolor="rgba(0,0,0,0)",margin=dict(l=0,r=0))
fig.update_xaxes(showline=True, linewidth=1, linecolor='rgba(255,255,255,0.5)', showgrid=False, zeroline=False, rangeslider_visible=True)
fig.update_yaxes(showline=True, linewidth=1, linecolor='rgba(255,255,255,0.5)', showgrid=False, zeroline=False)
for i in range(len(df_filtered)):
fig.add_vline(x=datetime.datetime.strptime(str(df_filtered['full_date'][i]), "%Y-%m-%d %H:%M:%S").timestamp() * 1000, line_width=1, line_dash="dash", line_color="#32fbe2",annotation_text=df_filtered['emojis'][i],annotation_position='top',annotation_font_size=32,annotation_hovertext=df_filtered['mood'][i])
card_content = []
for i in range(len(df_filtered)):
card_content.append(dbc.Row(
[
dbc.Col(dbc.Card(children=[
dbc.CardHeader(children=[df_filtered['time'][i]]),
dbc.CardBody(
[
html.P(children=[df_filtered['note'][i]],
className="card-text",
),
]
)
],style={'margin':'10px 0px 10px 10px'},color="primary", inverse=True
)
)
]
))
return [string_prefix + date_string,dcc.Graph(figure=fig),card_content]
if __name__ == "__main__":
app.run_server(debug=False)