From cbe718ab6b8ac12c487f1e3fe4e0dc597578f5c6 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 2 Dec 2024 13:45:20 +0100 Subject: [PATCH] bugfixing --- src/lib/components/RatingsChart.svelte | 544 ++++++++++++++++++ src/routes/analysts/[slug]/+page.svelte | 58 +- .../afterhours/gainers/+page.svelte | 19 +- .../afterhours/losers/+page.svelte | 19 +- .../premarket/gainers/+page.svelte | 21 +- .../premarket/losers/+page.svelte | 21 +- 6 files changed, 674 insertions(+), 8 deletions(-) create mode 100644 src/lib/components/RatingsChart.svelte diff --git a/src/lib/components/RatingsChart.svelte b/src/lib/components/RatingsChart.svelte new file mode 100644 index 00000000..217095f4 --- /dev/null +++ b/src/lib/components/RatingsChart.svelte @@ -0,0 +1,544 @@ + + +
+ + +
+
+
+
+
+

+ Economic Indicators +

+
+ + {#if isLoaded} +
+ + Real-time and historical data on key economic indicators like GDP, + unemployment, and inflation, essential for tracking economic performance + and growth trends. +
+ +
+

+ Federal Fund Rate +

+ +
+ The federal funds rate is the interest rate at which banks lend + to each other overnight to maintain reserve balances. It's a + critical tool for U.S. monetary policy, influencing borrowing + costs for consumers and businesses, economic growth, and + inflation. Changes in the federal funds rate affect everything + from loan interest rates to stock market performance, making it + a key indicator of economic health. +
+ + +
+ +
+
+ +

+ Consumer Price Index (CPI) +

+ +
+ The CPI measures the average change in prices for a typical + basket of goods. It's key for tracking inflation, affecting + interest rates, wages, and business decisions. Rising CPI + indicates inflation, impacting purchasing power and the overall + economy. +
+ + +
+ +
+
+ +

+ Gross Domestic Product (GDP) +

+ +
+ The GDP measures a country's economic performance, representing + the total value of all goods and services produced within a + specific period. It's a key indicator of economic health, used + to compare the economic output of different nations and track + growth or decline over time. +
+ + +
+ +
+
+ +

+ Unemployment Rate vs Inflation Rate +

+ +
+ The unemployment rate measures the jobless percentage in the + labor force, impacting spending and growth. Low unemployment + boosts wages and activity, while high unemployment slows them. + The inflation rate tracks price increases, with moderate + inflation (~2%) being healthy. These rates are often inversely + related and crucial for economic stability, influencing + spending, savings, and investment. +
+ + +
+ +
+
+ +

+ Treasury Rates +

+ +
+ Treasury rates are the interest rates that the US government + pays on its debt obligations, and they are a key benchmark for + interest rates across the economy. +
+ +
+
+ +
+
+ +
+ +
+
+ +
+ {#each tabs as item, i} + + {/each} +
+ +
+ + + + + + + + + + + + + + + + + + + + {#each tableList as item} + + + + + + + + + + + + + + + + + {/each} + +
Date1-Month2-Month3-Month6-Month1-Year2-Year3-Year5-Year7-Year10-Year20-Year30-Year
+ {item?.date} + + {item?.month1} + + {item?.month2 !== null ? item?.month2 : "-"} + + {item?.month3} + + {item?.month6} + + {item?.year1} + + {item?.year2} + + {item?.year3} + + {item?.year5} + + {item?.year7} + + {item?.year10} + + {item?.year20} + + {item?.year30} +
+
+
+ {:else} +
+
+ +
+
+ {/if} +
+ +
+
+
+
+ + diff --git a/src/routes/analysts/[slug]/+page.svelte b/src/routes/analysts/[slug]/+page.svelte index e3f66567..1d738b30 100644 --- a/src/routes/analysts/[slug]/+page.svelte +++ b/src/routes/analysts/[slug]/+page.svelte @@ -8,11 +8,11 @@ let analystStats = data?.getAnalystStats; - let rawData = data?.getAnalystStats?.ratingsList; + let rawData = processTickerData(data?.getAnalystStats?.ratingsList); let originalData = [...rawData]; // Unaltered copy of raw data let stockList = rawData?.slice(0, 50) ?? []; - console.log(rawData); + let analystScore = analystStats?.analystScore; let rank = analystStats?.rank; let analystName = analystStats?.analystName; @@ -26,6 +26,34 @@ }).format(analystStats?.numOfAnalysts); let numOfStocks = analystStats?.numOfStocks; + function processTickerData(data) { + const tickerMap = new Map(); + + data.forEach((item) => { + const { ticker, date } = item; + + if (!ticker) return; // Skip if ticker is not defined + + if (!tickerMap.has(ticker)) { + // Add the item and initialize count + tickerMap.set(ticker, { ...item, ratings: 1 }); + } else { + const existing = tickerMap.get(ticker); + + // Increment the ratings count + existing.ratings += 1; + + // Keep the item with the latest date + if (new Date(item.date) > new Date(existing.date)) { + tickerMap.set(ticker, { ...item, ratings: existing.ratings }); + } + } + }); + + // Convert the Map back to an array + return Array.from(tickerMap.values()); + } + async function handleScroll() { const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height const isBottom = window.innerHeight + window.scrollY >= scrollThreshold; @@ -47,21 +75,25 @@ $: charNumber = $screenWidth < 640 ? 20 : 40; let columns = [ + { key: "chart", label: "", align: "right" }, { key: "ticker", label: "Name", align: "left" }, { key: "rating_current", label: "Action", align: "left" }, { key: "adjusted_pt_current", label: "Price Target", align: "right" }, { key: "price", label: "Current", align: "right" }, { key: "upside", label: "% Upside", align: "right" }, + { key: "ratings", label: "Ratings", align: "right" }, { key: "date", label: "Updated", align: "right" }, ]; let sortOrders = { + chart: { order: "none", type: "string" }, ticker: { order: "none", type: "string" }, rating_current: { order: "none", type: "string" }, adjusted_pt_current: { order: "none", type: "number" }, marketCap: { order: "none", type: "number" }, price: { order: "none", type: "number" }, upside: { order: "none", type: "number" }, + ratings: { order: "none", type: "number" }, date: { order: "none", type: "date" }, }; @@ -346,6 +378,22 @@ + + @@ -477,6 +525,12 @@ {item?.upside !== null ? item?.upside + "%" : "n/a"} + + {item?.ratings !== null ? item?.ratings : "n/a"} + + diff --git a/src/routes/market-mover/afterhours/gainers/+page.svelte b/src/routes/market-mover/afterhours/gainers/+page.svelte index 93413b43..788696dc 100644 --- a/src/routes/market-mover/afterhours/gainers/+page.svelte +++ b/src/routes/market-mover/afterhours/gainers/+page.svelte @@ -20,4 +20,21 @@ ]; - +{#if rawData?.length > 0} +
+{:else} +
+ + Currently no afterhours data is available yet! +
+{/if} diff --git a/src/routes/market-mover/afterhours/losers/+page.svelte b/src/routes/market-mover/afterhours/losers/+page.svelte index 93413b43..788696dc 100644 --- a/src/routes/market-mover/afterhours/losers/+page.svelte +++ b/src/routes/market-mover/afterhours/losers/+page.svelte @@ -20,4 +20,21 @@ ]; -
+{#if rawData?.length > 0} +
+{:else} +
+ + Currently no afterhours data is available yet! +
+{/if} diff --git a/src/routes/market-mover/premarket/gainers/+page.svelte b/src/routes/market-mover/premarket/gainers/+page.svelte index 7b34846c..5eee9fc8 100644 --- a/src/routes/market-mover/premarket/gainers/+page.svelte +++ b/src/routes/market-mover/premarket/gainers/+page.svelte @@ -2,7 +2,7 @@ import Table from "$lib/components/Table/Table.svelte"; export let data; - let rawData = data?.getMarketMover || []; + let rawData = data?.getMarketMover; const excludedRules = new Set([ "volume", @@ -20,4 +20,21 @@ ]; -
+{#if rawData?.length > 0} +
+{:else} +
+ + Currently no premarket data is available yet! +
+{/if} diff --git a/src/routes/market-mover/premarket/losers/+page.svelte b/src/routes/market-mover/premarket/losers/+page.svelte index 7b34846c..5eee9fc8 100644 --- a/src/routes/market-mover/premarket/losers/+page.svelte +++ b/src/routes/market-mover/premarket/losers/+page.svelte @@ -2,7 +2,7 @@ import Table from "$lib/components/Table/Table.svelte"; export let data; - let rawData = data?.getMarketMover || []; + let rawData = data?.getMarketMover; const excludedRules = new Set([ "volume", @@ -20,4 +20,21 @@ ]; -
+{#if rawData?.length > 0} +
+{:else} +
+ + Currently no premarket data is available yet! +
+{/if}