From 48fe6ca96e4a056f17e7ffeb596289892893413a Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sun, 20 Oct 2024 18:41:45 +0200 Subject: [PATCH] update metrics page --- .../{+page.server.ts => +layout.server.ts} | 56 +- .../stocks/[tickerID]/metrics/+layout.svelte | 59 +- .../stocks/[tickerID]/metrics/+page.svelte | 233 ++++++-- .../[tickerID]/metrics/[slug]/+page.svelte | 515 +++++++++--------- 4 files changed, 508 insertions(+), 355 deletions(-) rename src/routes/stocks/[tickerID]/metrics/{+page.server.ts => +layout.server.ts} (72%) diff --git a/src/routes/stocks/[tickerID]/metrics/+page.server.ts b/src/routes/stocks/[tickerID]/metrics/+layout.server.ts similarity index 72% rename from src/routes/stocks/[tickerID]/metrics/+page.server.ts rename to src/routes/stocks/[tickerID]/metrics/+layout.server.ts index 0762cadb..ad2577e0 100644 --- a/src/routes/stocks/[tickerID]/metrics/+page.server.ts +++ b/src/routes/stocks/[tickerID]/metrics/+layout.server.ts @@ -1,28 +1,28 @@ -export const load = async ({ locals, params }) => { - const getAnalystEstimate = async () => { - const { apiURL, apiKey } = locals; - - const postData = { - ticker: params.tickerID, - }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/analyst-estimate", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - const output = await response.json(); - - return output; - }; - - // Make sure to return a promise - return { - getAnalystEstimate: await getAnalystEstimate(), - }; -}; +export const load = async ({ locals, params }) => { + const getBusinessMetrics = async () => { + const { apiURL, apiKey } = locals; + + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/business-metrics", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getBusinessMetrics: await getBusinessMetrics(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/metrics/+layout.svelte b/src/routes/stocks/[tickerID]/metrics/+layout.svelte index c6d45ea7..8fa622d9 100644 --- a/src/routes/stocks/[tickerID]/metrics/+layout.svelte +++ b/src/routes/stocks/[tickerID]/metrics/+layout.svelte @@ -1,27 +1,31 @@ -
+
-
-
    +
    + diff --git a/src/routes/stocks/[tickerID]/metrics/+page.svelte b/src/routes/stocks/[tickerID]/metrics/+page.svelte index c2911958..04cf202a 100644 --- a/src/routes/stocks/[tickerID]/metrics/+page.svelte +++ b/src/routes/stocks/[tickerID]/metrics/+page.svelte @@ -1,24 +1,54 @@ @@ -28,54 +58,105 @@ {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} {$displayCompanyName} ({$stockTicker}) Business Metric Overview · stocknear - - - + + + - - + + -
    +
    -
    +
    {#if data?.getAnalystEstimate?.length !== 0} +

    + {$displayCompanyName} Revenue Breakdown +

    -

    {$displayCompanyName} Revenue Breakdown

    - -
    - +
    +
    - + {#each xData as item} - + {/each} - {#each categories as category, index} + {#each revenueNames as name, index} - + {#each categoryValues[index] as value} - {/each} - {#each growthValues[index] as growthValue} - {/each} @@ -84,42 +165,66 @@
    QuarterQuarter{new Date(item ?? null)?.toLocaleString('en-US', { - month: 'short', - day: 'numeric', - year: 'numeric', - })}{new Date(item ?? null)?.toLocaleString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + })}
    {category} Revenue + + {name} Revenue + + {abbreviateNumber(value)}
    - {category} Revenue Growth + + {name} Revenue Growth - {growthValue > 0 ? '+' : ''}{growthValue !== null ? growthValue?.toFixed(2) + '%' : '-'} + + {growthValue > 0 ? "+" : ""}{growthValue !== null + ? growthValue?.toFixed(2) + "%" + : "-"}
    +

    + Revenue by Geography +

    - - -

    Revenue by Geography

    - -
    - +
    +
    - + {#each geographicXData as item} - + {/each} - {#each geographicCategories as category, index} + {#each geographicNames as name, index} - + {#each geographiCategoryValues[index] as value} - {/each} - {#each geographicGrowthValues[index] as growthValue} - {/each} @@ -128,9 +233,21 @@
    QuarterQuarter{new Date(item ?? null)?.toLocaleString('en-US', { - month: 'short', - day: 'numeric', - year: 'numeric', - })}{new Date(item ?? null)?.toLocaleString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + })}
    {category} Revenue{name} Revenue + {abbreviateNumber(value)}
    - {category} Revenue Growth + + {name} Revenue Growth - {growthValue > 0 ? '+' : ''}{growthValue !== null ? growthValue?.toFixed(2) + '%' : '-'} + + {growthValue > 0 ? "+" : ""}{growthValue !== null + ? growthValue?.toFixed(2) + "%" + : "-"}
    {:else} -
    - - +
    + +

    No estimates available.

    diff --git a/src/routes/stocks/[tickerID]/metrics/[slug]/+page.svelte b/src/routes/stocks/[tickerID]/metrics/[slug]/+page.svelte index cacf8191..0c6714c7 100644 --- a/src/routes/stocks/[tickerID]/metrics/[slug]/+page.svelte +++ b/src/routes/stocks/[tickerID]/metrics/[slug]/+page.svelte @@ -1,283 +1,292 @@ - - - - - - - {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} {$displayCompanyName} ({$stockTicker}) Revenue Breakdown · stocknear - - - - - - - - + + + + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} + {$displayCompanyName} ({$stockTicker}) Revenue Breakdown · stocknear + + + + + + + + - -
    -
    -
    - - {#if isLoaded} -
    -
    -
    -

    - {convertToTitleCase(data?.getParams)} Revenue -

    -
    - - {#if rawData?.length !== 0} -
    - - - -
    - -
    - - -

    - History -

    - - - - -
    - - - - - - - - - - {#each tableList as item, index} - - - - - - - - - - - {/each} - - -
    QuarterValue% Change
    - {new Date(item?.date ?? null)?.toLocaleString('en-US', { - month: 'short', - day: 'numeric', - year: 'numeric', - })} - - {abbreviateNumber(item?.value)} - - {#if item?.valueGrowth > 0} - - +{(item?.valueGrowth)?.toFixed(2)}% - - {:else if item?.valueGrowth < 0} - - {(item?.valueGrowth)?.toFixed(2)}% - - {:else} - - - {/if} -
    - - -
    - - - - -
    - - {:else} -

    - No data available -

    - {/if} - -
    - -
    - {:else} -
    -
    - -
    -
    - {/if} +
    +
    +
    + {#if isLoaded} +
    +
    +
    +

    + {convertToTitleCase(data?.getParams)} Revenue +

    + + {#if rawData?.length !== 0} +
    +
    + +
    + +

    History

    + +
    + + + + + + + + + + {#each tableList as item, index} + + + + + + + + + {/each} + +
    QuarterValue% Change
    + {new Date(item?.date ?? null)?.toLocaleString( + "en-US", + { + month: "short", + day: "numeric", + year: "numeric", + }, + )} + + {abbreviateNumber(item?.value)} + + {#if item?.valueGrowth > 0} + + +{item?.valueGrowth?.toFixed(2)}% + + {:else if item?.valueGrowth < 0} + + {item?.valueGrowth?.toFixed(2)}% + + {:else} + - + {/if} +
    +
    +
    + {:else} +

    + No data available +

    + {/if} +
    +
    + {:else} +
    +
    + +
    -
    - - + {/if} +
    +
    +
    - + \ No newline at end of file + .chart { + width: 100%; + } +