Added total score to CSV

This commit is contained in:
Bobby Abellana 2025-02-03 22:14:12 -08:00
parent b6c6518ad4
commit e1d59411fa
No known key found for this signature in database
GPG Key ID: 647714CC45F3647B

View File

@ -1,7 +1,7 @@
import csv import csv
import os import os
# Get the absolute path to the `data/metrics/` directory (outside `src/`) # Define the directory and generic CSV file path
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) # Go two levels up BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) # Go two levels up
METRICS_DIR = os.path.join(BASE_DIR, "data", "metrics") METRICS_DIR = os.path.join(BASE_DIR, "data", "metrics")
CSV_FILE = os.path.join(METRICS_DIR, "stock_scores.csv") CSV_FILE = os.path.join(METRICS_DIR, "stock_scores.csv")
@ -12,11 +12,17 @@ def append_scores_to_csv(symbol, scores):
Args: Args:
symbol (str): Stock ticker symbol. symbol (str): Stock ticker symbol.
scores (dict): Dictionary of metric scores (e.g., C_Score, Sales_Score, etc.). scores (dict): Dictionary of metric scores (e.g., EPS_Score, Sales_Score, Annual_EPS_Score, etc.).
""" """
# Ensure the directory exists # Ensure the directory exists
os.makedirs(METRICS_DIR, exist_ok=True) os.makedirs(METRICS_DIR, exist_ok=True)
# Compute the total score (sum of all numeric values in scores)
total_score = sum(scores.values())
# Include `Total_Score` in the scores dictionary
scores["Total_Score"] = total_score
# Define the header dynamically based on the provided scores # Define the header dynamically based on the provided scores
headers = ["Symbol"] + list(scores.keys()) headers = ["Symbol"] + list(scores.keys())