Files
rogaining_srv/debug_test_event.py

86 lines
3.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
"""
TestEventが検索でヒットしない問題のデバッグスクリプト
Deploy先でこのスクリプトを実行してください
実行方法:
docker compose exec app python debug_test_event.py
"""
import os
import django
# Django設定
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()
from rog.models import NewEvent2, Location2025
from django.db.models import Q
def debug_test_event():
print("=== TestEvent検索問題デバッグ ===")
# 1. 全イベント数
total_events = NewEvent2.objects.count()
print(f"総イベント数: {total_events}")
# 2. TestEventを含むイベントの検索大文字小文字区別なし
test_events = NewEvent2.objects.filter(event_name__icontains='testevent')
print(f"TestEventを含むイベント大小文字無視: {test_events.count()}")
for event in test_events:
print(f" - ID {event.id}: '{event.event_name}' (status: {event.status})")
# 3. Testを含むイベントの検索
test_partial = NewEvent2.objects.filter(event_name__icontains='test')
print(f"Testを含むイベント: {test_partial.count()}")
for event in test_partial:
print(f" - ID {event.id}: '{event.event_name}' (status: {event.status})")
# 4. 最近作成されたイベント上位10件
print("\n=== 最近作成されたイベント上位10件 ===")
recent_events = NewEvent2.objects.order_by('-id')[:10]
for event in recent_events:
print(f" - ID {event.id}: '{event.event_name}' (status: {event.status})")
# 5. 各種検索パターンテスト
print("\n=== 各種検索パターンテスト ===")
search_patterns = [
'TestEvent',
'testevent',
'Test',
'test',
'EVENT',
'event'
]
for pattern in search_patterns:
results = NewEvent2.objects.filter(event_name__icontains=pattern)
print(f"'{pattern}' を含むイベント: {results.count()}")
if results.count() > 0 and results.count() <= 3:
for event in results:
print(f" - '{event.event_name}'")
# 6. ステータス別イベント数
print("\n=== ステータス別イベント数 ===")
from django.db.models import Count
status_counts = NewEvent2.objects.values('status').annotate(count=Count('id')).order_by('status')
for item in status_counts:
print(f" {item['status']}: {item['count']}")
# 7. 特定の文字列での完全一致検索
print("\n=== 完全一致検索テスト ===")
exact_match = NewEvent2.objects.filter(event_name='TestEvent')
print(f"'TestEvent'完全一致: {exact_match.count()}")
if exact_match.exists():
for event in exact_match:
print(f" - ID {event.id}: '{event.event_name}' (status: {event.status})")
# 関連するLocation2025も確認
cp_count = Location2025.objects.filter(event=event).count()
print(f" 関連チェックポイント: {cp_count}")
if __name__ == '__main__':
debug_test_event()