update forecast overview page

This commit is contained in:
MuslemRahimi 2024-08-31 15:56:19 +02:00
parent 04e4c12560
commit 2e6f640b0e
2 changed files with 10 additions and 51 deletions

View File

@ -50,36 +50,6 @@ function findIndex(data) {
let tableDataActual = [];
let tableDataForecast = [];
const getAnalystEstimate = async (ticker) => {
// Get cached data for the specific tickerID
const cachedData = getCache(ticker, "getAnalystEstimate");
if (cachedData) {
analystEstimateList = cachedData;
} else {
const postData = { ticker: ticker };
const response = await fetch(data?.apiURL + "/analyst-estimate", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": data?.apiKey,
},
body: JSON.stringify(postData),
});
analystEstimateList = await response?.json();
analystEstimateList = analystEstimateList?.filter((item) => !item.date.toString().startsWith("19"));
// Cache the data for this specific tickerID with a specific name 'getAnalystEstimate'
setCache(ticker, analystEstimateList, "getAnalystEstimate");
}
if (analystEstimateList?.length !== 0) {
$analystEstimateComponent = true;
} else {
$analystEstimateComponent = false;
}
};
function getPlotOptions() {
let dates = [];
@ -289,17 +259,15 @@ function findIndex(data) {
$: {
if ($stockTicker && displayData && typeof window !== "undefined") {
isLoaded = false;
const asyncFunctions = [getAnalystEstimate($stockTicker)];
Promise.all(asyncFunctions)
.then((results) => {
//prepareData(analystEstimateList)
optionsData = getPlotOptions();
prepareData();
})
.catch((error) => {
console.error("An error occurred:", error);
});
analystEstimateList = [];
analystEstimateList = data?.getAnalystEstimate || [];
if (analystEstimateList?.length !== 0) {
$analystEstimateComponent = true;
optionsData = getPlotOptions();
prepareData();
} else {
$analystEstimateComponent = false;
}
isLoaded = true;
}
}

View File

@ -1,18 +1,9 @@
<script lang="ts">
import { numberOfUnreadNotification, displayCompanyName, stockTicker, analystEstimateComponent } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from "$lib/components/InfoModal.svelte";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core";
import { LineChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
export let data;
use([LineChart, GridComponent, TooltipComponent, CanvasRenderer]);
function findIndex(data) {
const currentYear = new Date().getFullYear();
return data.findIndex(item => item.date >= currentYear && item.revenue === null);
@ -136,7 +127,7 @@ const changeEPS = abbreviateNumber(((data?.getAnalystEstimate[index-1]?.estimate
</div>
</div>
</div>
</div>