-
Notifications
You must be signed in to change notification settings - Fork 4
/
functions.py
61 lines (50 loc) · 1.48 KB
/
functions.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
import streamlit as st
import math
import plotly.graph_objects as go
def round_decimals_down(number: float, decimals: int = 2):
"""
Returns a value rounded down to a specific number of decimal places.
"""
if not isinstance(decimals, int):
raise TypeError("decimal places must be an integer")
elif decimals < 0:
raise ValueError("decimal places has to be 0 or more")
elif decimals == 0:
return math.ceil(number)
factor = 10 ** decimals
return math.floor(number * factor) / factor
def create_plotly_table(data):
fig = go.Figure(
data=[
go.Table(
header=dict(
values=list(data.keys()),
line_color="white",
fill_color="white",
font=dict(size=12, color="black"),
align="left",
),
cells=dict(
values=[data.get(k) for k in data.keys()],
align="left",
fill=dict(color=[["#F9F9F9", "#FFFFFF"] * 5]),
),
)
]
)
fig.update_layout(
autosize=False,
height=150,
margin=dict(
l=20,
r=20,
b=10,
t=30,
),
)
st.write(fig)
def local_css(file_name):
with open(file_name) as f:
st.markdown("<style>{}</style>".format(f.read()), unsafe_allow_html=True)
def percentage_format(x):
return f"{x:.0%}"