File size: 5,492 Bytes
e8510d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import sqlite3
import json
import logging
import sys
import os

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def inspect_cache_db(db_path):
    """Inspect an ELS cache database file for Quran ELS results with gematria sum 5642."""
    logger.info(f"Inspecting ELS cache database: {db_path}")
    
    if not os.path.exists(db_path):
        logger.error(f"Database file not found: {db_path}")
        return
        
    try:
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        
        # Check if the table exists
        cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='els_cache'")
        if not cursor.fetchone():
            logger.error("No 'els_cache' table found in database")
            conn.close()
            return
            
        # Query for Quran results with gematria sum 5642
        cursor.execute("SELECT * FROM els_cache WHERE function_name LIKE '%quran%' AND args LIKE '%5642%'")
        results = cursor.fetchall()
        
        if not results:
            logger.info("No matching Quran ELS cache entries found with gematria sum 5642")
            
            # Try with just the function name
            cursor.execute("SELECT * FROM els_cache WHERE function_name LIKE '%quran%'")
            quran_results = cursor.fetchall()
            logger.info(f"Total Quran-related cache entries: {len(quran_results)}")
            
            if quran_results:
                # Show a few examples
                for i, row in enumerate(quran_results[:3]):
                    try:
                        # Try to extract gematria sum from args
                        args_dict = json.loads(row[2]) if row[2] else {}
                        step = args_dict.get('step', 'unknown')
                        logger.info(f"Example {i+1}: function={row[1]}, step={step}")
                        
                        # Try to parse the results to extract the ELS text
                        if row[4]:  # results column
                            els_results = json.loads(row[4])
                            if isinstance(els_results, list) and els_results:
                                logger.info(f"  First result text: {els_results[0].get('result_text', 'N/A')}")
                                logger.info(f"  Gematria: {els_results[0].get('gematria', 'N/A')}")
                    except (json.JSONDecodeError, IndexError) as e:
                        logger.error(f"Error parsing cache entry: {e}")
        else:
            logger.info(f"Found {len(results)} matching cache entries")
            
            # Display the matched entries
            for i, row in enumerate(results):
                try:
                    query_hash = row[0] if len(row) > 0 else 'N/A'
                    function_name = row[1] if len(row) > 1 else 'N/A'
                    args = row[2] if len(row) > 2 else '{}'
                    
                    logger.info(f"Entry {i+1}:")
                    logger.info(f"  Query hash: {query_hash}")
                    logger.info(f"  Function: {function_name}")
                    
                    # Parse the args
                    args_dict = json.loads(args)
                    pretty_args = json.dumps(args_dict, indent=2)
                    logger.info(f"  Args: {pretty_args}")
                    
                    # Parse and display the results
                    if len(row) > 4 and row[4]:
                        results_data = json.loads(row[4])
                        
                        if isinstance(results_data, list):
                            logger.info(f"  Results count: {len(results_data)}")
                            
                            for j, result in enumerate(results_data[:3]):  # Show up to 3 results
                                if isinstance(result, dict):
                                    result_text = result.get('result_text', 'N/A')
                                    gematria = result.get('gematria', 'N/A')
                                    step = result.get('step', 'N/A')
                                    logger.info(f"    Result {j+1}: text={result_text}, gematria={gematria}, step={step}")
                        elif isinstance(results_data, dict):
                            logger.info("  Results is a dictionary")
                            result_text = results_data.get('result_text', 'N/A')
                            gematria = results_data.get('gematria', 'N/A')
                            step = results_data.get('step', 'N/A')
                            logger.info(f"    Result: text={result_text}, gematria={gematria}, step={step}")
                        else:
                            logger.info("  Results is not a list")
                except Exception as e:
                    logger.error(f"Error processing cache entry: {e}")
                    
        conn.close()
        
    except sqlite3.Error as e:
        logger.error(f"SQLite error: {e}")
    except Exception as e:
        logger.error(f"Unexpected error: {e}")

if __name__ == "__main__":
    # Check daily_psalm cache
    daily_psalm_db = "/run/media/julian/ML2/Python/bos-network/daily_psalm/els_cache.db"
    inspect_cache_db(daily_psalm_db)
    
    print("\n" + "-"*50 + "\n")
    
    # Check daily-psalms-api cache
    api_db = "/run/media/julian/ML2/Python/bos-network/daily-psalms-api/els_cache.db"
    inspect_cache_db(api_db)