bugfixing: fundamental data

This commit is contained in:
MuslemRahimi 2024-06-11 09:54:55 +02:00
parent ecf6dd32de
commit 703ecdddaf
5 changed files with 49 additions and 123 deletions

View File

@ -49,6 +49,51 @@ export const validateData = async (formData, schema) => {
}
export function sumQuarterlyResultsByYear(quarterlyResults) {
const yearlySummaries = {};
const quarterCounts = {};
// Define a Set of keys to exclude
const excludeKeys = new Set(['weightedAverageShsOut', 'weightedAverageShsOutDil']);
// Iterate over each quarterly result
quarterlyResults?.forEach(quarter => {
// Extract year from the date
const year = new Date(quarter?.calendarYear)?.getFullYear();
// Initialize the year in summaries and quarter counts if not already present
if (!yearlySummaries[year]) {
yearlySummaries[year] = {
calendarYear: `${year}`, // Use end of the year date
};
quarterCounts[year] = 0;
}
// Increment the quarter count for the year
quarterCounts[year]++;
// Sum up the numeric fields for the year, excluding specific keys
Object?.keys(quarter)?.forEach(key => {
if (typeof quarter[key] === 'number' && !excludeKeys.has(key)) {
yearlySummaries[year][key] = (yearlySummaries[year][key] || 0) + quarter[key];
} else if (excludeKeys.has(key)) {
// Directly copy the last quarter value for these keys
yearlySummaries[year][key] = quarter[key];
}
});
});
// Filter out years with less than 4 quarters
const validYears = Object.keys(quarterCounts).filter(year => quarterCounts[year] === 4);
const annualResults = validYears.map(year => yearlySummaries[year]);
// Sort the results by year in descending order
annualResults.sort((a, b) => b?.calendarYear?.localeCompare(a?.calendarYear));
return annualResults;
}
export const sortPostsByDate = (posts) => {
return posts.sort(function(a, b) {

View File

@ -1,7 +1,7 @@
<script lang="ts">
import { Chart } from 'svelte-echarts'
import {numberOfUnreadNotification, displayCompanyName, stockTicker} from '$lib/store';
import { abbreviateNumber } from '$lib/utils';
import { abbreviateNumber,sumQuarterlyResultsByYear } from '$lib/utils';
import * as XLSX from 'xlsx';
export let data;
@ -396,36 +396,7 @@ $: {
}
// Function to sum up quarterly results by year
function sumQuarterlyResultsByYear(quarterlyResults) {
const yearlySummaries = {};
// Iterate over each quarterly result
quarterlyResults?.forEach(quarter => {
// Extract year from the date
const year = new Date(quarter?.date)?.getFullYear();
// If the year doesn't exist in the summary, initialize it
if (!yearlySummaries[year]) {
yearlySummaries[year] = {
calendarYear: `${year}`, // Use end of the year date
};
}
// Sum up the numeric fields for the year
Object?.keys(quarter)?.forEach(key => {
if (typeof quarter[key] === 'number') {
yearlySummaries[year][key] = (yearlySummaries[year][key] || 0) + quarter[key];
}
});
});
// Convert yearly summaries object to an array
const annualResults = Object?.values(yearlySummaries)?.sort((a, b) => b?.calendarYear?.localeCompare(a?.calendarYear));
return annualResults;
}
</script>

View File

@ -3,7 +3,7 @@ import Chart from '$lib/components/Chart.svelte'
import { page } from '$app/stores';
import {numberOfUnreadNotification,displayCompanyName, stockTicker} from '$lib/store';
//import {Katex} from '$lib/components';
import { abbreviateNumber } from '$lib/utils';
import { abbreviateNumber, sumQuarterlyResultsByYear } from '$lib/utils';
import * as XLSX from 'xlsx';
export let data;
@ -363,35 +363,6 @@ $: {
// Function to sum up quarterly results by year
function sumQuarterlyResultsByYear(quarterlyResults) {
const yearlySummaries = {};
// Iterate over each quarterly result
quarterlyResults?.forEach(quarter => {
// Extract year from the date
const year = new Date(quarter?.date)?.getFullYear();
// If the year doesn't exist in the summary, initialize it
if (!yearlySummaries[year]) {
yearlySummaries[year] = {
calendarYear: `${year}`, // Use end of the year date
};
}
// Sum up the numeric fields for the year
Object?.keys(quarter)?.forEach(key => {
if (typeof quarter[key] === 'number') {
yearlySummaries[year][key] = (yearlySummaries[year][key] || 0) + quarter[key];
}
});
});
// Convert yearly summaries object to an array
const annualResults = Object?.values(yearlySummaries)?.sort((a, b) => b?.calendarYear?.localeCompare(a?.calendarYear));
return annualResults;
}
</script>

View File

@ -1,7 +1,7 @@
<script lang="ts">
import Chart from '$lib/components/Chart.svelte'
import {numberOfUnreadNotification,displayCompanyName, stockTicker} from '$lib/store';
import { abbreviateNumber } from '$lib/utils';
import { abbreviateNumber, sumQuarterlyResultsByYear } from '$lib/utils';
import * as XLSX from 'xlsx';
export let data;
@ -350,36 +350,6 @@ const exportData = (format = 'csv') => {
}
// Function to sum up quarterly results by year
function sumQuarterlyResultsByYear(quarterlyResults) {
const yearlySummaries = {};
// Iterate over each quarterly result
quarterlyResults?.forEach(quarter => {
// Extract year from the date
const year = new Date(quarter?.date)?.getFullYear();
// If the year doesn't exist in the summary, initialize it
if (!yearlySummaries[year]) {
yearlySummaries[year] = {
calendarYear: `${year}`, // Use end of the year date
};
}
// Sum up the numeric fields for the year
Object?.keys(quarter)?.forEach(key => {
if (typeof quarter[key] === 'number') {
yearlySummaries[year][key] = (yearlySummaries[year][key] || 0) + quarter[key];
}
});
});
// Convert yearly summaries object to an array
const annualResults = Object?.values(yearlySummaries)?.sort((a, b) => b?.calendarYear?.localeCompare(a?.calendarYear));
return annualResults;
}
</script>

View File

@ -1,6 +1,7 @@
<script lang="ts">
import { Chart } from 'svelte-echarts'
import {numberOfUnreadNotification, displayCompanyName, stockTicker} from '$lib/store';
import { sumQuarterlyResultsByYear } from '$lib/utils';
import * as XLSX from 'xlsx';
@ -333,38 +334,6 @@ $: {
}
// Function to sum up quarterly results by year
function sumQuarterlyResultsByYear(quarterlyResults) {
const yearlySummaries = {};
// Iterate over each quarterly result
quarterlyResults?.forEach(quarter => {
// Extract year from the date
const year = new Date(quarter?.date)?.getFullYear();
// If the year doesn't exist in the summary, initialize it
if (!yearlySummaries[year]) {
yearlySummaries[year] = {
calendarYear: `${year}`, // Use end of the year date
};
}
// Sum up the numeric fields for the year
Object?.keys(quarter)?.forEach(key => {
if (typeof quarter[key] === 'number') {
yearlySummaries[year][key] = (yearlySummaries[year][key] || 0) + quarter[key];
}
});
});
// Convert yearly summaries object to an array
const annualResults = Object?.values(yearlySummaries)?.sort((a, b) => b?.calendarYear?.localeCompare(a?.calendarYear));
return annualResults;
}
</script>