fix: resolve linting issues in token efficiency implementation
Some checks failed
CI / test (pull_request) Has been cancelled
Some checks failed
CI / test (pull_request) Has been cancelled
- Fix ambiguous variable names (l → layer) - Remove unused imports and variables - Organize import statements Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,8 +13,8 @@ import hashlib
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass
|
||||||
from typing import Any, TYPE_CHECKING
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from src.brain.gemini_client import TradeDecision
|
from src.brain.gemini_client import TradeDecision
|
||||||
@@ -26,7 +26,7 @@ logger = logging.getLogger(__name__)
|
|||||||
class CacheEntry:
|
class CacheEntry:
|
||||||
"""Cached decision with metadata."""
|
"""Cached decision with metadata."""
|
||||||
|
|
||||||
decision: "TradeDecision"
|
decision: TradeDecision
|
||||||
cached_at: float # Unix timestamp
|
cached_at: float # Unix timestamp
|
||||||
hit_count: int = 0
|
hit_count: int = 0
|
||||||
market_data_hash: str = ""
|
market_data_hash: str = ""
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ class ContextSelector:
|
|||||||
selected_layers = [layer for layer, score in scores.items() if score >= min_score]
|
selected_layers = [layer for layer, score in scores.items() if score >= min_score]
|
||||||
|
|
||||||
# Sort by score (descending)
|
# Sort by score (descending)
|
||||||
selected_layers.sort(key=lambda l: scores[l], reverse=True)
|
selected_layers.sort(key=lambda layer: scores[layer], reverse=True)
|
||||||
|
|
||||||
total_score = sum(scores[layer] for layer in selected_layers)
|
total_score = sum(scores[layer] for layer in selected_layers)
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ from typing import Any
|
|||||||
|
|
||||||
from google import genai
|
from google import genai
|
||||||
|
|
||||||
from src.config import Settings
|
|
||||||
from src.brain.cache import DecisionCache
|
from src.brain.cache import DecisionCache
|
||||||
from src.brain.prompt_optimizer import PromptOptimizer
|
from src.brain.prompt_optimizer import PromptOptimizer
|
||||||
|
from src.config import Settings
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import re
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
# Abbreviation mapping for common terms
|
# Abbreviation mapping for common terms
|
||||||
ABBREVIATIONS = {
|
ABBREVIATIONS = {
|
||||||
"price": "P",
|
"price": "P",
|
||||||
|
|||||||
@@ -176,9 +176,6 @@ class ContextSummarizer:
|
|||||||
Returns:
|
Returns:
|
||||||
Dictionary with recent (detailed) and historical (summary) data
|
Dictionary with recent (detailed) and historical (summary) data
|
||||||
"""
|
"""
|
||||||
now = datetime.now(UTC)
|
|
||||||
cutoff = now - timedelta(days=window_days)
|
|
||||||
|
|
||||||
result: dict[str, Any] = {
|
result: dict[str, Any] = {
|
||||||
"window_days": window_days,
|
"window_days": window_days,
|
||||||
"recent_data": {},
|
"recent_data": {},
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from google import genai
|
|||||||
|
|
||||||
from src.config import Settings
|
from src.config import Settings
|
||||||
from src.db import init_db
|
from src.db import init_db
|
||||||
from src.logging.decision_logger import DecisionLog, DecisionLogger
|
from src.logging.decision_logger import DecisionLogger
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ from src.broker.overseas import OverseasBroker
|
|||||||
from src.config import Settings
|
from src.config import Settings
|
||||||
from src.context.layer import ContextLayer
|
from src.context.layer import ContextLayer
|
||||||
from src.context.store import ContextStore
|
from src.context.store import ContextStore
|
||||||
from src.core.criticality import CriticalityAssessor, CriticalityLevel
|
from src.core.criticality import CriticalityAssessor
|
||||||
from src.core.priority_queue import PriorityTaskQueue
|
from src.core.priority_queue import PriorityTaskQueue
|
||||||
from src.core.risk_manager import CircuitBreakerTripped, RiskManager
|
from src.core.risk_manager import CircuitBreakerTripped, RiskManager
|
||||||
from src.db import init_db, log_trade
|
from src.db import init_db, log_trade
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ from __future__ import annotations
|
|||||||
import json
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import tempfile
|
import tempfile
|
||||||
from datetime import UTC, datetime, timedelta
|
from datetime import UTC, datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
from unittest.mock import AsyncMock, Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from src.config import Settings
|
from src.config import Settings
|
||||||
from src.db import init_db, log_trade
|
from src.db import init_db, log_trade
|
||||||
from src.evolution.ab_test import ABTester, ABTestResult, StrategyPerformance
|
from src.evolution.ab_test import ABTester
|
||||||
from src.evolution.optimizer import EvolutionOptimizer
|
from src.evolution.optimizer import EvolutionOptimizer
|
||||||
from src.evolution.performance_tracker import (
|
from src.evolution.performance_tracker import (
|
||||||
PerformanceDashboard,
|
PerformanceDashboard,
|
||||||
@@ -28,7 +28,6 @@ from src.evolution.performance_tracker import (
|
|||||||
)
|
)
|
||||||
from src.logging.decision_logger import DecisionLogger
|
from src.logging.decision_logger import DecisionLogger
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Fixtures
|
# Fixtures
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|||||||
@@ -12,11 +12,10 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
from datetime import UTC, datetime, timedelta
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from src.brain.cache import CacheMetrics, DecisionCache
|
from src.brain.cache import DecisionCache
|
||||||
from src.brain.context_selector import ContextSelector, DecisionType
|
from src.brain.context_selector import ContextSelector, DecisionType
|
||||||
from src.brain.gemini_client import TradeDecision
|
from src.brain.gemini_client import TradeDecision
|
||||||
from src.brain.prompt_optimizer import PromptOptimizer, TokenMetrics
|
from src.brain.prompt_optimizer import PromptOptimizer, TokenMetrics
|
||||||
@@ -24,7 +23,6 @@ from src.context.layer import ContextLayer
|
|||||||
from src.context.store import ContextStore
|
from src.context.store import ContextStore
|
||||||
from src.context.summarizer import ContextSummarizer, SummaryStats
|
from src.context.summarizer import ContextSummarizer, SummaryStats
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Prompt Optimizer Tests
|
# Prompt Optimizer Tests
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
@@ -294,7 +292,7 @@ class TestContextSelector:
|
|||||||
# Should only select high-relevance layers
|
# Should only select high-relevance layers
|
||||||
assert len(selection.layers) >= 1
|
assert len(selection.layers) >= 1
|
||||||
assert ContextLayer.L7_REALTIME in selection.layers
|
assert ContextLayer.L7_REALTIME in selection.layers
|
||||||
assert all(selection.relevance_scores[l] >= 0.5 for l in selection.layers)
|
assert all(selection.relevance_scores[layer] >= 0.5 for layer in selection.layers)
|
||||||
|
|
||||||
def test_get_context_data(self, store):
|
def test_get_context_data(self, store):
|
||||||
"""Test context data retrieval."""
|
"""Test context data retrieval."""
|
||||||
|
|||||||
Reference in New Issue
Block a user