fix: update chart_service path from data/ to storage/

PR #86 moved state files to storage/ but missed chart_service.py,
which still pointed to data/charts.json. The file exists at
/app/storage/charts.json in the container but the code looked
in /app/data/charts.json, causing empty autocomplete results.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-03-20 20:29:05 -05:00
parent be4213aab6
commit 3c453c89ce

View File

@ -4,6 +4,7 @@ Chart Service for managing gameplay charts and infographics.
This service handles loading, saving, and managing chart definitions
from the JSON configuration file.
"""
import json
import logging
from pathlib import Path
@ -18,6 +19,7 @@ logger = logging.getLogger(__name__)
@dataclass
class Chart:
"""Represents a gameplay chart or infographic."""
key: str
name: str
category: str
@ -27,17 +29,17 @@ class Chart:
def to_dict(self) -> Dict[str, Any]:
"""Convert chart to dictionary (excluding key)."""
return {
'name': self.name,
'category': self.category,
'description': self.description,
'urls': self.urls
"name": self.name,
"category": self.category,
"description": self.description,
"urls": self.urls,
}
class ChartService:
"""Service for managing gameplay charts and infographics."""
CHARTS_FILE = Path(__file__).parent.parent / 'data' / 'charts.json'
CHARTS_FILE = Path(__file__).parent.parent / "storage" / "charts.json"
def __init__(self):
"""Initialize the chart service."""
@ -54,21 +56,21 @@ class ChartService:
self._categories = {}
return
with open(self.CHARTS_FILE, 'r') as f:
with open(self.CHARTS_FILE, "r") as f:
data = json.load(f)
# Load categories
self._categories = data.get('categories', {})
self._categories = data.get("categories", {})
# Load charts
charts_data = data.get('charts', {})
charts_data = data.get("charts", {})
for key, chart_data in charts_data.items():
self._charts[key] = Chart(
key=key,
name=chart_data['name'],
category=chart_data['category'],
description=chart_data.get('description', ''),
urls=chart_data.get('urls', [])
name=chart_data["name"],
category=chart_data["category"],
description=chart_data.get("description", ""),
urls=chart_data.get("urls", []),
)
logger.info(f"Loaded {len(self._charts)} charts from {self.CHARTS_FILE}")
@ -81,20 +83,17 @@ class ChartService:
def _save_charts(self) -> None:
"""Save charts to JSON file."""
try:
# Ensure data directory exists
# Ensure storage directory exists
self.CHARTS_FILE.parent.mkdir(parents=True, exist_ok=True)
# Build data structure
data = {
'charts': {
key: chart.to_dict()
for key, chart in self._charts.items()
},
'categories': self._categories
"charts": {key: chart.to_dict() for key, chart in self._charts.items()},
"categories": self._categories,
}
# Write to file
with open(self.CHARTS_FILE, 'w') as f:
with open(self.CHARTS_FILE, "w") as f:
json.dump(data, f, indent=2)
logger.info(f"Saved {len(self._charts)} charts to {self.CHARTS_FILE}")
@ -134,10 +133,7 @@ class ChartService:
Returns:
List of charts in the specified category
"""
return [
chart for chart in self._charts.values()
if chart.category == category
]
return [chart for chart in self._charts.values() if chart.category == category]
def get_chart_keys(self) -> List[str]:
"""
@ -157,8 +153,9 @@ class ChartService:
"""
return self._categories.copy()
def add_chart(self, key: str, name: str, category: str,
urls: List[str], description: str = "") -> None:
def add_chart(
self, key: str, name: str, category: str, urls: List[str], description: str = ""
) -> None:
"""
Add a new chart.
@ -176,18 +173,19 @@ class ChartService:
raise BotException(f"Chart '{key}' already exists")
self._charts[key] = Chart(
key=key,
name=name,
category=category,
description=description,
urls=urls
key=key, name=name, category=category, description=description, urls=urls
)
self._save_charts()
logger.info(f"Added chart: {key}")
def update_chart(self, key: str, name: Optional[str] = None,
category: Optional[str] = None, urls: Optional[List[str]] = None,
description: Optional[str] = None) -> None:
def update_chart(
self,
key: str,
name: Optional[str] = None,
category: Optional[str] = None,
urls: Optional[List[str]] = None,
description: Optional[str] = None,
) -> None:
"""
Update an existing chart.