Commit graph

123 commits

Author SHA1 Message Date
Marko Djordjevic
4605283d2b feat: redesign UI to match lovable compact sidebar layout
- Replace green hacker theme with professional blue-toned design
- Light theme default, manual toggle only (no system detection)
- Compact w-60 sidebar with collapsible sections
- New CSS tokens: sidebar, chart, candle, annotation colors
- Tools displayed as compact grid buttons
- Color swatches as inline bar
- Chart top bar with keyboard shortcut hints
- Inter + JetBrains Mono font pairing
- All components updated for compact styling
- Tailwind config extended with sidebar/chart tokens
2026-02-16 20:50:30 +01:00
Marko Djordjevic
2bde38d0bf fix: resolve database migration failures and startup ordering
- Add scripts/run-migrations.js to run migrations before data loading
- Fix startup.sh ordering: migrations -> data load -> app start
- Fix migration 0005 missing statement-breakpoint between ALTER TABLE statements
- Add migration 0005 to drizzle journal (was missing)
- Fix load-initial-data.js to check table existence before querying
- Fix load-initial-data.js to create chart record before inserting candles (chart_id NOT NULL constraint)
- Simplify db/index.ts migration error handling (remove overly broad 'already exists' catch)
- Add pre-migration check for inconsistent DB state (tables without migration tracking)
2026-02-16 19:59:47 +01:00
Marko Djordjevic
573efea5b5 fix: improve migration error handling to gracefully handle existing tables 2026-02-16 19:43:32 +01:00
Marko Djordjevic
bbaf330020 fix: skip migrations during build phase to prevent 'table already exists' errors 2026-02-16 19:41:22 +01:00
Marko Djordjevic
ecb23855b5 fix: add curl to ml-service for healthcheck 2026-02-16 17:31:08 +01:00
Marko Djordjevic
e48bff46cf docs: document RTK npm run bug workaround 2026-02-16 16:37:15 +01:00
Marko Djordjevic
511a557c42 add for docker until i fix it 2026-02-16 16:21:46 +01:00
Marko Djordjevic
23131b2c33 fix: resolve TypeScript narrowing errors and renamed lightweight-charts exports 2026-02-16 16:05:54 +01:00
Marko Djordjevic
efcf5c185f docs: document RTK bug with npm run command 2026-02-16 16:01:20 +01:00
Marko Djordjevic
025cf6d973 fix: resolve TypeScript error by renaming conflicting lineHit variable 2026-02-16 15:42:13 +01:00
Marko Djordjevic
08bd9625ae fix: build TA-Lib from source in ML Dockerfile 2026-02-16 14:58:07 +01:00
Marko Djordjevic
2cde02b722 docs: mark all line-rectangle-annotations tasks as complete 2026-02-16 12:14:22 +01:00
Marko Djordjevic
73e07c9050 feat: complete SVG overlay removal and line endpoint dragging (tasks 6.1-7.3) 2026-02-16 12:13:29 +01:00
Marko Djordjevic
aea1791122 feat: complete rectangle annotation tool (tasks 4.1-5.2)
- Add rectangle primitive management in CandleChart
- Handle chart switching with proper primitive cleanup
- Implement rectangle selection via hitTest
- Add rectangle deletion in delete tool
- Add rectangle tool button to Toolbox
- Wire rectangle tool with toggle behavior
2026-02-16 11:58:49 +01:00
Marko Djordjevic
82fd5ce819 feat: wire up drawing interaction for line and rectangle tools (tasks 3.1-3.5)
- Add drawing state and preview primitive refs
- Implement two-click drawing flow via subscribeClick
- Add crosshair move handler to update preview in real-time
- Add Escape key handler to cancel drawing
- Manage TrendLine primitives for saved line annotations
2026-02-16 11:55:06 +01:00
Marko Djordjevic
bec0aeb6ca feat: enhance TrendLine plugin and create RectangleDrawingPrimitive
- Add hitTest, setSelected, attached/detached lifecycle methods to TrendLine
- Add preview mode support with dashed lines and reduced opacity
- Draw selection handles on endpoints when selected
- Create RectangleDrawingPrimitive plugin with full ISeriesPrimitive implementation
- Support preview mode, selection, hit testing, and autoscaling for rectangles
- Set z-order to bottom for rectangles to render behind candlesticks

