Skip to content

Legacy -> master#52

Open
dapi wants to merge 164 commits intofinfex:masterfrom
alfagen:legacy
Open

Legacy -> master#52
dapi wants to merge 164 commits intofinfex:masterfrom
alfagen:legacy

Conversation

@dapi
Copy link
Copy Markdown
Contributor

@dapi dapi commented Dec 30, 2025

No description provided.

m1ndg8mer and others added 30 commits March 31, 2021 15:56
Rate source: use transaction instead of locking
ExchangeRate: allow to use negative comission
* Изменение автокурсов в зависимости от базовых курсов направления

* Add worker

* 1 minute -> 1 hour

* Remove unused code

* Fix reference

* Refactoring

* Refactoring

* Refactoring v2
* RatesWorker: remove logger to save transaction time

* Add rescue block

* Add newline
* RatesWorker optimization

* Move rescue to top
dapi and others added 30 commits December 29, 2025 14:16
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Защита от деления на ноль при median=0 в find_non_anomalous_rate_above
- Обработка nil calculator_type как 'legacy' для обратной совместимости
- Добавлены тесты для edge cases

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…e-based-on-legacy

feat: Position-aware автокурс с округлением комиссии (#69, #75)
Production log level is :warn so debug logs are not written.
Using info level to ensure logs appear in production.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fixes #83

UC-9 (median-based anomaly filtering) has been cancelled because:
- Doesn't work correctly with negative commission rates
- Negative rates are now normal for competitive directions
- Median-based deviation was marking all top positions as anomalous

UC-13 (Protection from jumping above position_from - 1) is a simpler
approach that:
- Only compares with the immediate position above target range
- Prevents jumping above position_from - 1 regardless of "anomalies"
- Doesn't require complex median calculations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…above

Когда позиция выше целевого диапазона отсутствует (rate_above = nil),
калькулятор теперь использует курс первой целевой позиции если он
в допустимом диапазоне autorate_from..autorate_to.

Это гарантирует что обменник не выйдет за пределы position_from
даже при отсутствии данных для позиций выше.

Closes #83

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Добавлен .compact перед .select для обработки nil в rates_in_target_position
- Удалён неиспользуемый параметр target_rate из fallback_to_first_target_position
- Исправлен комментарий UC-14: уточнено что fallback только для position_from > 1
- Исправлено имя теста: "корректирует до первой целевой позиции"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Критические исправления:
- Добавлен safe navigation (rate&.exchanger_id) в filtered_external_rates
- Добавлен try-catch в RateComissionCalculator с логированием и fallback
- Добавлен .compact в debug_log для rates_in_target_position

Важные улучшения:
- autorate_debug_enabled = false по умолчанию (избегаем спама в production)
- Исправлен комментарий "Гарантирует" → описание реального поведения
- Добавлен тест для случая first_target_rate = nil

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Добавлено логирование в rescue блок DirectionsRatesWorker
- Добавлена проверка rates.present? перед insert_all (защита от ArgumentError)
- Убран allow_nil из валидации calculator_type (согласованность с БД)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…tion

- Add .compact before .select in Base#external_rates_in_target_comission
  to prevent NoMethodError on nil elements (fixes Legacy calculator edge case)
- Restore allow_nil: true for calculator_type validation to match
  autorate_calculator_class behavior which treats nil as 'legacy'

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add UC-6 tests (adaptive GAP) to isolated_spec.rb
- Add UC-8 tests (exclude our exchanger) to isolated_spec.rb
- Add UC-13 tests (prevent position jumping) to isolated_spec.rb
- Update doc/autorate_system.md with correct AUTO_COMISSION_GAP value (0.0001)

Test coverage now includes all UC cases in isolated tests:
- UC-1 through UC-5: basic scenarios
- UC-6: adaptive GAP for dense ratings
- UC-8: exclude our exchanger from calculation
- UC-12: skip GAP on equal rates
- UC-13: prevent jumping above target position
- UC-14: fallback to first target position

29 examples, 0 failures

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…_above = nil

Fixes #86

При position_from > 1 и rate_above = nil теперь ВСЕГДА возвращаем
first_target_rate.target_rate_percent, без условной проверки.

Изменения:
- fallback_to_first_target_position теперь всегда возвращает курс первой целевой позиции
- При first_target_rate = nil возвращаем autorate_from (было target_comission)
- Добавлено warn_log для отслеживания fallback событий
- MIN_GAP уменьшен до 0.00001 для корректной работы адаптивного GAP

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Добавлен round_commission в fallback_to_first_target_position для консистентности
- Добавлен тест для edge case: rate_above=nil + first_target вне диапазона + valid_rates не пуст
- Исправлены ссылки на issue #86 в комментариях
- Добавлена ссылка на issue #86 в документацию fallback метода

Fixes #86

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Исправлены ссылки issue #83#86 для UC-14
- Добавлен warn_log для аварийных путей в fallback_to_first_target_position
- Унифицирован debug_log — добавлена проверка defined?(Rails)
- Улучшены комментарии к методам логирования

Refs #86

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Удалён anomaly_threshold_percent из configuration.rb (UC-9 отменён)
- Удалены устаревшие стабы UC-9 из isolated_spec.rb и position_aware_spec.rb
- Исправлены ссылки #86#83 в position_aware.rb
- Добавлена документация edge cases для fallback_to_first_target_position

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Добавить raise ArgumentError в filtered_external_rates при nil external_rates
- Добавить raise ArgumentError в round_commission при nil value
- Раскомментировать after_commit :update_direction_rates (регрессия)
- Убрать allow_nil: true из валидации calculator_type (противоречит NOT NULL)
- Удалить неиспользуемый could_be_calculated? из RateComissionCalculator

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Вернуть закомментированный after_commit (было отключено намеренно в 1f04791)
- Добавить комментарий с объяснением почему отключено
- Добавить логирование когда rates пустой в DirectionsRatesWorker

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Resolve conflict: remove .claude/settings.local.json (deleted in legacy)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…us-fallback

feat: UC-14 — fallback на первую целевую позицию при отсутствии rate_above
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove the `income_payment_system_id <> outcome_payment_system_id` filter
from ExchangeRate.available scope. This legacy restriction prevented 35
crypto same-to-same directions (e.g. USDT TRC20 → USDT TRC20) from
appearing in cs.json, making them unavailable on the frontend despite
being enabled in the admin panel and visible in valuta.xml/BestChange.

Unify available_for_parser as alias of available since both scopes are
now identical.

Fixes alfagen/mercury#2291
Issue: alfagen/mercury#2291

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix(PIR-076): allow same-to-same payment system directions
…lable scope

Verify that ExchangeRate.available includes directions where
income_payment_system_id == outcome_payment_system_id.

Issue: alfagen/mercury#2291

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
test(PIR-076): regression test for same-to-same available scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants