Spaces:
Sleeping
Sleeping
shaileshjadhavSS
Solved start test button issue and Added python, django, Data engineering and common questions
2b130d1 | import os | |
| import streamlit as st | |
| from settings import BASE_DIR, NUMBER_OF_TECHNICAL_QUESTIONS, NUMBER_OF_COMMON_QUESTIONS | |
| from core.slack_notifier import SlackNotifier | |
| from core.questions_loader_local import QuestionLoaderLocal | |
| from presentation.layout import Layout | |
| # Slack Webhook | |
| SLACK_WEBHOOK_URL = os.environ["SLACK_WEBHOOK_URL"] | |
| layout = Layout() | |
| def call(): | |
| # Check if questions are already loaded | |
| if 'questions' not in st.session_state: | |
| # Define questions | |
| questions = QuestionLoaderLocal( | |
| os.path.join(BASE_DIR, "questions", st.session_state['technology'].lower(), "questions.csv"), | |
| NUMBER_OF_TECHNICAL_QUESTIONS | |
| ).fetch_questions() | |
| common_questions = QuestionLoaderLocal( | |
| os.path.join(BASE_DIR, "questions", "common", "questions.csv"), | |
| NUMBER_OF_COMMON_QUESTIONS | |
| ).fetch_questions() | |
| questions.extend(common_questions) | |
| # Store questions in session state to persist across interactions | |
| st.session_state['questions'] = questions | |
| # Retrieve the questions from session state | |
| questions = st.session_state['questions'] | |
| score = 0 | |
| total_questions = len(questions) | |
| answered_all = True | |
| for idx, question in enumerate(questions): | |
| # Section for each question with styling | |
| selected_option = layout.render_test_question(question, idx) | |
| if not selected_option: | |
| answered_all = False | |
| # Checking for correct answer and assigning points based on difficulty | |
| if selected_option == question['answer']: | |
| score += 1 | |
| if st.button("Submit Test", use_container_width=True, type="primary"): | |
| if answered_all: | |
| st.session_state['test_started'] = False | |
| layout.render_completion_message(score, total_questions) | |
| result = (score / total_questions) * 100 | |
| SlackNotifier(SLACK_WEBHOOK_URL).send_candidate_info( | |
| st.session_state['name'], | |
| st.session_state['email'], | |
| st.session_state['experience'], | |
| st.session_state['technology'], | |
| f"{result:.2f}%" | |
| ) | |
| else: | |
| # Show a message asking the user to answer all questions | |
| st.warning("Please answer all questions before submitting.") | |
| def main(): | |
| # Set page config with custom title and layout | |
| st.set_page_config(page_title="Candidate MCQ Platform", layout="wide") | |
| layout.render_header() | |
| if 'test_started' not in st.session_state: | |
| st.session_state['test_started'] = False | |
| if not st.session_state['test_started']: | |
| st.title("Welcome to the Candidate Assessment Platform") | |
| name, email, experience, technology, submit = layout.render_signup_form() | |
| if name and email: | |
| st.session_state['name'] = name | |
| st.session_state['email'] = email | |
| st.session_state['experience'] = experience | |
| st.session_state['technology'] = technology | |
| st.session_state['test_wip'] = True | |
| if submit: | |
| st.session_state['test_started'] = True | |
| st.rerun() | |
| layout.render_instructions() | |
| else: | |
| call() | |
| if __name__ == "__main__": | |
| main() | |