@@ -10,6 +10,7 @@ import tempfile |
| 10 | 10 | from pathlib import Path |
| 11 | 11 | import random |
| 12 | 12 | import uuid |
| 13 | +import logging |
| 13 | 14 | |
| 14 | 15 | from rest_framework.decorators import api_view |
| 15 | 16 | from rest_framework.response import Response |
@@ -17,6 +18,8 @@ from rest_framework import status |
| 17 | 18 | from .markov import get_markov_instance |
| 18 | 19 | from .models import JubJubWord, WordDefinition, WordInteraction |
| 19 | 20 | |
| 21 | +logger = logging.getLogger(__name__) |
| 22 | + |
| 20 | 23 | |
| 21 | 24 | def get_or_create_session_id(request): |
| 22 | 25 | """Get or create a session ID for anonymous users""" |
@@ -56,7 +59,12 @@ def generate_words(request): |
| 56 | 59 | syllable_awareness = max(0.0, min(float(syllable_awareness), 1.0)) |
| 57 | 60 | |
| 58 | 61 | # 35/65 chance to show community word vs generate new |
| 59 | | - use_community = random.random() < 0.35 |
| 62 | + use_community = random.random() < 0.35 # Changed from 0.2 to 0.35 |
| 63 | + |
| 64 | + # Debug logging |
| 65 | + if use_community: |
| 66 | + total_community_words = JubJubWord.objects.filter(copy_count__gt=0).count() |
| 67 | + logger.info(f"Attempting community word selection. Total available: {total_community_words}") |
| 60 | 68 | |
| 61 | 69 | # Max attempts to avoid infinite loops |
| 62 | 70 | max_generation_attempts = 20 |
@@ -67,7 +75,10 @@ def generate_words(request): |
| 67 | 75 | |
| 68 | 76 | if use_community and not seed: # Don't use community words if user provided seed |
| 69 | 77 | # Try to get a popular community word, excluding the last shown word |
| 70 | | - query = JubJubWord.objects.filter(copy_count__gt=0) |
| 78 | + # Include words with definitions OR copies |
| 79 | + query = JubJubWord.objects.filter( |
| 80 | + Q(copy_count__gt=0) | Q(definition_count__gt=0) |
| 81 | + ) |
| 71 | 82 | if last_word: |
| 72 | 83 | query = query.exclude(word=last_word) |
| 73 | 84 | |
@@ -207,6 +218,8 @@ def track_copy(request): |
| 207 | 218 | session_id = get_or_create_session_id(request) |
| 208 | 219 | word_text = request.data.get('word', '').strip() |
| 209 | 220 | |
| 221 | + logger.info(f"Track copy called for word: {word_text}") |
| 222 | + |
| 210 | 223 | if not word_text: |
| 211 | 224 | return Response({'error': 'No word provided'}, status=400) |
| 212 | 225 | |
@@ -217,6 +230,10 @@ def track_copy(request): |
| 217 | 230 | word.copy_count = F('copy_count') + 1 |
| 218 | 231 | word.save(update_fields=['copy_count']) |
| 219 | 232 | |
| 233 | + # Refresh to get actual count |
| 234 | + word.refresh_from_db() |
| 235 | + logger.info(f"Word '{word_text}' now has {word.copy_count} copies") |
| 236 | + |
| 220 | 237 | # Track interaction |
| 221 | 238 | WordInteraction.objects.create( |
| 222 | 239 | word=word, |
@@ -230,6 +247,7 @@ def track_copy(request): |
| 230 | 247 | }) |
| 231 | 248 | |
| 232 | 249 | except Exception as e: |
| 250 | + logger.error(f"Error tracking copy: {str(e)}") |
| 233 | 251 | return Response({'error': str(e)}, status=500) |
| 234 | 252 | |
| 235 | 253 | |