File size: 12,233 Bytes
d99d715
 
 
 
 
898cf42
d99d715
 
898cf42
d99d715
898cf42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import requests
import json
import os
import uuid
import streamlit as st
import math
from datetime import datetime, timedelta
from dotenv import load_dotenv
from typing import List

load_dotenv()

def get_question_topics():
    url = os.environ["BASE_URL"]+"/question-topics"
    headers = {
        "x-api-key": os.environ["API_KEY"]
    }
    try:
        response = requests.get(url,headers=headers)
        response.raise_for_status()
        return response.json()["output"]
    except Exception as e:
        print(f"Fehler beim Fetchen der Topics: {e}")
        st.error("Someting went wrong. Please try again later.", icon="🚨") 

def get_coding_task_topics():
    url = os.environ["BASE_URL"]+"/coding-task-topics"
    headers = {
        "x-api-key": os.environ["API_KEY"]
    }
    try:
        response = requests.get(url,headers=headers)
        response.raise_for_status()
        return response.json()["output"]
    except Exception as e:
        print(f"Fehler beim Fetchen der Topics: {e}")
        st.error("Someting went wrong. Please try again later.", icon="🚨") 

def get_questions(topic):
    url = os.environ["BASE_URL"]+"/questions"+f"?dimension={topic}"
    headers = {
        "x-api-key": os.environ["API_KEY"]
    }
    try:
        response = requests.get(url, data=topic, headers=headers)
        response.raise_for_status()
        # print(response.json())
        return response.json()["output"]
    except Exception as e:
        print(f"Fehler beim Fetchen der Topics: {e}")
        st.error("Someting went wrong. Please try again later.", icon="🚨")

def get_coding_tasks(topic):
    url = os.environ["BASE_URL"]+"/coding-tasks"+f"?topic={topic}"
    headers = {
        "x-api-key": os.environ["API_KEY"]
    }
    try:
        response = requests.get(url, data=topic, headers=headers)
        response.raise_for_status()
        print(response.json())
        return response.json()["output"]
    except Exception as e:
        print(f"Fehler beim Fetchen der Topics: {e}")
        st.error("Someting went wrong. Please try again later.", icon="🚨")

def load_topics_into_question_list():
    with st.spinner("Loading questions..."):
        for topic in st.session_state["loaded_questions"]:
            if topic["topic"] not in st.session_state["selected_topics"]:
                st.session_state["loaded_questions"].remove(topic)
        for topic in st.session_state["selected_topics"]:
            if topic not in [topic["topic"] for topic in st.session_state["loaded_questions"]]:
                question_element = {"topic": topic, "questions": get_questions(topic)}
                st.session_state["loaded_questions"].append(question_element)

def load_topics_into_task_list():
    with st.spinner("Loading coding tasks..."):
        for topic in st.session_state["loaded_tasks"]:
            if topic["topic"] not in st.session_state["selected_task_topics"]:
                st.session_state["loaded_tasks"].remove(topic)
        for topic in st.session_state["selected_task_topics"]:
            if topic not in [topic["topic"] for topic in st.session_state["loaded_tasks"]]:
                question_element = {"topic": topic, "tasks": get_coding_tasks(topic)}
                st.session_state["loaded_tasks"].append(question_element)

def add_question_to_interview(question):
    if question not in st.session_state["questions_for_interview"]:
        st.session_state["questions_for_interview"].append(question)
    else:
        print("Question already in list")

def increment_page():
    if st.session_state["current_page"] < math.ceil(len(st.session_state["questions_to_display"])/10):
        st.session_state["current_page"] += 1  

def decrement_page():
    if st.session_state["current_page"] > 1:
        st.session_state["current_page"] -= 1

def change_question_type():
    if st.session_state["question_type"] == "question":
        st.session_state["question_type"] = "coding_tasks"
    else:
        st.session_state["question_type"] = "question"

if "topics" not in st.session_state:
    topics = list(set([topic["dimension"] for topic in get_question_topics() if topic["dimension"] != None]))
    st.session_state["topics"] = topics
if "task_topics" not in st.session_state:
    topics = list(set([topic for topic in get_coding_task_topics() if topic != None]))
    st.session_state["task_topics"] = topics
if "loaded_questions" not in st.session_state:
    st.session_state["loaded_questions"] = []
if "loaded_tasks" not in st.session_state:
    st.session_state["loaded_tasks"] = []
if "selected_topics" not in st.session_state:
    st.session_state["selected_topics"] = []
if "questions_to_display" not in st.session_state:
    st.session_state["questions_to_display"] = []
if "tasks_to_display" not in st.session_state:
    st.session_state["tasks_to_display"] = []
if "questions_for_interview" not in st.session_state:
    st.session_state["questions_for_interview"] = []
if "current_page" not in st.session_state:
    st.session_state["current_page"] = 1
if "question_type" not in st.session_state:
    st.session_state["question_type"] = "question"
if "tasks_for_interview" not in st.session_state:
    st.session_state["tasks_for_interview"] = []

col1, col2 = st.columns([2, 1])

col1.title("Interview Preparation")
col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg")

type_col1, type_col2 = st.columns([1, 1])

with type_col1:
    st.button("Questions", key="question_button", on_click=change_question_type, disabled=True if st.session_state["question_type"] == "question" else False, use_container_width=True)
with type_col2:
    st.button("Coding tasks", key="coding_tasks", on_click=change_question_type, disabled=True if st.session_state["question_type"] == "coding_tasks" else False, use_container_width=True)


