Skip to content

2. Utils

2.1 utils

2.1.1 check_credentials()

Checks whether credentials are available in the session state.

This function verifies if the credentials are stored in the Streamlit session state. If available, it shows a success message for 3 seconds, and returns True. If not available, it shows a warning message and returns False.

Returns:

Name Type Description
bool bool

True if credentials are available, otherwise False.

Source code in src/utils/utils.py
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
def check_credentials() -> bool:
	"""
	Checks whether credentials are available in the session state.

	This function verifies if the credentials are stored in the Streamlit session state.
	If available, it shows a success message for 3 seconds, and returns True.
	If not available, it shows a warning message and returns False.

	Returns:
		bool: True if credentials are available, otherwise False.
	"""

	@st.cache_data
	def credentials_available():
		# Create an empty container that can be updated
		message_container = st.empty()

		# Show a success message
		message_container.success("Credentials available.", icon="🔐")

		# Wait for 3 seconds
		time.sleep(3)

		# Empty the message
		message_container.empty()

	if "credentials" in st.session_state and st.session_state.credentials:
		credentials_available()
		return True

	st.warning("Credentials not available.", icon="⚠️")
	return False

2.1.2 config_streamlit_page(page_name)

Configures the Streamlit page settings based on the given page name.

Parameters:

Name Type Description Default
page_name str

The name of the page that is being configured.

required
Source code in src/utils/utils.py
 7
 8
 9
10
11
12
13
14
15
16
def config_streamlit_page(page_name: str) -> None:
	"""
	Configures the Streamlit page settings based on the given page name.

	Args:
		page_name (str): The name of the page that is being configured.
	"""

	# Configure the title of the Streamlit page
	st.title(page_name)

2.1.3 obtain_top(df, top, column)

Obtain the top 'n' rows from a DataFrame based on a specific column.

Parameters:

Name Type Description Default
df DataFrame

The DataFrame containing the data.

required
top int

The number of top rows to return based on the column value.

required
column str

The column name to sort the data by to determine the top rows.

required

Returns:

Name Type Description
list list

A list of the top 'n' values from the specified column in the DataFrame.

Source code in src/utils/utils.py
53
54
55
56
57
58
59
60
61
62
63
64
65
def obtain_top(df: pd.DataFrame, top: int, column: str) -> list:
	"""Obtain the top 'n' rows from a DataFrame based on a specific column.

	Args:
		df: The DataFrame containing the data.
		top: The number of top rows to return based on the column value.
		column: The column name to sort the data by to determine the top rows.

	Returns:
		list: A list of the top 'n' values from the specified column in the DataFrame.
	"""

	return list(df[column].value_counts()[:top].index)