T-87: M1.1l — Security-type classifier: eodSymbols.Type → securityTypeByIsin for the security-master loader (no new dependencies)
This commit is contained in:
parent
a368e8a47a
commit
b2a1f5ce80
3 changed files with 102 additions and 36 deletions
|
|
@ -28,6 +28,7 @@ import {
|
|||
} from './listing-stage-b';
|
||||
import type { SecurityType } from './persist';
|
||||
import {
|
||||
buildSecurityTypeByIsin,
|
||||
buildSecurityTypeByIsinForStageA,
|
||||
type SecurityTypeClassificationStats,
|
||||
type SecurityTypeConflict,
|
||||
|
|
@ -200,7 +201,7 @@ export type AdaptEodSymbolResult =
|
|||
readonly ok: true;
|
||||
readonly stageARecord: StageASourceRecord;
|
||||
readonly eodListing: StageBEodListingInput;
|
||||
readonly rawType: unknown;
|
||||
readonly rawType: string | null;
|
||||
readonly resolvedIsin: string | null;
|
||||
readonly invalidIdentifiersNulled: number;
|
||||
}
|
||||
|
|
@ -235,6 +236,7 @@ export interface ReadEodSymbolsResult {
|
|||
securityTypeRecords: SecurityTypeInputRecord[];
|
||||
securityTypeByIsin: Map<string, SecurityType>;
|
||||
securityTypeStats: SecurityTypeClassificationStats;
|
||||
securityTypeLoaderStats: SecurityTypeClassificationStats;
|
||||
unknownSecurityTypes: UnknownSecurityTypeCount[];
|
||||
securityTypeConflicts: SecurityTypeConflict[];
|
||||
stats: SourceCollectionReadStats;
|
||||
|
|
@ -278,6 +280,7 @@ export interface SecurityMasterSourcesResult {
|
|||
securityTypeRecords: SecurityTypeInputRecord[];
|
||||
securityTypeByIsin: Map<string, SecurityType>;
|
||||
securityTypeStats: SecurityTypeClassificationStats;
|
||||
securityTypeLoaderStats: SecurityTypeClassificationStats;
|
||||
unknownSecurityTypes: UnknownSecurityTypeCount[];
|
||||
securityTypeConflicts: SecurityTypeConflict[];
|
||||
stats: SecurityMasterSourcesStats;
|
||||
|
|
@ -771,16 +774,17 @@ function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|||
|
||||
/**
|
||||
* Extracts raw EODHD `Type`/`type` without rejecting non-string values so a malformed `Type`
|
||||
* never skips the symbol document (it is counted as `missingType` by the classifier instead).
|
||||
* never skips the symbol document. Non-string and blank values normalize to `null` so
|
||||
* `securityTypeRecords` ordering is deterministic while still counting as `missingType`.
|
||||
*/
|
||||
function readRawSecurityType(doc: Record<string, unknown>): unknown {
|
||||
function readRawSecurityType(doc: Record<string, unknown>): string | null {
|
||||
if (typeof doc.Type === 'string' && doc.Type.trim().length > 0) {
|
||||
return doc.Type;
|
||||
}
|
||||
if (typeof doc.type === 'string' && doc.type.trim().length > 0) {
|
||||
return doc.type;
|
||||
}
|
||||
return doc.Type !== undefined ? doc.Type : doc.type;
|
||||
return null;
|
||||
}
|
||||
|
||||
function isNorthAmericaIso(code: string | null): code is 'US' | 'CA' {
|
||||
|
|
@ -1050,19 +1054,7 @@ function compareSymbolChanges(a: StageBSymbolChangeInput, b: StageBSymbolChangeI
|
|||
}
|
||||
|
||||
function rawTypeSortKey(rawType: unknown): string {
|
||||
if (typeof rawType === 'string') {
|
||||
return `s:${rawType}`;
|
||||
}
|
||||
if (rawType === null) {
|
||||
return 'n:null';
|
||||
}
|
||||
if (rawType === undefined) {
|
||||
return 'u:undefined';
|
||||
}
|
||||
if (typeof rawType === 'number' || typeof rawType === 'boolean' || typeof rawType === 'bigint') {
|
||||
return `${typeof rawType}:${String(rawType)}`;
|
||||
}
|
||||
return `o:${typeof rawType}`;
|
||||
return typeof rawType === 'string' ? `s:${rawType}` : 'n:null';
|
||||
}
|
||||
|
||||
function compareSecurityTypeRecords(
|
||||
|
|
@ -1733,27 +1725,31 @@ export async function readEodSymbols(
|
|||
eodListings.sort(compareEodListings);
|
||||
securityTypeRecords.sort(compareSecurityTypeRecords);
|
||||
|
||||
// Build the loader-facing map strictly from EOD rows accepted as Stage A instrument members so
|
||||
// Stage A-quarantined rows (e.g. isin_cusip_mismatch, duplicate_source_id) cannot supply or veto
|
||||
// a valid instrument's type, while keeping all emitted rows in `securityTypeRecords` for raw
|
||||
// vocabulary diagnostics.
|
||||
const eodStageA = matchInstrumentsStageA(stageARecords);
|
||||
const securityTypeResult = buildSecurityTypeByIsinForStageA(
|
||||
securityTypeRecords,
|
||||
eodStageA.instruments,
|
||||
// Compute vocabulary diagnostics across every emitted EOD row, while building the loader-facing
|
||||
// `securityTypeByIsin` map and its conflicts strictly from EOD rows accepted as Stage A
|
||||
// instrument members so quarantined rows (e.g. isin_cusip_mismatch, duplicate_source_id)
|
||||
// cannot supply or veto a valid instrument's type.
|
||||
const securityTypeOptions =
|
||||
options.maxSecurityTypeConflicts !== undefined
|
||||
? { maxConflicts: options.maxSecurityTypeConflicts }
|
||||
: undefined
|
||||
: undefined;
|
||||
const allSecurityTypeResult = buildSecurityTypeByIsin(securityTypeRecords, securityTypeOptions);
|
||||
const eodStageA = matchInstrumentsStageA(stageARecords);
|
||||
const loaderSecurityTypeResult = buildSecurityTypeByIsinForStageA(
|
||||
securityTypeRecords,
|
||||
eodStageA.instruments,
|
||||
securityTypeOptions
|
||||
);
|
||||
|
||||
return {
|
||||
stageARecords,
|
||||
eodListings,
|
||||
securityTypeRecords,
|
||||
securityTypeByIsin: securityTypeResult.securityTypeByIsin,
|
||||
securityTypeStats: securityTypeResult.stats,
|
||||
unknownSecurityTypes: securityTypeResult.unknownRawTypes,
|
||||
securityTypeConflicts: securityTypeResult.conflicts,
|
||||
securityTypeByIsin: loaderSecurityTypeResult.securityTypeByIsin,
|
||||
securityTypeStats: allSecurityTypeResult.stats,
|
||||
securityTypeLoaderStats: loaderSecurityTypeResult.stats,
|
||||
unknownSecurityTypes: allSecurityTypeResult.unknownRawTypes,
|
||||
securityTypeConflicts: loaderSecurityTypeResult.conflicts,
|
||||
stats,
|
||||
};
|
||||
}
|
||||
|
|
@ -1971,6 +1967,7 @@ export async function readSecurityMasterSources(
|
|||
securityTypeRecords: eodResult.securityTypeRecords,
|
||||
securityTypeByIsin: eodResult.securityTypeByIsin,
|
||||
securityTypeStats: eodResult.securityTypeStats,
|
||||
securityTypeLoaderStats: eodResult.securityTypeLoaderStats,
|
||||
unknownSecurityTypes: eodResult.unknownSecurityTypes,
|
||||
securityTypeConflicts: eodResult.securityTypeConflicts,
|
||||
stats: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue