analyze_answer_list.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. require __DIR__.'/vendor/autoload.php';
  3. $app = require_once __DIR__.'/bootstrap/app.php';
  4. $kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
  5. $kernel->bootstrap();
  6. // Read the most recent Aliyun response from logs
  7. $logFile = storage_path('logs/laravel.log');
  8. $lines = file($logFile);
  9. // Find the last "Aliyun Data Preview" entry
  10. $lastDataPreview = null;
  11. foreach (array_reverse($lines) as $line) {
  12. if (strpos($line, 'Aliyun Data Preview') !== false && strpos($line, '"data"') !== false) {
  13. $lastDataPreview = $line;
  14. break;
  15. }
  16. }
  17. if ($lastDataPreview) {
  18. // Extract JSON from log line
  19. preg_match('/"data":"(.+?)"}/', $lastDataPreview, $matches);
  20. if (isset($matches[1])) {
  21. $jsonStr = $matches[1];
  22. // Unescape
  23. $jsonStr = str_replace('\\"', '"', $jsonStr);
  24. $jsonStr = str_replace('\\\\', '\\', $jsonStr);
  25. $data = json_decode($jsonStr, true);
  26. if ($data && isset($data['page_list'][0]['answer_list'])) {
  27. echo "=== Answer List Structure ===\n\n";
  28. foreach ($data['page_list'][0]['answer_list'] as $i => $answer) {
  29. echo "Answer #{$i} (Question ID: " . json_encode($answer['ids'] ?? []) . "):\n";
  30. echo " Text: " . ($answer['text'] ?? 'N/A') . "\n";
  31. echo " All keys: " . implode(', ', array_keys($answer)) . "\n\n";
  32. if ($i >= 2) break; // Show first 3 answers
  33. }
  34. // Check if there's a pattern we can use
  35. echo "\n=== Analysis ===\n";
  36. echo "Total answers found: " . count($data['page_list'][0]['answer_list']) . "\n";
  37. // Check if text contains just the answer letter
  38. $firstAnswer = $data['page_list'][0]['answer_list'][0];
  39. $text = $firstAnswer['text'] ?? '';
  40. echo "First answer text length: " . mb_strlen($text) . " characters\n";
  41. echo "First answer text: " . $text . "\n";
  42. } else {
  43. echo "No answer_list found in response\n";
  44. echo "Available keys in page_list[0]: " . implode(', ', array_keys($data['page_list'][0] ?? [])) . "\n";
  45. }
  46. }
  47. } else {
  48. echo "No Aliyun Data Preview found in logs\n";
  49. }