Tasks completed: 1.1-1.4, 2.1-2.7
2026-02-16 11:51:07 +01:00
Marko Djordjevic
28e3f83cf7 archive: candle-backend change complete 2026-02-16 11:44:53 +01:00
Marko Djordjevic
7e0579f65d sync: migrate delta specs to main openspec/specs
- Added 5 new capabilities: feature-engineering, annotation-ingestion, ml-training, ml-inference, prediction-ui
- Updated 2 existing capabilities: backend-api, span-annotation
- All specs synced from openspec/changes/candle-backend/specs/
2026-02-16 11:44:34 +01:00
Marko Djordjevic
65f00e6ce7 feat: complete prediction UI feedback tasks (11.2, 11.4, 11.5)
- Implement disagreement visual highlighting with distinct colors
  - Yellow highlight for 'missed_by_human' predictions
  - Orange for 'label_mismatch' disagreements
  - Warning icon on disagreement markers
- Add click-to-convert prediction feedback
  - Click disagreement predictions to create span annotations
  - Auto-fill with predicted label and times
  - Set source as 'model_confirmed' or 'model_corrected'
- Add dismiss action for false positive predictions
  - Alt+Click or Ctrl+Click to dismiss predictions
  - Saves negative annotation with label 'O'
  - Records original prediction in model_prediction field
- Filter predictions when 'Show only disagreements' is enabled
2026-02-16 11:40:55 +01:00
Marko Djordjevic
a18c6d110a Remove __pycache__ from git tracking 2026-02-15 22:29:35 +01:00
Marko Djordjevic
e3184ea86c save mlruns dir to git 2026-02-15 22:26:01 +01:00
Marko Djordjevic
f7b154f866 fix(ml): extract class labels from model when metadata is missing
The model info returned empty labels array because the pkl file has
no metadata dict. Now extracts labels from model.classes_ or
model.model.classes_ as fallback.
2026-02-15 22:18:16 +01:00
Marko Djordjevic
be09cef098 fix(ml): add missing numpy import in main.py 2026-02-15 22:08:41 +01:00
Marko Djordjevic
40d6d1739e fix(ml): add windowed feature flattening for inference parity
The model was trained on 94-candle sliding windows flattened to 2820
features (94 candles x 30 features). Inference was sending raw per-candle
features (27 columns).