if st.session_state["question_type"] == "question":
    st.multiselect("Select the topics for the questions", st.session_state["topics"], key="selected_topics", default=None, on_change=load_topics_into_question_list)
    st.divider()
    if len(st.session_state["selected_topics"]) > 0:
        st.subheader("Questions to choose from:")
        st.write("Filter according to the difficulty of the questions:")
        st.checkbox("Easy", key="checkbox_filter_easy", value=True)
        st.checkbox("Medium", key="checkbox_filter_medium", value=True)
        st.checkbox("Hard", key="checkbox_filter_hard", value=True)
        st.write("Filter by the topic of the questions:")
        for topic in st.session_state["loaded_questions"]:
            st.checkbox(topic["topic"], key="checkbox_filter_"+topic["topic"], value=True)
        result_questions = []
        for i, topic in enumerate(st.session_state["loaded_questions"]):
            if st.session_state["checkbox_filter_"+topic["topic"]]:
                for j, question in enumerate(topic["questions"]):
                    if st.session_state["checkbox_filter_easy"] and question["difficulty"] == "Easy":
                        result_questions.append(question)
                    if st.session_state["checkbox_filter_medium"] and question["difficulty"] == "Medium":
                        result_questions.append(question)
                    if st.session_state["checkbox_filter_hard"] and question["difficulty"] == "Hard":
                        result_questions.append(question)
        st.session_state["questions_to_display"] = result_questions
        if len(st.session_state["questions_to_display"]) > 0:
            nav_col1, nav_col2, nav_col3 = st.columns([1, 4, 1])

            nav_col1.button("◀️", key="nav1", use_container_width=True, on_click=decrement_page, disabled=True if st.session_state["current_page"] == 1 else False)
            nav_col2.markdown(f"<div style='text-align: center;'>Page {str(st.session_state['current_page'])} / {str(math.ceil(len(st.session_state['questions_to_display'])/10))}</div>", unsafe_allow_html=True)
            nav_col3.button("▶️", key="nav2", use_container_width=True, on_click=increment_page, disabled=True if st.session_state["current_page"] == math.ceil(len(st.session_state["questions_to_display"])/10) else False)

            for i in range((st.session_state["current_page"]-1)*10, st.session_state["current_page"]*10 if st.session_state["current_page"]*10 < len(st.session_state["questions_to_display"]) else len(st.session_state["questions_to_display"])):
                col_1, col_2 = st.columns([7, 1])
                with col_1:
                    st.write(st.session_state["questions_to_display"][i]["question"])
                with col_2:
                    st.button("Select", disabled=True if st.session_state["questions_to_display"][i] in st.session_state["questions_for_interview"] else False ,key="select_button_"+str(i), on_click=add_question_to_interview, args=(st.session_state["questions_to_display"][i],))
else: 
    st.multiselect("Select the topics for the coding tasks", options=st.session_state["task_topics"], key="selected_task_topics", default=None, on_change=load_topics_into_task_list)      
    st.divider()
    if len(st.session_state["selected_task_topics"]) > 0:
        st.subheader("Coding tasks to choose from:")
        st.write("Filter by the topic of the coding task:")
        for topic in st.session_state["loaded_tasks"]:
            st.checkbox(topic["topic"], key="checkbox_filter_tasks_"+topic["topic"], value=True)
        result_tasks = []
        for i, topic in enumerate(st.session_state["loaded_tasks"]):
            if st.session_state["checkbox_filter_tasks_"+topic["topic"]]:
                for j, task in enumerate(topic["tasks"]):
                    result_tasks.append(task)
        st.session_state["tasks_to_display"] = result_tasks
        if len(st.session_state["tasks_to_display"]) > 0:
            nav_col1, nav_col2, nav_col3 = st.columns([1, 4, 1])

            nav_col1.button("◀️", key="nav1", use_container_width=True, on_click=decrement_page, disabled=True if st.session_state["current_page"] == 1 else False)
            nav_col2.markdown(f"<div style='text-align: center;'>Page {str(st.session_state['current_page'])} / {str(math.ceil(len(st.session_state['tasks_to_display'])/10))}</div>", unsafe_allow_html=True)
            nav_col3.button("▶️", key="nav2", use_container_width=True, on_click=increment_page, disabled=True if st.session_state["current_page"] == math.ceil(len(st.session_state["tasks_to_display"])/10) else False)

            for i in range((st.session_state["current_page"]-1)*10, st.session_state["current_page"]*10 if st.session_state["current_page"]*10 < len(st.session_state["tasks_to_display"]) else len(st.session_state["tasks_to_display"])):
                col_1, col_2 = st.columns([7, 1])
                with col_1:
                    st.write(st.session_state["tasks_to_display"][i]["task"])
                with col_2:
                    st.button("Select", disabled=True if st.session_state["tasks_to_display"][i] in st.session_state["tasks_for_interview"] else False ,key="select_button_tasks_"+str(i), on_click=st.session_state["tasks_for_interview"].append, args=(st.session_state["tasks_to_display"][i],))
st.divider()

st.subheader("Questions for the interview:")
if len(st.session_state["questions_for_interview"]) == 0:
    st.write("No questions selected yet.")
for i, question in enumerate(st.session_state["questions_for_interview"]):
    interview_col_1, interview_col_2 = st.columns([7, 1])
    with interview_col_1:
        st.write(question["question"])
    with interview_col_2:
        st.button("Remove", key="remove_button_"+str(i), on_click=st.session_state["questions_for_interview"].remove, args=(question,))
st.subheader("Coding tasks for the interview:")
if len(st.session_state["tasks_for_interview"]) == 0:
    st.write("No coding tasks selected yet.")
for i, task in enumerate(st.session_state["tasks_for_interview"]):
    interview_col_1, interview_col_2 = st.columns([7, 1])
    with interview_col_1:
        st.write(task["task"])
    with interview_col_2:
        st.button("Remove", key="remove_button_tasks_"+str(i), on_click=st.session_state["tasks_for_interview"].remove, args=(task,))
st.divider()