|
29 | 29 | fred = Fred(api_key=apikey) |
30 | 30 | print("FRED object initialized.") |
31 | 31 |
|
| 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 | + |
32 | 44 | # 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) |
38 | 50 |
|
39 | 51 | # Create helper function to fetch recessions |
40 | 52 | 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_ |
132 | 144 | ) |
133 | 145 |
|
134 | 146 | # 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") |
136 | 148 | print(f"Attempting to write HTML to: {html_file_path}") # New log |
137 | 149 | fig.write_html( |
138 | 150 | 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_ |
273 | 285 | # Save data |
274 | 286 |
|
275 | 287 | 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 |
277 | 289 | print(f"Attempting to write CSV to: {csv_path_absolute}") # New log |
278 | 290 | # csv_path = "../../static/dashboard/unemployment_rate.csv" |
279 | 291 | 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_ |
315 | 327 | # Save data |
316 | 328 |
|
317 | 329 | 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 |
319 | 331 | print(f"Attempting to write CSV to: {csv_path_absolute}") # New log |
320 | 332 | # csv_path = "../../static/dashboard/vacancy_rate.csv" |
321 | 333 | 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_ |
357 | 369 | # Save data |
358 | 370 |
|
359 | 371 | 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 |
361 | 373 | print(f"Attempting to write CSV to: {csv_path_absolute}") # New log |
362 | 374 | # csv_path = "../../static/dashboard/labor_market_tightness.csv" |
363 | 375 | 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_ |
493 | 505 | # Save data |
494 | 506 |
|
495 | 507 | 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 |
497 | 509 | print(f"Attempting to write CSV to: {csv_path_absolute}") # New log |
498 | 510 | # csv_path = "../../static/dashboard/feru.csv" |
499 | 511 | 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_ |
521 | 533 | # Save data |
522 | 534 |
|
523 | 535 | 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 |
525 | 537 | print(f"Attempting to write CSV to: {csv_path_absolute}") # New log |
526 | 538 | # csv_path = "../../static/dashboard/unemployment_gap.csv" |
527 | 539 | 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_ |
549 | 561 | # Save data |
550 | 562 |
|
551 | 563 | 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 |
553 | 565 | print(f"Attempting to write CSV to: {csv_path_absolute}") # New log |
554 | 566 | # csv_path = "../../static/dashboard/recession_indicator.csv" |
555 | 567 | 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_ |
577 | 589 | # Save data |
578 | 590 |
|
579 | 591 | 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 |
581 | 593 | print(f"Attempting to write CSV to: {csv_path_absolute}") # New log |
582 | 594 | # csv_path = "../../static/dashboard/recession_probability.csv" |
583 | 595 | df_out = df.copy() |
|
0 commit comments