Phase 1 trading plan core

This commit is contained in:
Codex
2026-05-06 11:45:07 +08:00
parent a17d67f658
commit e47d197ff4
62 changed files with 20340 additions and 15962 deletions
@@ -21,6 +21,24 @@ create table if not exists training_cases (
check (decision_ts <= end_ts)
);
alter table if exists training_cases add column if not exists instrument_id bigint;
alter table if exists training_cases add column if not exists timeframe text not null default '1m';
alter table if exists training_cases add column if not exists case_type text not null default 'unknown';
alter table if exists training_cases add column if not exists skill_tag text not null default 'general';
alter table if exists training_cases add column if not exists chapter_ref text;
alter table if exists training_cases add column if not exists source_event_type text;
alter table if exists training_cases add column if not exists source_event_id bigint;
alter table if exists training_cases add column if not exists source_event_refs jsonb not null default '[]'::jsonb;
alter table if exists training_cases add column if not exists start_ts timestamptz not null default now();
alter table if exists training_cases add column if not exists decision_ts timestamptz not null default now();
alter table if exists training_cases add column if not exists end_ts timestamptz not null default now();
alter table if exists training_cases add column if not exists difficulty text not null default 'medium';
alter table if exists training_cases add column if not exists answer_key jsonb not null default '{}'::jsonb;
alter table if exists training_cases add column if not exists status text not null default 'draft';
alter table if exists training_cases add column if not exists meta jsonb not null default '{}'::jsonb;
alter table if exists training_cases add column if not exists created_at timestamptz not null default now();
alter table if exists training_cases add column if not exists updated_at timestamptz not null default now();
create index if not exists idx_training_cases_instr_tf_decision_desc
on training_cases (instrument_id, timeframe, decision_ts desc);
@@ -45,6 +63,18 @@ create table if not exists training_case_tasks (
updated_at timestamptz not null default now()
);
alter table if exists training_case_tasks add column if not exists case_id bigint;
alter table if exists training_case_tasks add column if not exists task_type text not null default 'annotation';
alter table if exists training_case_tasks add column if not exists skill_tag text not null default 'general';
alter table if exists training_case_tasks add column if not exists prompt text not null default '';
alter table if exists training_case_tasks add column if not exists required_annotation_types jsonb not null default '[]'::jsonb;
alter table if exists training_case_tasks add column if not exists max_score numeric(8,2) not null default 0;
alter table if exists training_case_tasks add column if not exists sort_order integer not null default 0;
alter table if exists training_case_tasks add column if not exists status text not null default 'active';
alter table if exists training_case_tasks add column if not exists meta jsonb not null default '{}'::jsonb;
alter table if exists training_case_tasks add column if not exists created_at timestamptz not null default now();
alter table if exists training_case_tasks add column if not exists updated_at timestamptz not null default now();
create index if not exists idx_training_case_tasks_case_sort
on training_case_tasks (case_id, sort_order, id);
@@ -65,6 +95,17 @@ create table if not exists training_attempts (
updated_at timestamptz not null default now()
);
alter table if exists training_attempts add column if not exists case_id bigint;
alter table if exists training_attempts add column if not exists user_id text not null default 'local';
alter table if exists training_attempts add column if not exists status text not null default 'started';
alter table if exists training_attempts add column if not exists current_frame_index integer not null default 0;
alter table if exists training_attempts add column if not exists started_at timestamptz not null default now();
alter table if exists training_attempts add column if not exists submitted_at timestamptz;
alter table if exists training_attempts add column if not exists total_score numeric(8,2);
alter table if exists training_attempts add column if not exists meta jsonb not null default '{}'::jsonb;
alter table if exists training_attempts add column if not exists created_at timestamptz not null default now();
alter table if exists training_attempts add column if not exists updated_at timestamptz not null default now();
create index if not exists idx_training_attempts_user_status_created_desc
on training_attempts (user_id, status, created_at desc);
@@ -82,6 +123,14 @@ create table if not exists training_annotations (
updated_at timestamptz not null default now()
);
alter table if exists training_annotations add column if not exists attempt_id bigint;
alter table if exists training_annotations add column if not exists task_id bigint;
alter table if exists training_annotations add column if not exists user_id text not null default 'local';
alter table if exists training_annotations add column if not exists annotation_type text not null default 'note';
alter table if exists training_annotations add column if not exists payload jsonb not null default '{}'::jsonb;
alter table if exists training_annotations add column if not exists created_at timestamptz not null default now();
alter table if exists training_annotations add column if not exists updated_at timestamptz not null default now();
create index if not exists idx_training_annotations_attempt_type_created
on training_annotations (attempt_id, annotation_type, created_at);
@@ -98,6 +147,16 @@ create table if not exists training_scores (
updated_at timestamptz not null default now()
);
alter table if exists training_scores add column if not exists attempt_id bigint;
alter table if exists training_scores add column if not exists task_id bigint;
alter table if exists training_scores add column if not exists user_id text not null default 'local';
alter table if exists training_scores add column if not exists category text not null default 'general';
alter table if exists training_scores add column if not exists score numeric(8,2) not null default 0;
alter table if exists training_scores add column if not exists max_score numeric(8,2) not null default 0;
alter table if exists training_scores add column if not exists feedback jsonb not null default '{}'::jsonb;
alter table if exists training_scores add column if not exists created_at timestamptz not null default now();
alter table if exists training_scores add column if not exists updated_at timestamptz not null default now();
create index if not exists idx_training_scores_attempt_category
on training_scores (attempt_id, category);
@@ -115,5 +174,15 @@ create table if not exists training_progress (
unique (user_id, skill_tag)
);
alter table if exists training_progress add column if not exists user_id text not null default 'local';
alter table if exists training_progress add column if not exists skill_tag text not null default 'general';
alter table if exists training_progress add column if not exists attempt_count integer not null default 0;
alter table if exists training_progress add column if not exists avg_score numeric(8,4);
alter table if exists training_progress add column if not exists last_attempt_at timestamptz;
alter table if exists training_progress add column if not exists weakness_tags jsonb not null default '[]'::jsonb;
alter table if exists training_progress add column if not exists meta jsonb not null default '{}'::jsonb;
alter table if exists training_progress add column if not exists created_at timestamptz not null default now();
alter table if exists training_progress add column if not exists updated_at timestamptz not null default now();
create index if not exists idx_training_progress_user_skill
on training_progress (user_id, skill_tag);
+27
View File
@@ -0,0 +1,27 @@
create table if not exists trading_plans (
id bigserial primary key,
instrument_id bigint not null references instruments(id),
plan_date date not null,
status text not null,
narrative text not null,
primary_draw jsonb not null default '{}'::jsonb,
secondary_draw jsonb not null default '{}'::jsonb,
bias text not null,
allowed_sessions jsonb not null default '[]'::jsonb,
invalidations jsonb not null default '[]'::jsonb,
no_trade_conditions jsonb not null default '[]'::jsonb,
inputs jsonb not null default '{}'::jsonb,
quality jsonb not null default '{}'::jsonb,
timeframe_set jsonb not null default '{}'::jsonb,
created_ts timestamptz not null,
activated_ts timestamptz,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now(),
unique (instrument_id, plan_date)
);
create index if not exists idx_trading_plans_instr_date_desc
on trading_plans (instrument_id, plan_date desc);
create index if not exists idx_trading_plans_instr_status_date_desc
on trading_plans (instrument_id, status, plan_date desc);