-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
72 lines (56 loc) · 2.1 KB
/
main.py
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
import streamlit as st
import pandas as pd
import logging
from data_handling import (
record_choice,
initialize_experiment,
get_next_comparison,
)
from analysis_main import analyze_results
from config import attributes, display_names
# Set up logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def run_conjoint_experiment():
st.title("TCJA Conjoint Analysis Tool")
if "data" not in st.session_state:
st.session_state.data = []
if "num_comparisons" not in st.session_state:
st.session_state.num_comparisons = 0
# Initialize the experiment design
initialize_experiment(20) # Increased to 20 comparisons
# Display current analysis if there's data
if st.session_state.data:
with st.expander("Current Analysis", expanded=False):
analyze_results(st.session_state.data)
profile1, profile2 = get_next_comparison()
if profile1 and profile2:
st.write(
f"Comparison {st.session_state.num_comparisons + 1} of 20"
) # Updated to 20
col1, col2 = st.columns(2)
with col1:
st.write("Option 1")
for attr, value in profile1.items():
st.write(f"{display_names[attr]}: {value:.2f}")
if st.button("Choose Option 1"):
record_choice(profile1, profile2, 1)
with col2:
st.write("Option 2")
for attr, value in profile2.items():
st.write(f"{display_names[attr]}: {value:.2f}")
if st.button("Choose Option 2"):
record_choice(profile1, profile2, 2)
else:
st.write("All comparisons completed. Final analysis:")
analyze_results(st.session_state.data)
# Add a button to force analysis even if less than 20 comparisons
if (
st.session_state.num_comparisons >= 10
and st.session_state.num_comparisons < 20
):
if st.button("Finish and Analyze Results"):
st.write("Final analysis:")
analyze_results(st.session_state.data)
if __name__ == "__main__":
run_conjoint_experiment()