tenseleyflow/jubjubword / af198d4

Browse files

fixed?

Authored by espadonne
SHA
af198d48876da4e217bd030d8e186913eafe5764
Parents
36b32ca
Tree
a1dda9a

1 changed file

StatusFile+-
M backend/jubjub/jubjubword/views.py 20 2
backend/jubjub/jubjubword/views.pymodified
@@ -10,6 +10,7 @@ import tempfile
1010
 from pathlib import Path
1111
 import random
1212
 import uuid
13
+import logging
1314
 
1415
 from rest_framework.decorators import api_view
1516
 from rest_framework.response import Response
@@ -17,6 +18,8 @@ from rest_framework import status
1718
 from .markov import get_markov_instance
1819
 from .models import JubJubWord, WordDefinition, WordInteraction
1920
 
21
+logger = logging.getLogger(__name__)
22
+
2023
 
2124
 def get_or_create_session_id(request):
2225
     """Get or create a session ID for anonymous users"""
@@ -56,7 +59,12 @@ def generate_words(request):
5659
         syllable_awareness = max(0.0, min(float(syllable_awareness), 1.0))
5760
 
5861
         # 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}")
6068
         
6169
         # Max attempts to avoid infinite loops
6270
         max_generation_attempts = 20
@@ -67,7 +75,10 @@ def generate_words(request):
6775
             
6876
             if use_community and not seed:  # Don't use community words if user provided seed
6977
                 # 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
+                )
7182
                 if last_word:
7283
                     query = query.exclude(word=last_word)
7384
                 
@@ -207,6 +218,8 @@ def track_copy(request):
207218
         session_id = get_or_create_session_id(request)
208219
         word_text = request.data.get('word', '').strip()
209220
         
221
+        logger.info(f"Track copy called for word: {word_text}")
222
+        
210223
         if not word_text:
211224
             return Response({'error': 'No word provided'}, status=400)
212225
         
@@ -217,6 +230,10 @@ def track_copy(request):
217230
         word.copy_count = F('copy_count') + 1
218231
         word.save(update_fields=['copy_count'])
219232
         
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
+        
220237
         # Track interaction
221238
         WordInteraction.objects.create(
222239
             word=word,
@@ -230,6 +247,7 @@ def track_copy(request):
230247
         })
231248
     
232249
     except Exception as e:
250
+        logger.error(f"Error tracking copy: {str(e)}")
233251
         return Response({'error': str(e)}, status=500)
234252
 
235253