-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebApp.py
82 lines (66 loc) · 2.67 KB
/
WebApp.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
### Example
# - Distance 21.01 km
# - Pace 7:49/km
# - Time 2h 44m
### Another example:
# - Distance 6.44 km
# - Pace 7:20/km
# - Time 47m 16s
import streamlit as st
import pandas as pd
from Functions import *
st.set_page_config(page_title="Pace Converter", page_icon="RunningIcon_Test.jpg", layout="centered", menu_items=None)
# Pace conversion section
st.markdown("<h3 style='text-align: center;'>Pace Converter</h3>", unsafe_allow_html=True)
# Drop box -> selection if km or m
measurement_conver = st.selectbox('Are you measuring in Miles or Kilometers?', options=["Kilometers","Miles"])
# Enter pace here
default_pace = '7.48'
pace_conver = st.text_input("What was your pace?", default_pace)
# Applying function for conversion
try:
pace_conversion = paceConverter(measurement_conver, pace_conver)
except:
st.write('Please enter your pace in the correct format: 0.0')
# Pace calculator secion
st.markdown("<h3 style='text-align: center;'>Pace Calculator</h3>", unsafe_allow_html=True)
# Getting time variable
default_time = '2:44:0'
time = st.text_input("What was your time? Please enter hours, minutes, and seconds separated by ':'. h:m:s", default_time)
# Distance
default_distance = '21.01'
distance = st.text_input("What distance did you run? Please enter value separated by commas: 0,0", default_distance)
# Km or mi
measurement = st.selectbox('Are you measuring in kilometer or miles?', options=["Kilometers","Miles"])
# Calculating pace with function from Functions.py file
# time, distance, measurement
try:
pace = paceCalculator(time, distance, measurement)
except ValueError as e:
pace = str(e)
st.write('Invalid time format. Please enter hours, minutes, and seconds separated by ":"')
# Km to mile converter
st.markdown("<h3 style='text-align: center;'>Unit Conversion</h3>", unsafe_allow_html=True)
# Drop box -> selection if km or m
conversion = st.selectbox('Converting from', options=["Kilometers","Miles"])
distance_to_convert = st.text_input("Enter your distance", '10')
try:
distance_conversion = UnitConverter(conversion, distance_to_convert)
except ValueError as e:
distance_conversion = str(e)
st.write('Invalid unit format. Please enter a number.')
# Common pace and times table, getting data from excel file
st.markdown("<h3 style='text-align: center;'>Common Pace and Times Table</h3>", unsafe_allow_html=True)
df = pd.DataFrame(df)
# Define the CSS style for centering the dataframe
centered_css = """
<style>
div.stDataFrame {
display: flex;
justify-content: center;
}
</style>
"""
# Render the dataframe with the CSS style applied
st.markdown(centered_css, unsafe_allow_html=True)
st.dataframe(df.set_index(df.columns[0]))