feat(research): prepare stored EOD datasets before canonical admission
This commit is contained in:
parent
366bee810b
commit
0c6aec4dc6
16 changed files with 1897 additions and 61 deletions
|
|
@ -18,8 +18,11 @@ interface Retention {
|
|||
input: unknown;
|
||||
preview: CanonicalDatasetPreparation;
|
||||
}
|
||||
type InputMode = 'export' | 'stored-eod';
|
||||
const instant = (value: number) => new Date(value).toISOString();
|
||||
export function DatasetPreparation({ disabled, begin, onStateChange, onRetained }: Props) {
|
||||
const [mode, setMode] = useState<InputMode>('export');
|
||||
const modeRef = useRef<InputMode>('export');
|
||||
const [input, setInput] = useState<{ value: unknown; filename: string } | null>(null);
|
||||
const [preview, setPreview] = useState<CanonicalDatasetPreparation | null>(null);
|
||||
const [retained, setRetained] = useState(false),
|
||||
|
|
@ -65,6 +68,20 @@ export function DatasetPreparation({ disabled, begin, onStateChange, onRetained
|
|||
}
|
||||
state(false, false);
|
||||
};
|
||||
const changeMode = (next: string) => {
|
||||
if (
|
||||
(next !== 'export' && next !== 'stored-eod') ||
|
||||
next === modeRef.current ||
|
||||
disabled ||
|
||||
captured.current ||
|
||||
!callbacks.current.begin()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
reset();
|
||||
modeRef.current = next;
|
||||
setMode(next);
|
||||
};
|
||||
const loadFile = async (file: File | undefined) => {
|
||||
if (disabled || captured.current || !callbacks.current.begin()) {
|
||||
return;
|
||||
|
|
@ -107,6 +124,7 @@ export function DatasetPreparation({ disabled, begin, onStateChange, onRetained
|
|||
};
|
||||
const inspect = async () => {
|
||||
const selectedSource = source.current;
|
||||
const selectedMode = modeRef.current;
|
||||
if (
|
||||
disabled ||
|
||||
pending.current ||
|
||||
|
|
@ -127,10 +145,16 @@ export function DatasetPreparation({ disabled, begin, onStateChange, onRetained
|
|||
setRetained(false);
|
||||
state(true, true);
|
||||
try {
|
||||
const result = await backtestApiV2.previewDataset(selectedSource.value, abort.signal);
|
||||
const result =
|
||||
selectedMode === 'stored-eod'
|
||||
? await backtestApiV2.previewStoredDataset(selectedSource.value, abort.signal)
|
||||
: {
|
||||
input: selectedSource.value,
|
||||
preparation: await backtestApiV2.previewDataset(selectedSource.value, abort.signal),
|
||||
};
|
||||
if (active.current && revision === generation.current) {
|
||||
prepared.current = { input: selectedSource.value, preview: result };
|
||||
setPreview(result);
|
||||
prepared.current = { input: result.input, preview: result.preparation };
|
||||
setPreview(result.preparation);
|
||||
}
|
||||
} catch (cause) {
|
||||
if (active.current && revision === generation.current) {
|
||||
|
|
@ -197,7 +221,9 @@ export function DatasetPreparation({ disabled, begin, onStateChange, onRetained
|
|||
prepared.current = null;
|
||||
setIntent(null);
|
||||
setPreview(null);
|
||||
setError(`${cause.message} Preview again or choose a corrected source export.`);
|
||||
setError(
|
||||
`${cause.message} Preview again or choose a corrected ${modeRef.current === 'export' ? 'source export' : 'metadata file'}.`
|
||||
);
|
||||
} else {
|
||||
setError(
|
||||
`${cause instanceof Error ? cause.message : 'Dataset retention response was lost'} Retry the exact same input and hash; retention may already have succeeded.`
|
||||
|
|
@ -215,25 +241,53 @@ export function DatasetPreparation({ disabled, begin, onStateChange, onRetained
|
|||
return (
|
||||
<section aria-label="Source dataset preparation" className="space-y-3 text-sm">
|
||||
<p>
|
||||
Supply a complete source export with metadata and bars. Sessions, source revisions,
|
||||
universe, corporate actions and publication availability must be explicit. Declared
|
||||
provenance is not independent provider certification. Preview writes nothing; retention does
|
||||
not save settings or start a run.
|
||||
Supply complete metadata with exported bars or explicitly selected stored EOD intraday bars.
|
||||
Sessions, source revisions, universe, corporate actions and publication availability must be
|
||||
explicit. Declared provenance is not independent provider certification. Preview writes
|
||||
nothing; retention does not save settings or start a run.
|
||||
</p>
|
||||
<label className="block">
|
||||
Source dataset JSON
|
||||
Dataset input
|
||||
<select
|
||||
aria-label="Dataset input"
|
||||
className={fieldClass}
|
||||
value={mode}
|
||||
disabled={disabled || Boolean(intent)}
|
||||
onChange={event => changeMode(event.target.value)}
|
||||
>
|
||||
<option value="export">Source export</option>
|
||||
<option value="stored-eod">Stored EOD intraday bars</option>
|
||||
</select>
|
||||
</label>
|
||||
{mode === 'stored-eod' && (
|
||||
<p>
|
||||
Load one EOD instrument from existing storage using raw 1m, 5m or 1h interval-start bars.
|
||||
Supply complete metadata with interval-end-assumption availability. Source sequence is a
|
||||
deterministic sorted row ordinal, not a vendor sequence. The current store, history and
|
||||
declared revision are not independently certified. Preview reads a new snapshot; retention
|
||||
uses that captured snapshot without querying storage again.
|
||||
</p>
|
||||
)}
|
||||
<label className="block">
|
||||
{mode === 'export' ? 'Source dataset JSON' : 'Source metadata JSON'}
|
||||
<input
|
||||
ref={fileInput}
|
||||
className={fieldClass}
|
||||
type="file"
|
||||
accept="application/json,.json"
|
||||
aria-label="Source dataset JSON"
|
||||
aria-label={mode === 'export' ? 'Source dataset JSON' : 'Source metadata JSON'}
|
||||
disabled={disabled || Boolean(intent)}
|
||||
onChange={event => void loadFile(event.target.files?.[0])}
|
||||
/>
|
||||
</label>
|
||||
{!input && !phase && !error && <p>No source export selected.</p>}
|
||||
{input && <p>Selected export: {input.filename}</p>}
|
||||
{!input && !phase && !error && (
|
||||
<p>{mode === 'export' ? 'No source export selected.' : 'No source metadata selected.'}</p>
|
||||
)}
|
||||
{input && (
|
||||
<p>
|
||||
Selected {mode === 'export' ? 'export' : 'metadata'}: {input.filename}
|
||||
</p>
|
||||
)}
|
||||
{phase && (
|
||||
<p role="status">
|
||||
{phase === 'reading'
|
||||
|
|
@ -295,6 +349,13 @@ export function DatasetPreparation({ disabled, begin, onStateChange, onRetained
|
|||
)}
|
||||
{preview && (
|
||||
<section aria-label="Prepared dataset metadata" className="space-y-2 break-words">
|
||||
{mode === 'stored-eod' && (
|
||||
<p>
|
||||
Stored source: EOD · Query bounds (UTC, end exclusive):{' '}
|
||||
{instant(preview.manifest.bounds.warmupStart)} —{' '}
|
||||
{instant(preview.manifest.bounds.tradeEnd)}
|
||||
</p>
|
||||
)}
|
||||
<p className="break-all">Dataset hash: {preview.hash}</p>
|
||||
<p>
|
||||
{preview.manifest.barCount} bars · Eligibility: {preview.manifest.eligibility} ·{' '}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue