-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean_press.py
97 lines (74 loc) · 3.16 KB
/
clean_press.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
import math
import os
from PIL import Image, ImageDraw, ImageFont
import streamlit as st
from streamlit_javascript import st_javascript
import numpy as np
import pandas as pd
BAR_WEIGHT = 20
plates = [
{"weight": 25, "color" : 'red'},
{"weight": 20, "color" : 'blue'},
{"weight": 15, "color" : 'yellow'},
{"weight": 10, "color" : 'black'},
{"weight": 5, "color": 'black'},
{"weight": 2.5, "color": 'red'},
{"weight": 1.25, "color": 'black'},
{"weight": 1, "color": 'black'},
{"weight": 0.5, "color": 'black'}
]
sorted_plates = sorted(plates, key=lambda x: x['weight'], reverse=True)
def decompose_weight(weight, weights_selection):
added_weight = weight - BAR_WEIGHT # remove the bar weight
semi_weight = added_weight / 2
current_weight = 0
composition = []
for plate in sorted_plates:
if weights_selection and not plate['weight'] in weights_selection:
continue
while current_weight + plate["weight"] <= semi_weight:
composition.append(plate)
current_weight = current_weight + plate["weight"]
return composition
def make_table(weight, plates_selection):
rounding_value = min(plates_selection)
percents = [i for i in np.arange(0.8, 1.01, 0.02)]
perfect_weights = [round(weight * p, 2) for p in percents]
min_weights = [math.floor(w / rounding_value) * rounding_value for w in perfect_weights]
max_weights = [math.ceil(w / rounding_value) * rounding_value for w in perfect_weights]
actual_weights = list(set(min_weights + max_weights))
compositions = [decompose_weight(w, plates_selection) for w in actual_weights]
df1 = pd.DataFrame(data={'percent': percents, 'actual': perfect_weights})
df2 = pd.DataFrame(data={'actual': actual_weights, 'composition': compositions})
df = df1.merge(df2, how='outer', on='actual')
df = df.sort_values(by='actual', ascending=False)
return df
def make_weight_list(my_plates):
if not isinstance(my_plates, list):
return []
return [p['weight'] for p in my_plates]
st.set_page_config(
page_title="WOD with william",
page_icon=":weight_lifter:"
)
options = [plate['weight'] for plate in reversed(sorted_plates)]
plates_selection = st.pills("Choose your plates"
, options
, default = [w for w in options if w <=10 and w>=1.25]
, selection_mode="multi")
weight_one_rep = st.number_input("Enter your 1 REP weight (in Kg)"
, value=60.0
,step=2.5)
st.divider()
df = make_table(weight_one_rep, plates_selection)
df['composition'] = df['composition'].apply(make_weight_list)
df['percent'] = df['percent'].fillna("")
column_config={
"percent": st.column_config.NumberColumn(format="%.2f")
, "actual": st.column_config.NumberColumn(format="%.2f")
, "composition": st.column_config.ListColumn(width="large")
}
st.dataframe(df
, hide_index=True
, column_config=column_config
, width=600, height=600)