Fix residual detail row aggregation

This commit is contained in:
2026-03-13 00:14:30 -04:00
parent 8a8c4f7177
commit 5998066524
2 changed files with 184 additions and 2 deletions

View File

@@ -295,6 +295,54 @@ function rowHasValues(values: Record<string, number | null>) {
return Object.values(values).some((value) => value !== null);
}
function detailConceptIdentity(row: DetailFinancialRow) {
const localName = row.localName.trim().toLowerCase();
if (localName.length > 0) {
if (row.isExtension) {
return `extension:${localName}`;
}
if (row.namespaceUri.includes('us-gaap')) {
return `us-gaap:${localName}`;
}
if (row.namespaceUri.includes('ifrs')) {
return `ifrs:${localName}`;
}
const prefix = row.qname.split(':')[0]?.trim().toLowerCase();
if (prefix) {
return `${prefix}:${localName}`;
}
}
const normalizedQName = row.qname.trim().toLowerCase();
if (normalizedQName.length > 0) {
return normalizedQName;
}
const normalizedConceptKey = row.conceptKey.trim().toLowerCase();
if (normalizedConceptKey.length > 0) {
return normalizedConceptKey;
}
return row.key.trim().toLowerCase();
}
function detailMergeKey(row: DetailFinancialRow) {
const dimensionsKey = [...row.dimensionsSummary]
.map((value) => value.trim().toLowerCase())
.filter((value) => value.length > 0)
.sort((left, right) => left.localeCompare(right))
.join('|') || 'no-dimensions';
return [
detailConceptIdentity(row),
row.unit ?? 'no-unit',
dimensionsKey
].join('::');
}
const PINNED_INCOME_SURFACE_ROWS = new Set([
'revenue',
'gross_profit',
@@ -413,9 +461,10 @@ function aggregateDetailRows(input: {
continue;
}
const existing = bucket.get(row.key);
const mergeKey = detailMergeKey(row);
const existing = bucket.get(mergeKey);
if (!existing) {
bucket.set(row.key, {
bucket.set(mergeKey, {
...row,
values: filteredValues,
sourceFactIds: [...row.sourceFactIds],
@@ -1186,6 +1235,7 @@ export const __financialTaxonomyInternals = {
buildDimensionBreakdown,
buildNormalizationMetadata,
aggregateSurfaceRows,
aggregateDetailRows,
mergeStructuredKpiRowsByPriority,
periodSorter,
selectPrimaryPeriodsByCadence,