Changes:
- Rewrite preprocessing to return (X, window_times) tuple
- Add sliding window creation with correct feature ordering
- Fill missing columns (average, barCount) with 0 for feature parity
- Fill NaN from indicator warmup with 0 instead of dropping rows
- Always compute all indicators (including MFI) for feature parity
- Update predict and batch predict endpoints for new signature
2026-02-15 22:07:06 +01:00
Marko Djordjevic
4c7b3f2676 fix(ml): detect all-NaN volume column (not just missing column)
The Pydantic model sets volume=None when absent, creating an all-NaN
column rather than a missing column. Check isna().all() in addition
to column existence.
2026-02-15 21:58:16 +01:00
Marko Djordjevic
317f925c43 fix(ml): handle missing volume data and skip volume-dependent indicators
- Fill volume with 0 when column is absent from candle data
- Skip MFI/OBV/AD/ADOSC indicators when no real volume data available
- Fix pandas FutureWarning for inplace fillna in candle_features
- Remove temporary debug NaN logging
2026-02-15 21:56:14 +01:00
Marko Djordjevic
b6b37160a7 fix(ml): cast OHLCV arrays to float64 for TA-Lib compatibility 2026-02-15 21:52:45 +01:00
Marko Djordjevic
f850728d44 fix(api): add GET /api/charts/[id] and fix batch prediction
- Add GET handler to /api/charts/[id] route to fetch chart metadata
- Fix batch prediction to use regular /predict endpoint with database candles
- Remove /predict/batch usage (was designed for file-based predictions)
- Make volume field optional in CandleData model (database candles don't have volume)
- Convert timestamps to ISO dates for batch requests

Known issue: TA-Lib indicators failing with 'input array type is not double'
- May need to ensure candle data is float64/double type before processing
2026-02-15 21:49:22 +01:00
Marko Djordjevic
6d0d67e39b fix(ml): make pair and timeframe optional in PredictRequest
- Change pair and timeframe fields from required to optional
- Frontend only sends candles array, not pair/timeframe metadata
- These fields are only used for logging, not prediction logic
- Update logging to handle None values with 'unknown' fallback
- Fixes 422 validation error on /predict endpoint
2026-02-15 21:43:14 +01:00
Marko Djordjevic
5a7c901980 fix(frontend): update ModelInfoResponse types to match backend structure
- Update TypeScript types to match flat backend response structure
- Remove nested model_info and metrics objects
- Remove label_config, use labels array and per_class_metrics array
- Update all component references to use new structure
- Generate default colors for prediction labels in CandleChart
- Fix TypeScript type errors for nullable model_version
- Remove accuracy/F1 metrics display (not in new response)
2026-02-15 21:39:38 +01:00
Marko Djordjevic
aa81d4f3d0 fix(ml): complete ML pipeline fixes and setup
- Fix CCI indicator to use HLC prices instead of close only
- Parse datetime column when loading enriched CSV
- Strip timezone from annotation timestamps
- Fix TA-Lib pattern names (CDL3WHITESOLDIERS, CDL3BLACKCROWS)
- Exclude programmatic label columns from training features
- Fix classification report to handle missing classes
- Update MLflow tracking to use localhost:5000
- Grant PostgreSQL permissions to ml_user

Pipeline now runs successfully end-to-end:
- Feature engineering: 2543 rows, 31 columns
- Annotation ingestion: 286 samples
- Training: 89.47% test accuracy with Random Forest
2026-02-15 21:29:54 +01:00
Marko Djordjevic
ceb4103ec4 fix(ml): parse datetime column and fix TA-Lib pattern names
- Add parse_dates parameter when loading enriched CSV
- Strip timezone from annotation timestamps to match data
- Fix pattern names: CDLTHREEWHITESOLDIERS -> CDL3WHITESOLDIERS
- Fix pattern names: CDLTHREEBLACKCROWS -> CDL3BLACKCROWS
2026-02-15 21:13:20 +01:00
Marko Djordjevic
2b86524436 fix(ml): correct CCI indicator signature to use HLC prices 2026-02-15 21:09:47 +01:00
Marko Djordjevic
63486bc7b5 fix(ml): add CCI to hlc_indicators list
CCI (Commodity Channel Index) requires high, low, and close prices
2026-02-15 21:08:20 +01:00
Marko Djordjevic
57240d4eea fix(scripts): add created_at timestamps to annotation import
Set created_at field for both span_label_types and span_annotations
to satisfy NOT NULL constraint
2026-02-15 19:36:55 +01:00
Marko Djordjevic
a68a681c9b fix(ml): handle date strings in TA-Lib annotation generator
- Convert date strings to Unix timestamps in load_ohlcv()
- Fix duplicate pattern names (CDL3WHITESOLDIERS/CDL3BLACKCROWS)
- Ensure time column is always integer type
2026-02-15 19:30:38 +01:00
Marko Djordjevic
847ff67986 feat(ml): add TA-Lib annotation generation and import workflow
Add complete workflow for using TA-Lib to bootstrap training data:

- generate_talib_annotations.py: Python script to run TA-Lib CDL* functions
  and output span annotations in UI-compatible format
- import_talib_annotations.ts: TypeScript script to import generated
  annotations into the UI database with auto-label-type creation
- npm script 'import-annotations' for easy execution
- TALIB_WORKFLOW.md: Comprehensive guide covering the full cycle:
  * Generate patterns with TA-Lib
  * Import into UI
  * Review and edit in browser
  * Export and train model
  * Compare predictions with TA-Lib detections
  * Iterate for improvement

This enables the intended workflow: use TA-Lib for initial annotations,
manually refine them, then train a model that learns from corrections.
2026-02-15 19:18:28 +01:00
Marko Djordjevic
228f70daf3 docs: add ML pipeline quickstart guide for training first model
Complete step-by-step guide covering:
- Creating training data through annotations
- Exporting annotations and candle data
- Running the full ML pipeline
- Verifying model creation and loading
- Getting predictions in the UI
- Troubleshooting common issues
- Iteration through active learning loop
2026-02-15 19:08:09 +01:00
Marko Djordjevic
21f184aa8d feat(ui): implement disagreement detection, prediction summary, loading states, and update documentation
- Add disagreement detection logic comparing human annotations vs predictions
- Display prediction summary in PredictionPanel (agreements/disagreements)
- Wire up 'Show only disagreements' filter toggle
- Add loading overlay during prediction fetching
- Update docker-compose.yml with healthchecks for all services
- Update DEPLOYMENT.md with comprehensive ML service setup instructions
- Update README.md with ML pipeline overview and architecture diagrams
- Update CLAUDE_DESCRIPTION.md with v3.0.0 ML integration details

Remaining tasks (11.2, 11.4, 11.5) deferred - core functionality complete
2026-02-15 16:34:02 +01:00
Marko Djordjevic
952eb7413c feat(ui): add prediction chart rendering with histogram overlay, markers, filtering, and visibility toggle
- Add histogram series to CandleChart for per-bar prediction colors (15% opacity)
- Add series markers showing label name and confidence % at prediction span starts
- Implement confidence threshold filtering for both histogram and markers
- Implement label type filtering from PredictionPanel checkboxes
- Implement prediction layer visibility toggle (show/hide)
- Add getVisibleCandles method to CandleChartHandle for on-demand prediction fetching
- Pass prediction state props from page.tsx to CandleChart

Tasks 10.1-10.5 complete.
2026-02-15 16:26:17 +01:00
Marko Djordjevic
28ebe2c5d1 feat(ui): add prediction state management and PredictionPanel component
- Create prediction type definitions in src/types/predictions.ts
- Add prediction state management to page.tsx with caching
- Implement PredictionPanel component with:
  - Master visibility toggle
  - Model info display (name, version, type, metrics)
  - Action buttons (Run on Visible, Predict All)
  - Confidence threshold slider
  - Label filter checkboxes with per-class metrics
  - Disagreement filter toggle
  - Prediction summary display
  - Model server offline banner
- Add on-demand and batch prediction fetching
- Implement prediction caching by chart and model version
- Add health polling for inference API (30s interval when offline)
- Ensure annotation tools work independently of prediction API

Tasks completed: 9.1-9.5, 12.1-12.3 (59/78 total)
2026-02-15 16:20:07 +01:00
Marko Djordjevic
bb1b6d573f feat(api): add span annotation export and feedback loop support
- Add GET /api/span-annotations/export endpoint for ML pipeline JSON/CSV export
- Add source and model_prediction fields to span_annotations schema
- Update POST endpoint to accept source (human/model/human_correction) and model_prediction metadata
- Support negative annotations (label 'O' for user corrections to model predictions)
- Create migration 0005 for new schema fields

Completes tasks 8.1-8.4 of candle-backend change
2026-02-15 14:35:31 +01:00
Marko Djordjevic
205021e810 feat(api): add Next.js proxy routes for ML inference service 2026-02-15 14:30:09 +01:00
Marko Djordjevic
3a83fd38e9 feat(ml): implement FastAPI inference service with model loading, preprocessing, and prediction endpoints 2026-02-15 14:29:07 +01:00
Marko Djordjevic
f4c0f9a836 feat(ml): implement training stage with MLflow tracking and model wrappers
- Create RandomForestModel and XGBoostModel wrappers with class weight support
- Implement temporal and random train/val/test splitting
- Add MLflow experiment tracking with full parameter and metric logging
- Create evaluation module for confusion matrix, feature importance, and classification reports
- Implement model training with sklearn/xgboost flavor logging and optional registry registration
- Store training run metadata in PostgreSQL
- Wire training stage into pipeline.py orchestrator
- Support both RandomForest and XGBoost models with configurable hyperparameters
2026-02-15 14:22:19 +01:00
Marko Djordjevic
16763b967e feat(ml): implement annotation ingestion with windowed/BIO encoding and TA-Lib patterns 2026-02-15 12:28:58 +01:00
Marko Djordjevic
fd29ab91e0 feat(ml): implement feature engineering pipeline
- Create pipeline.py with CLI argument parsing for running stages
- Implement TA-Lib indicator computation with multi-output support
- Add candle feature extraction (body_size, wicks, ratios, etc.)
- Create custom feature loader with dynamic module import
- Wire all feature engineering stages with NaN handling
- Tasks completed: 2.2, 2.3, 3.1, 3.2, 3.3, 3.4, 3.5
2026-02-15 12:22:59 +01:00
Marko Djordjevic
ea339a54a7 feat(ml): add database schema, config parser, and DVC setup
- Initialize DVC with local storage backend (task 1.6)
- Create PostgreSQL schema for training_runs table (task 1.7)
- Add SQLAlchemy database connection setup (task 1.8)
- Create Pydantic config models for pipeline.yaml (task 2.1)
- Add migration runner for database setup
- Fix pyproject.toml package discovery config
2026-02-15 12:08:53 +01:00
Marko Djordjevic
1a653c5866 feat: add ML service scaffolding with Python FastAPI, Docker, and MLflow setup 2026-02-15 11:58:31 +01:00
Marko Djordjevic
92abab5316 span annotations are working 2026-02-15 10:16:05 +01:00