aboutsummaryrefslogtreecommitdiff
path: root/utils/salary_visualization.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/salary_visualization.py')
-rw-r--r--utils/salary_visualization.py45
1 files changed, 34 insertions, 11 deletions
diff --git a/utils/salary_visualization.py b/utils/salary_visualization.py
index 311e3c2..2a826b5 100644
--- a/utils/salary_visualization.py
+++ b/utils/salary_visualization.py
@@ -1,19 +1,29 @@
"""
A file that will visualize salary data from an incoming CSV.
+
+This script reads a CSV file containing salary data and visualizes it using
+plotly.
"""
import locale
+from pandas import read_csv as pd_read_csv
import pandas as pd
import plotly.graph_objs as go
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
-df = pd.read_csv('~/git/cleberg.net/static/salary.csv')
+# Read the CSV file
+df = pd_read_csv('~/git/cleberg.net/theme/static/salary.csv')
-# Function to format salary as US currency
-def format_currency(value):
+def format_currency(value: float) -> str:
"""
Format values in USD currency format.
+
+ Args:
+ value (float): The value to be formatted.
+
+ Returns:
+ str: The formatted value.
"""
return f"${value:,.2f}"
@@ -23,25 +33,37 @@ df = df.iloc[::-1].reset_index(drop=True)
# Calculate the percentage increase
df['Percentage Increase'] = df['Salary'].pct_change() * 100
-# Initialize the plot
-fig = go.Figure()
+def create_trace(row: pd.Series) -> go.Scatter:
+ """
+ Create a scatter plot trace for a single row.
-# Adding each data point as a separate trace to display the text
-for index, row in df.iterrows():
- TITLE_COMPANY = f"{row['Title']} ({row['Company']})"
+ Args:
+ row (pd.Series): The row to be plotted.
+
+ Returns:
+ go.Scatter: The created scatter plot trace.
+ """
+ title_company = f"{row['Title']} ({row['Company']})"
salary_formatted = format_currency(row['Salary'])
if pd.notna(row['Percentage Increase']):
text = f"{salary_formatted} ({row['Percentage Increase']:.2f}%)"
else:
text = salary_formatted
- fig.add_trace(go.Scatter(
+ return go.Scatter(
x=[row['Start'], row['End']],
y=[row['Salary'], row['Salary']],
text=[text],
mode='lines+text',
- name=TITLE_COMPANY,
+ name=title_company,
textposition='top center'
- ))
+ )
+
+# Initialize the plot
+fig = go.Figure()
+
+# Add each data point as a separate trace to display the text
+for index, row in df.iterrows():
+ fig.add_trace(create_trace(row))
# Update visual styles of the figure
fig.update_layout(
@@ -60,4 +82,5 @@ fig.update_layout(
height=800
)
+# Display the plot
fig.show()