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 tableDataActual = [];
let tableDataForecast = []; 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() { function getPlotOptions() {
let dates = []; let dates = [];
@ -289,17 +259,15 @@ function findIndex(data) {
$: { $: {
if ($stockTicker && displayData && typeof window !== "undefined") { if ($stockTicker && displayData && typeof window !== "undefined") {
isLoaded = false; isLoaded = false;
analystEstimateList = [];
const asyncFunctions = [getAnalystEstimate($stockTicker)]; analystEstimateList = data?.getAnalystEstimate || [];
Promise.all(asyncFunctions) if (analystEstimateList?.length !== 0) {
.then((results) => { $analystEstimateComponent = true;
//prepareData(analystEstimateList) optionsData = getPlotOptions();
optionsData = getPlotOptions(); prepareData();
prepareData(); } else {
}) $analystEstimateComponent = false;
.catch((error) => { }
console.error("An error occurred:", error);
});
isLoaded = true; isLoaded = true;
} }
} }

View File

@ -1,17 +1,8 @@
<script lang="ts"> <script lang="ts">
import { numberOfUnreadNotification, displayCompanyName, stockTicker, analystEstimateComponent } from "$lib/store"; import { numberOfUnreadNotification, displayCompanyName, stockTicker, analystEstimateComponent } from "$lib/store";
import { abbreviateNumber } from "$lib/utils"; 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; export let data;
use([LineChart, GridComponent, TooltipComponent, CanvasRenderer]);
function findIndex(data) { function findIndex(data) {
const currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();