-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
152 lines (97 loc) · 4.3 KB
/
streamlit_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
# streamlit_app.py
import streamlit as st
import snowflake.connector
import pandas as pd
import pandas_profiling
from streamlit_pandas_profiling import st_profile_report
from pandas_profiling import ProfileReport
# Initialize connection.
# Uses st.experimental_singleton to only run once.
@st.experimental_singleton
def init_connection():
return snowflake.connector.connect(
**st.secrets["snowflake"], client_session_keep_alive=True
)
conn = init_connection()
# Perform query.
# Uses st.experimental_memo to only rerun when the query changes or after 10 min.
@st.experimental_memo(ttl=600)
def run_query(query):
with conn.cursor() as cur:
cur.execute(query)
return cur.fetchall()
rows = run_query("SELECT * from MHEALTH_3;")
df = pd.DataFrame(rows)
# Print results.
#for row in rows:
# st.write(f"{row[0]} has a :{row[1]}:")
st.write(df)
st.sidebar.header("Pick an activity for profiling")
x_val= st.sidebar.selectbox("Pick a type of activity", ('Null class', 'Standing still (1 min)', 'Sitting and relaxing (1 min)', 'Lying down (1 min)', 'Walking (1 min)', 'Climbing stairs (1 min)', 'Waist bends forward (20x)', 'Frontal elevation of arms (20x)', 'Knees bending (crouching) (20x)', 'Cycling (1 min)', 'Jogging (1 min)', 'Running (1 min)', 'Jump front & back (20x)'))
act_val = 0
if x_val == 'Null class':
act_val = 0
if x_val == 'Standing still (1 min)':
act_val = 1
if x_val == 'Sitting and relaxing (1 min)':
act_val = 2
if x_val == 'Lying down (1 min)':
act_val = 3
if x_val == 'Walking (1 min)':
act_val = 4
if x_val == 'Climbing stairs (1 min)':
act_val = 5
if x_val == 'Waist bends forward (20x)':
act_val = 6
if x_val == 'Frontal elevation of arms (20x)':
act_val = 7
if x_val == 'Knees bending (crouching) (20x)':
act_val = 8
if x_val == 'Cycling (1 min)':
act_val = 9
if x_val == 'Jogging (1 min)':
act_val = 10
if x_val == 'Running (1 min)':
act_val = 11
if x_val == 'Jump front & back (20x)':
act_val = 12
df = df[df['label'] == act_val]
profile = ProfileReport(df.loc[:,'acc_chest_x':'mag_arm_z'],
title="mHealth Dataset",
dataset={
"description": "This profiling report was generated for mHealth Dataset",
"url": "https://archive.ics.uci.edu/ml/datasets/MHEALTH%20Dataset",
},
variables={
"descriptions": {
"sub_id": "Subject identitification number",
"acc_chest_x": "acceleration from the chest sensor (X axis)",
"acc_chest_y": "acceleration from the chest sensor (Y axis)",
"acc_chest_z": "acceleration from the chest sensor (Z axis)",
"ekg_1": "electrocardiogram signal (lead 1)",
"ekg_2": "electrocardiogram signal (lead 2)",
"acc_ankle_x": "acceleration from the left-ankle sensor (X axis)",
"acc_ankle_y": "acceleration from the left-ankle sensor (Y axis)",
"acc_ankle_z": "acceleration from the left-ankle sensor (Z axis)",
"gyro_ankle_x": "gyro from the left-ankle sensor (X axis)",
"gyro_ankle_y": "gyro from the left-ankle sensor (Y axis)",
"gyro_ankle_z": "gyro from the left-ankle sensor (Z axis)",
"mag_ankle_x": "magnetometer from the left-ankle sensor (X axis)",
"mag_ankle_y": "magnetometer from the left-ankle sensor (Y axis)",
"mag_ankle_z": "magnetometer from the left-ankle sensor (Z axis)",
"acc_arm_x": "acceleration from the right-lower-arm sensor (X axis)",
"acc_arm_y": "acceleration from the right-lower-arm sensor (Y axis)",
"acc_arm_z": "acceleration from the right-lower-arm sensor (Z axis)",
"gyro_arm_x": "gyro from the right-lower-arm sensor (X axis)",
"gyro_arm_y": "gyro from the right-lower-arm sensor (Y axis)",
"gyro_arm_z": "gyro from the right-lower-arm sensor (Z axis)",
"mag_arm_x": "magnetometer from the right-lower-arm sensor (X axis)",
"mag_arm_y": "magnetometer from the right-lower-arm sensor (Y axis)",
"mag_arm_z": "magnetometer from the right-lower-arm sensor (Z axis)",
"label": "Activity type",
}
}
)
st.title(f"mHealth Dataset Profiling in Streamlit for activity: {x_val}!")
st.write(df)
st_profile_report(profile)