Skip to content

Commit 097c0ed

Browse files
committed
Update dashboard.py
1 parent de29244 commit 097c0ed

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

content/dashboard/dashboard.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,24 @@
2929
fred = Fred(api_key=apikey)
3030
print("FRED object initialized.")
3131

32+
# Get the absolute directory of the current script (e.g., .../content/dashboard/)
33+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
34+
35+
# Go up two levels to get to the repository root (from .../content/dashboard/ to .../)
36+
REPO_ROOT_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..'))
37+
38+
# Define the output directory relative to the repository root
39+
OUTPUT_DIR_ABSOLUTE = os.path.join(REPO_ROOT_DIR, 'static', 'dashboard')
40+
41+
print(f"Ensuring output directory exists: {OUTPUT_DIR_ABSOLUTE}") # New log
42+
os.makedirs(OUTPUT_DIR_ABSOLUTE, exist_ok=True)
43+
3244
# Ensure output directory exists
33-
# os.makedirs("../../static/dashboard", exist_ok=True)
34-
output_dir_relative = "../../static/dashboard"
35-
output_dir_absolute = os.path.abspath(output_dir_relative)
36-
print(f"Ensuring output directory exists: {output_dir_absolute}") # New log
37-
os.makedirs(output_dir_absolute, exist_ok=True)
45+
# # os.makedirs("../../static/dashboard", exist_ok=True)
46+
# output_dir_relative = "../../static/dashboard"
47+
# output_dir_absolute = os.path.abspath(output_dir_relative)
48+
# print(f"Ensuring output directory exists: {output_dir_absolute}") # New log
49+
# os.makedirs(output_dir_absolute, exist_ok=True)
3850

3951
# Create helper function to fetch recessions
4052
def get_recession_periods(rec_series):
@@ -132,7 +144,7 @@ def make_plot(df, y_column, title, filename, y_label, x_min=None, x_max=None, y_
132144
)
133145

134146
# In your make_plot function, before fig.write_html:
135-
html_file_path = os.path.join(output_dir_absolute, f"{filename}.html")
147+
html_file_path = os.path.join(OUTPUT_DIR_ABSOLUTE, f"{filename}.html")
136148
print(f"Attempting to write HTML to: {html_file_path}") # New log
137149
fig.write_html(
138150
html_file_path, # Use the absolute path
@@ -273,7 +285,7 @@ def make_plot(df, y_column, title, filename, y_label, x_min=None, x_max=None, y_
273285
# Save data
274286

275287
csv_filename = "unemployment_rate.csv"
276-
csv_path_absolute = os.path.join(output_dir_absolute, csv_filename) # Use absolute path
288+
csv_path_absolute = os.path.join(OUTPUT_DIR_ABSOLUTE, csv_filename) # Use absolute path
277289
print(f"Attempting to write CSV to: {csv_path_absolute}") # New log
278290
# csv_path = "../../static/dashboard/unemployment_rate.csv"
279291
df_out = df.copy()
@@ -315,7 +327,7 @@ def make_plot(df, y_column, title, filename, y_label, x_min=None, x_max=None, y_
315327
# Save data
316328

317329
csv_filename = "vacancy_rate.csv"
318-
csv_path_absolute = os.path.join(output_dir_absolute, csv_filename) # Use absolute path
330+
csv_path_absolute = os.path.join(OUTPUT_DIR_ABSOLUTE, csv_filename) # Use absolute path
319331
print(f"Attempting to write CSV to: {csv_path_absolute}") # New log
320332
# csv_path = "../../static/dashboard/vacancy_rate.csv"
321333
df_out = df.copy()
@@ -357,7 +369,7 @@ def make_plot(df, y_column, title, filename, y_label, x_min=None, x_max=None, y_
357369
# Save data
358370

359371
csv_filename = "labor_market_tightness.csv"
360-
csv_path_absolute = os.path.join(output_dir_absolute, csv_filename) # Use absolute path
372+
csv_path_absolute = os.path.join(OUTPUT_DIR_ABSOLUTE, csv_filename) # Use absolute path
361373
print(f"Attempting to write CSV to: {csv_path_absolute}") # New log
362374
# csv_path = "../../static/dashboard/labor_market_tightness.csv"
363375
df_out = df.copy()
@@ -493,7 +505,7 @@ def make_plot(df, y_column, title, filename, y_label, x_min=None, x_max=None, y_
493505
# Save data
494506

495507
csv_filename = "feru.csv"
496-
csv_path_absolute = os.path.join(output_dir_absolute, csv_filename) # Use absolute path
508+
csv_path_absolute = os.path.join(OUTPUT_DIR_ABSOLUTE, csv_filename) # Use absolute path
497509
print(f"Attempting to write CSV to: {csv_path_absolute}") # New log
498510
# csv_path = "../../static/dashboard/feru.csv"
499511
df_out = df.copy()
@@ -521,7 +533,7 @@ def make_plot(df, y_column, title, filename, y_label, x_min=None, x_max=None, y_
521533
# Save data
522534

523535
csv_filename = "unemployment_gap.csv"
524-
csv_path_absolute = os.path.join(output_dir_absolute, csv_filename) # Use absolute path
536+
csv_path_absolute = os.path.join(OUTPUT_DIR_ABSOLUTE, csv_filename) # Use absolute path
525537
print(f"Attempting to write CSV to: {csv_path_absolute}") # New log
526538
# csv_path = "../../static/dashboard/unemployment_gap.csv"
527539
df_out = df.copy()
@@ -549,7 +561,7 @@ def make_plot(df, y_column, title, filename, y_label, x_min=None, x_max=None, y_
549561
# Save data
550562

551563
csv_filename = "recession_indicator.csv"
552-
csv_path_absolute = os.path.join(output_dir_absolute, csv_filename) # Use absolute path
564+
csv_path_absolute = os.path.join(OUTPUT_DIR_ABSOLUTE, csv_filename) # Use absolute path
553565
print(f"Attempting to write CSV to: {csv_path_absolute}") # New log
554566
# csv_path = "../../static/dashboard/recession_indicator.csv"
555567
df_out = df.copy()
@@ -577,7 +589,7 @@ def make_plot(df, y_column, title, filename, y_label, x_min=None, x_max=None, y_
577589
# Save data
578590

579591
csv_filename = "recession_probability.csv"
580-
csv_path_absolute = os.path.join(output_dir_absolute, csv_filename) # Use absolute path
592+
csv_path_absolute = os.path.join(OUTPUT_DIR_ABSOLUTE, csv_filename) # Use absolute path
581593
print(f"Attempting to write CSV to: {csv_path_absolute}") # New log
582594
# csv_path = "../../static/dashboard/recession_probability.csv"
583595
df_out = df.copy()

0 commit comments

Comments
 (0)