From af67492e1106519fc86e9d72d001f4d27213400f Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Fri, 29 Nov 2024 01:05:45 +0100 Subject: [PATCH] bugfixing --- src/lib/components/AnalystEstimate.svelte | 53 ++++++++++++++++++----- src/routes/options-flow/+page.ts | 46 -------------------- 2 files changed, 43 insertions(+), 56 deletions(-) delete mode 100644 src/routes/options-flow/+page.ts diff --git a/src/lib/components/AnalystEstimate.svelte b/src/lib/components/AnalystEstimate.svelte index d6602391..accf3a5b 100644 --- a/src/lib/components/AnalystEstimate.svelte +++ b/src/lib/components/AnalystEstimate.svelte @@ -173,6 +173,8 @@ let tableForecastRevenue = []; let tableForecastEPS = []; + let tableCombinedRevenue = []; + let tableCombinedEPS = []; function getPlotOptions(dataType: string) { let dates = []; @@ -534,6 +536,8 @@ function prepareData() { tableActualRevenue = []; tableForecastRevenue = []; + tableCombinedRevenue = []; + tableCombinedEPS = []; tableActualEPS = []; tableForecastEPS = []; @@ -558,6 +562,20 @@ }); }); + tableCombinedRevenue = tableActualRevenue?.map((item1) => { + // Find the corresponding item in data2 based on "FY" + const item2 = tableForecastRevenue?.find( + (item2) => item2?.FY === item1?.FY, + ); + + // If the value in data1 is null, replace it with the value from data2 + return { + FY: item1.FY, + val: item1.val === null ? item2.val : item1.val, + numOfAnalysts: item2.numOfAnalysts, + }; + }); + //EPS Data filteredData?.forEach((item) => { tableActualEPS?.push({ @@ -572,10 +590,21 @@ //Values coincide with table values for crosscheck revenueAvgGrowthList = computeGrowthList( tableActualRevenue, - tableForecastRevenue, + tableCombinedRevenue, ); - epsAvgGrowthList = computeGrowthList(tableActualEPS, tableForecastEPS); + tableCombinedEPS = tableActualEPS?.map((item1) => { + // Find the corresponding item in data2 based on "FY" + const item2 = tableForecastEPS?.find((item2) => item2?.FY === item1?.FY); + + // If the value in data1 is null, replace it with the value from data2 + return { + FY: item1.FY, + val: item1.val === null ? item2.val : item1.val, + }; + }); + + epsAvgGrowthList = computeGrowthList(tableActualEPS, tableCombinedEPS); } $: { @@ -630,7 +659,7 @@ > Revenue - {#each tableForecastRevenue as item} + {#each tableCombinedRevenue as item} @@ -649,7 +678,7 @@ > Revenue Growth - {#each computeGrowthList(tableActualRevenue, tableForecastRevenue) as item, index} + {#each computeGrowthList(tableActualRevenue, tableCombinedRevenue) as item, index} @@ -684,7 +713,7 @@ > EPS - {#each tableForecastEPS as item} + {#each tableCombinedEPS as item} @@ -703,7 +732,7 @@ > EPS Growth - {#each computeGrowthList(tableActualEPS, tableForecastEPS) as item, index} + {#each computeGrowthList(tableActualEPS, tableCombinedEPS) as item, index} @@ -756,13 +785,17 @@ class="text-white whitespace-nowrap text-sm sm:text-[1rem] text-start font-medium bg-[#27272A] border-b border-[#27272A]" >No. Analysts - {#each tableForecastRevenue as item} + {#each tableCombinedRevenue as item} - {item?.numOfAnalysts === (null || 0) - ? "n/a" - : item?.numOfAnalysts} + {#if item?.FY > 24} + {item?.numOfAnalysts === (null || 0) + ? "n/a" + : item?.numOfAnalysts} + {:else} + - + {/if} {/each} diff --git a/src/routes/options-flow/+page.ts b/src/routes/options-flow/+page.ts deleted file mode 100644 index 2dc6fe35..00000000 --- a/src/routes/options-flow/+page.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { isOpen } from "$lib/store"; - -const checkMarketHour = async () => { - const holidays = [ - "2024-01-01", - "2024-01-15", - "2024-02-19", - "2024-03-29", - "2024-05-27", - "2024-06-19", - "2024-07-04", - "2024-09-02", - "2024-11-28", - "2024-12-25", - ]; - const currentDate = new Date().toISOString().split("T")[0]; - - // Get the current time in the ET time zone - const etTimeZone = "America/New_York"; - const currentTime = new Date().toLocaleString("en-US", { - timeZone: etTimeZone, - }); - - // Determine if the NYSE is currently open or closed - const currentHour = new Date(currentTime).getHours(); - const isWeekendValue = - new Date(currentTime).getDay() === 6 || - new Date(currentTime).getDay() === 0; - const isBeforeMarketOpenValue = - currentHour < 9 || - (currentHour === 9 && new Date(currentTime).getMinutes() < 30); - const isAfterMarketCloseValue = currentHour >= 16; - - isOpen.set( - !( - isWeekendValue || - isBeforeMarketOpenValue || - isAfterMarketCloseValue || - holidays?.includes(currentDate) - ) - ); -}; - -export const load = async () => { - await checkMarketHour(); -};