File size: 4,265 Bytes
a543e33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
119
120
121
122
123
124
#!/usr/bin/env python3

import streamlit as st
import pandas as pd
import tempfile
import os
from pathlib import Path

def debug_session_state():
    """Debug function to check session state contents."""
    st.write("## Debug Session State")
    
    # Check if reference_lists exists
    if 'reference_lists' in st.session_state:
        st.write("**reference_lists found in session state**")
        
        for key, value in st.session_state.reference_lists.items():
            st.write(f"### {key}")
            st.write(f"Type: {type(value)}")
            
            if isinstance(value, dict):
                for sub_key, sub_value in value.items():
                    st.write(f"  - {sub_key}: {type(sub_value)}")
                    
                    if isinstance(sub_value, dict):
                        if sub_value.get('is_custom_config'):
                            st.write(f"    * Custom config:")
                            st.write(f"      - file_path: {sub_value.get('file_path')}")
                            st.write(f"      - word_column: {sub_value.get('word_column')}")
                            st.write(f"      - freq_column: {sub_value.get('freq_column')}")
                            st.write(f"      - delimiter: {sub_value.get('delimiter')}")
                        else:
                            st.write(f"    * Regular dict with {len(sub_value)} entries")
                    else:
                        st.write(f"    * Value: {sub_value}")
            else:
                st.write(f"  Value: {value}")
    else:
        st.write("**No reference_lists in session state**")
    
    # Check uploaded_file_configs
    if 'uploaded_file_configs' in st.session_state:
        st.write("**uploaded_file_configs found**")
        
        for key, value in st.session_state.uploaded_file_configs.items():
            st.write(f"### {key}")
            st.write(f"  - columns: {value.get('columns', [])}")
            st.write(f"  - base_name: {value.get('base_name', 'N/A')}")
            st.write(f"  - file_path: {value.get('file_path', 'N/A')}")
    else:
        st.write("**No uploaded_file_configs in session state**")

def clear_session_state():
    """Clear session state for debugging."""
    if st.button("Clear Session State"):
        for key in list(st.session_state.keys()):
            if key in ['reference_lists', 'uploaded_file_configs']:
                del st.session_state[key]
        st.success("Session state cleared")
        st.experimental_rerun()

def test_multi_config():
    """Test multi-configuration setup."""
    st.write("## Test Multi-Configuration")
    
    # Create test data
    test_data = """Type,POS,Headword,Rank,Freq,Range,NormFreq
the,,,1,60056,500,59001.119
of,,,2,30331,500,29798.237
and,,,3,28973,500,28464.091"""
    
    # Save to temp file
    temp_dir = tempfile.mkdtemp()
    test_file = os.path.join(temp_dir, "test_multi.csv")
    
    with open(test_file, 'w') as f:
        f.write(test_data)
    
    # Create configurations
    configs = [
        {
            'index_name': 'test_freq',
            'word_column': 'Type',
            'score_column': 'Freq'
        },
        {
            'index_name': 'test_range',
            'word_column': 'Type',
            'score_column': 'Range'
        }
    ]
    
    if st.button("Create Test Configurations"):
        # Initialize reference_lists
        if 'reference_lists' not in st.session_state:
            st.session_state.reference_lists = {}
        
        # Add configurations
        for config in configs:
            custom_data = {
                'file_path': test_file,
                'word_column': config['word_column'],
                'freq_column': config['score_column'],
                'delimiter': ',',
                'is_custom_config': True
            }
            
            st.session_state.reference_lists[config['index_name']] = {
                'token': custom_data
            }
        
        st.success("Test configurations created")
        st.experimental_rerun()

# Main app
def main():
    st.title("Debug Multi-Index Configuration")
    
    debug_session_state()
    clear_session_state()
    test_multi_config()

if __name__ == "__main__":
    main()