File size: 4,530 Bytes
577ec3b
 
e6ecc3e
44e9020
 
e6ecc3e
 
 
a9086cb
 
e6ecc3e
baef142
e6ecc3e
 
 
fc2a80f
 
 
 
 
 
e6ecc3e
fc2a80f
e6ecc3e
 
fc2a80f
 
e6ecc3e
 
a9086cb
e6ecc3e
 
fc2a80f
 
 
 
 
 
 
 
44e9020
 
e6ecc3e
85eda91
a9086cb
 
e6ecc3e
fc2a80f
 
f4aa625
e6ecc3e
f4aa625
fc2a80f
 
 
 
 
 
 
9c9228c
fc2a80f
f4aa625
44e9020
37734a9
a9086cb
baef142
 
a9086cb
 
 
 
 
 
 
 
44e9020
fc2a80f
 
52246c7
990121a
baef142
44e9020
85eda91
44e9020
 
a9086cb
 
fc2a80f
 
 
 
 
85eda91
baef142
 
85eda91
 
baef142
 
 
 
 
 
 
 
 
 
 
fc2a80f
44e9020
37734a9
85eda91
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
import streamlit as st
import pandas as pd
import os

# μ‚¬μ΄λ“œλ°”μ—μ„œ νŽ˜μ΄μ§€ 선택
user_type = st.sidebar.selectbox("μ‚¬μš©μž μœ ν˜•μ„ μ„ νƒν•˜μ„Έμš”:", ["학생 응닡", "μ„€λ¬Έ μ„€μ •", "κ²°κ³Ό 확인"])

# μ„€λ¬Έ 데이터 파일 경둜
survey_file_path = "survey_data.csv"
responses_file_path = "responses_data.csv"

# μ„€λ¬Έ μ„€μ • νŽ˜μ΄μ§€ (κ°•μ‚¬μš©)
if user_type == "μ„€λ¬Έ μ„€μ •":
    st.title("μ„€λ¬Έ μ„€μ •")
    question = st.text_input("μ„€λ¬Έ μ§ˆλ¬Έμ„ μž…λ ₯ν•˜μ„Έμš”:")
    use_options = st.checkbox("객관식 μ˜΅μ…˜ μ‚¬μš©")
    options = []
    if use_options:
        options = st.text_area("μ„ νƒν˜• λ‹΅λ³€ ν•­λͺ©μ„ μž…λ ₯ν•˜μ„Έμš” (각 ν•­λͺ©μ„ μƒˆ 쀄에 μž…λ ₯):").split('\n')
        options = [option.strip() for option in options if option.strip()]  # 빈 μ˜΅μ…˜ 제거
    
    if st.button("μ„€λ¬Έ μ‹œμž‘"):
        if question:
            data = {
                'question': [question],
                'options': [options],
                'use_options': [use_options]
            }
            df = pd.DataFrame(data)
            df.to_csv(survey_file_path, index=False)
            st.success("섀문이 μ„€μ •λ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
        else:
            st.error("μ§ˆλ¬Έμ„ μž…λ ₯ν•˜μ„Έμš”.")
    
    if st.button("μ„€μ • μ΄ˆκΈ°ν™”"):
        if os.path.exists(survey_file_path):
            os.remove(survey_file_path)
        if os.path.exists(responses_file_path):
            os.remove(responses_file_path)
        st.success("λͺ¨λ“  μ„€μ •κ³Ό 응닡이 μ΄ˆκΈ°ν™”λ˜μ—ˆμŠ΅λ‹ˆλ‹€.")

# 학생 응닡 νŽ˜μ΄μ§€
elif user_type == "학생 응닡":
    st.title("μ„€λ¬Έ 응닡")
    if os.path.exists(survey_file_path):
        df = pd.read_csv(survey_file_path)
        question = df['question'][0]
        use_options = df['use_options'][0]
        options = eval(df['options'][0]) if use_options else []
        
        st.write(f"### {question}")
        
        if use_options and options:
            options.append("기타 (직접 μž…λ ₯)")
            selected_option = st.radio("닡변을 μ„ νƒν•˜μ„Έμš”:", options)
            if selected_option == "기타 (직접 μž…λ ₯)":
                answer = st.text_area("주관식 닡변을 μž…λ ₯ν•˜μ„Έμš”:")
            else:
                answer = selected_option
        else:
            answer = st.text_area("주관식 닡변을 μž…λ ₯ν•˜μ„Έμš”:")
        
        if st.button("λ‹΅λ³€ 제좜"):
            # 응닡 데이터 μ €μž₯
            response_data = {
                '응닡': [answer],
                'μœ ν˜•': ['객관식' if use_options and answer in options else '주관식']
            }
            response_df = pd.DataFrame(response_data)
            
            if os.path.exists(responses_file_path):
                response_df.to_csv(responses_file_path, mode='a', header=False, index=False)
            else:
                response_df.to_csv(responses_file_path, index=False)
            
            st.success("닡변이 μ œμΆœλ˜μ—ˆμŠ΅λ‹ˆλ‹€!")
            st.write("### λ‹΅λ³€ 제좜 μ™„λ£Œ")
            st.write(f"κ·€ν•˜μ˜ λ‹΅λ³€: {answer}")
            
    else:
        st.warning("섀문이 아직 μ„€μ •λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. κ°•μ‚¬μ—κ²Œ λ¬Έμ˜ν•˜μ„Έμš”.")

# κ²°κ³Ό 확인 νŽ˜μ΄μ§€ (κ°•μ‚¬μš©)
elif user_type == "κ²°κ³Ό 확인":
    st.title("μ„€λ¬Έ κ²°κ³Ό 확인")
    if os.path.exists(responses_file_path):
        df = pd.read_csv(responses_file_path)
        st.write("### 응닡 κ²°κ³Ό")
        if os.path.exists(survey_file_path):
            survey_df = pd.read_csv(survey_file_path)
            use_options = survey_df['use_options'][0]
            if use_options:
                options = eval(survey_df['options'][0])
                # 객관식 μ‘λ‹΅λ§Œ ν•„ν„°λ§ν•˜μ—¬ λ§‰λŒ€ κ·Έλž˜ν”„ 생성
                objective_responses = df[df['μœ ν˜•'] == '객관식']
                response_counts = objective_responses['응닡'].value_counts().reindex(options, fill_value=0)
                st.bar_chart(response_counts)
            
            # 주관식 응닡 ν‘œμ‹œ
            subjective_responses = df[df['μœ ν˜•'] == '주관식']
            if not subjective_responses.empty:
                st.write("### 주관식 응닡")
                st.table(subjective_responses['응닡'])
            else:
                st.info("아직 주관식 응닡이 μ—†μŠ΅λ‹ˆλ‹€.")
        
        # λͺ¨λ“  응닡 ν‘œμ‹œ
        st.write("### λͺ¨λ“  응닡")
        st.table(df)
    else:
        st.warning("아직 제좜된 닡변이 μ—†μŠ΅λ‹ˆλ‹€.")