83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
#!/usr/bin/env python
|
|
"""Test script to verify chart data is generated correctly"""
|
|
import os
|
|
import django
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PX360.settings')
|
|
django.setup()
|
|
|
|
from django.contrib.auth.models import User
|
|
from apps.surveys.models import SurveyInstance
|
|
from apps.surveys.ui_views import survey_instance_list
|
|
|
|
# Get the data by calling the view logic directly
|
|
from django.test import RequestFactory
|
|
|
|
# Create a fake request
|
|
factory = RequestFactory()
|
|
request = factory.get('/surveys/instances/')
|
|
|
|
# Create a test user
|
|
user, created = User.objects.get_or_create(
|
|
username='test_admin',
|
|
defaults={'is_superuser': True, 'is_staff': True}
|
|
)
|
|
|
|
request.user = user
|
|
|
|
# Call the view
|
|
try:
|
|
response = survey_instance_list(request)
|
|
|
|
# Extract context data
|
|
context = response.context_data
|
|
|
|
print("=== CHART DATA TEST RESULTS ===\n")
|
|
|
|
print("Score Distribution:")
|
|
for item in context['score_distribution']:
|
|
print(f" {item['range']}: {item['count']} surveys ({item['percentage']}%)")
|
|
|
|
print("\nEngagement Funnel:")
|
|
for item in context['engagement_funnel']:
|
|
print(f" {item['stage']}: {item['count']} surveys ({item['percentage']}%)")
|
|
|
|
print("\nCompletion Time Distribution:")
|
|
for item in context['completion_time_distribution']:
|
|
print(f" {item['range']}: {item['count']} surveys ({item['percentage']}%)")
|
|
|
|
print("\nDevice Distribution:")
|
|
for item in context['device_distribution']:
|
|
print(f" {item['name']}: {item['count']} surveys ({item['percentage']}%)")
|
|
|
|
print("\n=== VERIFICATION ===")
|
|
total_score = sum(item['count'] for item in context['score_distribution'])
|
|
print(f"Total surveys in score distribution: {total_score}")
|
|
|
|
total_engagement = sum(item['count'] for item in context['engagement_funnel'])
|
|
print(f"Total surveys in engagement funnel (first stage): {context['engagement_funnel'][0]['count']}")
|
|
|
|
total_time = sum(item['count'] for item in context['completion_time_distribution'])
|
|
print(f"Total surveys in completion time: {total_time}")
|
|
|
|
print("\n=== STATUS ===")
|
|
if total_score > 0:
|
|
print("✓ Score Distribution: HAS DATA")
|
|
else:
|
|
print("✗ Score Distribution: NO DATA")
|
|
|
|
if context['engagement_funnel'][0]['count'] > 0:
|
|
print("✓ Engagement Funnel: HAS DATA")
|
|
else:
|
|
print("✗ Engagement Funnel: NO DATA")
|
|
|
|
if total_time > 0:
|
|
print("✓ Completion Time: HAS DATA")
|
|
else:
|
|
print("✗ Completion Time: NO DATA")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|