feat(research): prepare and retain explicit source datasets in the web workbench
This commit is contained in:
parent
06039d17ba
commit
366bee810b
21 changed files with 2677 additions and 76 deletions
|
|
@ -2,23 +2,9 @@
|
|||
import { readFile } from 'node:fs/promises';
|
||||
import { Pool } from 'pg';
|
||||
import { validateDatasetV2 } from '../apps/stock/orchestrator/src/data/historical-dataset-v2';
|
||||
import { retainResearchDataset } from '../apps/stock/orchestrator/src/data/retained-research-dataset';
|
||||
|
||||
export async function retainResearchDataset(database: Pick<Pool, 'query'>, input: unknown) {
|
||||
const dataset = validateDatasetV2(input);
|
||||
await database.query(
|
||||
'INSERT INTO backtest_datasets(hash,payload) VALUES($1,$2::jsonb) ON CONFLICT(hash) DO NOTHING',
|
||||
[dataset.manifest.hash, JSON.stringify(dataset)]
|
||||
);
|
||||
const stored = (
|
||||
await database.query('SELECT payload FROM backtest_datasets WHERE hash=$1', [
|
||||
dataset.manifest.hash,
|
||||
])
|
||||
).rows[0];
|
||||
if (!stored || validateDatasetV2(stored.payload).manifest.hash !== dataset.manifest.hash) {
|
||||
throw new Error('Retained dataset content does not match the imported identity');
|
||||
}
|
||||
return dataset.manifest;
|
||||
}
|
||||
export { retainResearchDataset } from '../apps/stock/orchestrator/src/data/retained-research-dataset';
|
||||
|
||||
if (import.meta.main) {
|
||||
let database: Pool | undefined;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue