| @@ -10,10 +10,11 @@ from pandas import read_csv as pd_read_csv |
| 10 | import pandas as pd |
10 | import pandas as pd |
| 11 | import plotly.graph_objs as go |
11 | import plotly.graph_objs as go |
| 12 | |
12 | |
| 13 | locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') |
13 | locale.setlocale(locale.LC_ALL, "en_US.UTF-8") |
| 14 | |
14 | |
| 15 | # Read the CSV file |
15 | # Read the CSV file |
| 16 | df = pd_read_csv('~/git/cleberg.net/theme/static/salary.csv') |
16 | df = pd_read_csv("~/git/cleberg.net/theme/static/salary.csv") |
| |
17 | |
| 17 | |
18 | |
| 18 | def format_currency(value: float) -> str: |
19 | def format_currency(value: float) -> str: |
| 19 | """ |
20 | """ |
| @@ -27,11 +28,13 @@ def format_currency(value: float) -> str: |
| 27 | """ |
28 | """ |
| 28 | return f"${value:,.2f}" |
29 | return f"${value:,.2f}" |
| 29 | |
30 | |
| |
31 | |
| 30 | # Reverse the order of the DataFrame |
32 | # Reverse the order of the DataFrame |
| 31 | df = df.iloc[::-1].reset_index(drop=True) |
33 | df = df.iloc[::-1].reset_index(drop=True) |
| 32 | |
34 | |
| 33 | # Calculate the percentage increase |
35 | # Calculate the percentage increase |
| 34 | df['Percentage Increase'] = df['Salary'].pct_change() * 100 |
36 | df["Percentage Increase"] = df["Salary"].pct_change() * 100 |
| |
37 | |
| 35 | |
38 | |
| 36 | def create_trace(row: pd.Series) -> go.Scatter: |
39 | def create_trace(row: pd.Series) -> go.Scatter: |
| 37 | """ |
40 | """ |
| @@ -44,20 +47,21 @@ def create_trace(row: pd.Series) -> go.Scatter: |
| 44 | go.Scatter: The created scatter plot trace. |
47 | go.Scatter: The created scatter plot trace. |
| 45 | """ |
48 | """ |
| 46 | title_company = f"{row['Title']} ({row['Company']})" |
49 | title_company = f"{row['Title']} ({row['Company']})" |
| 47 | salary_formatted = format_currency(row['Salary']) |
50 | salary_formatted = format_currency(row["Salary"]) |
| 48 | if pd.notna(row['Percentage Increase']): |
51 | if pd.notna(row["Percentage Increase"]): |
| 49 | text = f"{salary_formatted} ({row['Percentage Increase']:.2f}%)" |
52 | text = f"{salary_formatted} ({row['Percentage Increase']:.2f}%)" |
| 50 | else: |
53 | else: |
| 51 | text = salary_formatted |
54 | text = salary_formatted |
| 52 | return go.Scatter( |
55 | return go.Scatter( |
| 53 | x=[row['Start'], row['End']], |
56 | x=[row["Start"], row["End"]], |
| 54 | y=[row['Salary'], row['Salary']], |
57 | y=[row["Salary"], row["Salary"]], |
| 55 | text=[text], |
58 | text=[text], |
| 56 | mode='lines+text', |
59 | mode="lines+text", |
| 57 | name=title_company, |
60 | name=title_company, |
| 58 | textposition='top center' |
61 | textposition="top center", |
| 59 | ) |
62 | ) |
| 60 | |
63 | |
| |
64 | |
| 61 | # Initialize the plot |
65 | # Initialize the plot |
| 62 | fig = go.Figure() |
66 | fig = go.Figure() |
| 63 | |
67 | |
| @@ -70,16 +74,16 @@ fig.update_layout( |
| 70 | title="Salary Data Over Time (annualized)", |
74 | title="Salary Data Over Time (annualized)", |
| 71 | xaxis_title="Time", |
75 | xaxis_title="Time", |
| 72 | yaxis_title="Salary", |
76 | yaxis_title="Salary", |
| 73 | font={"family": 'monospace', "size": 16}, |
77 | font={"family": "monospace", "size": 16}, |
| 74 | margin={"l": 50, "r": 50, "t": 50, "b": 100}, |
78 | margin={"l": 50, "r": 50, "t": 50, "b": 100}, |
| 75 | legend={ |
79 | legend={ |
| 76 | "orientation": 'h', |
80 | "orientation": "h", |
| 77 | "yanchor": 'top', |
81 | "yanchor": "top", |
| 78 | "y": -0.3, |
82 | "y": -0.3, |
| 79 | "xanchor": 'center', |
83 | "xanchor": "center", |
| 80 | "x": 0.5 |
84 | "x": 0.5, |
| 81 | }, |
85 | }, |
| 82 | height=800 |
86 | height=800, |
| 83 | ) |
87 | ) |
| 84 | |
88 | |
| 85 | # Display the plot |
89 | # Display the plot |