-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnTheScales.py
174 lines (148 loc) · 4.9 KB
/
OnTheScales.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
import streamlit as st
import functions.utils as ut
import functions.user as user
import functions.figures as fgs
# init default values
ut.init_vars()
ut.default_style()
ut.create_menu()
# ----- current user -----
col_title = st.columns(2, gap="small", vertical_alignment="bottom")
# name
with col_title[0]:
col_title[0].header(st.session_state.user_name)
# shortcut to go to measurements page
with col_title[1]:
goto_measurement = st.button("New Measurement", icon=":material/add_circle:")
if goto_measurement:
ut.switch_page("measurements")
# ----- main figure -----
# create fragment 4 main_figure
@st.fragment()
def fragment_main_figure():
with st.container(border=True):
# create figure
fig_chrono = fgs.main()
# draw and show figure
if fig_chrono is None:
st.markdown("_No measurements stored yet._")
else:
st.plotly_chart(
fig_chrono,
use_container_width=True,
config={"displayModeBar": False},
key="fig_chrono",
)
# add selectbox for figure styling
st.divider()
st.segmented_control(
"data style:", options=["lines", "markers", "both"], key="fig_main_style"
)
# run main figure fragment
fragment_main_figure()
# ----- trend figure -----
ut.h_spacer(1)
st.subheader("trend & predict")
# create trend figure and get trend
fig_trend, trend = fgs.trend()
with st.container(border=True):
if fig_trend is None:
st.markdown("_No, or not enough, measurements stored yet._")
else:
# show current change rate of weight
c1, c2, c3 = st.columns([3, 2, 2])
c1.markdown(
"**$\Delta$kg {txt}:**".format(
txt=(
"since {date}".format(
date=st.session_state.trend_start.date().strftime("%d.%m.%Y")
)
if st.session_state.trend_how == "start date"
else "in last {weeks} weeks".format(
weeks=st.session_state.trend_range
)
)
)
)
c2.markdown(f"_{round(trend*10**9*60*60*24*7, 2)} kg/week_")
c3.markdown(f"_{round(trend*10**9*60*60*24*30, 2)} kg/month_")
# draw and show trend
st.plotly_chart(
fig_trend,
use_container_width=True,
config={"displayModeBar": False},
key="fig_trend",
)
# add columns for figure options
st.divider()
col_trend = st.columns(2, gap="small")
# radio button to select how to define starting point
with col_trend[0]:
st.segmented_control(
"trend based on:",
options=["start date", "date range"],
key="trend_how",
on_change=user.update_trend,
)
# select _start date_
with col_trend[1]:
if st.session_state.trend_how == "start date":
st.date_input(
"select 'start date':",
format="DD.MM.YYYY",
key="trend_start",
on_change=user.update_trend,
)
# select _date range_
if st.session_state.trend_how == "date range":
st.number_input(
"select 'range' - in weeks:",
format="%d",
min_value=1,
max_value=100,
step=1,
key="trend_range",
on_change=user.update_trend,
)
# ----- body composition figure -----
ut.h_spacer(1)
st.subheader("body composition")
# create fragment 4 body_comp_figure
@st.fragment()
def fragemnt_body_comp_figure():
with st.container(border=True):
# draw figure
fig_body_comp = fgs.body_comp()
if fig_body_comp is None:
st.markdown("_No measurements stored yet._")
else:
st.plotly_chart(
fig_body_comp,
use_container_width=True,
config={"displayModeBar": False},
key="fig_body_comp",
)
# add columns for figure options
st.divider()
col_body_comp = st.columns([2, 3, 2], gap="small")
# add selectbox for body composition
col_body_comp[0].segmented_control(
"body composition:",
options=["%", "kg"],
format_func=lambda x: "in " + x,
key="fig_body_comp_type",
)
# add selectbox for figure styling
col_body_comp[1].segmented_control(
"data style:",
options=["lines", "markers", "both"],
key="fig_body_comp_style",
)
# add selectbox for adding weight
col_body_comp[2].segmented_control(
"showing:",
options=["weight & target"],
key="fig_body_comp_weight",
)
# run body comp figure fragment_main_figure
fragemnt_body_comp_figure()