|
import random |
|
import pandas as pd |
|
import streamlit as st |
|
import streamlit_authenticator as stauth |
|
from yaml.loader import SafeLoader |
|
import yaml |
|
|
|
|
|
custom_footer = """ |
|
<style> |
|
footer{ |
|
visibility:visible; |
|
} |
|
footer:before{ |
|
content: 'Made by Primoz Konda @ [email protected]'; |
|
display:block; |
|
position:relative; |
|
color:tomato; |
|
} |
|
</style> |
|
""" |
|
|
|
|
|
with open('config.yaml') as file: |
|
config = yaml.load(file, Loader=SafeLoader) |
|
|
|
|
|
authenticator = stauth.Authenticate( |
|
config['credentials'], |
|
config['cookie']['name'], |
|
config['cookie']['key'], |
|
config['cookie']['expiry_days'], |
|
config['preauthorized'] |
|
) |
|
|
|
|
|
csv_file = 'questions_working.csv' |
|
|
|
|
|
def load_dataset(): |
|
return pd.read_csv(csv_file, encoding='latin1') |
|
|
|
questions_df = load_dataset() |
|
|
|
|
|
def select_random_question(level): |
|
unused_questions = questions_df[(questions_df['Level'] == level) & (questions_df['Status'] == 'Not Asked')] |
|
|
|
|
|
if unused_questions.empty: |
|
|
|
questions_df['Status'] = 'Not Asked' |
|
questions_df.to_csv(csv_file, index=False) |
|
unused_questions = questions_df[(questions_df['Level'] == level) & (questions_df['Status'] == 'Not Asked')] |
|
|
|
|
|
min_count = unused_questions['Count'].min() |
|
unused_questions_min_count = unused_questions[unused_questions['Count'] == min_count] |
|
|
|
selected_question_idx = random.choice(unused_questions_min_count.index) |
|
selected_question = questions_df.at[selected_question_idx, 'Question'] |
|
|
|
|
|
questions_df.at[selected_question_idx, 'Count'] += 1 |
|
questions_df.at[selected_question_idx, 'Status'] = 'Asked' |
|
questions_df.to_csv(csv_file, index=False) |
|
|
|
|
|
return selected_question, questions_df.at[selected_question_idx, 'ID'] |
|
|
|
|
|
def main(): |
|
|
|
st.sidebar.image("https://yt3.googleusercontent.com/ytc/AOPolaRAsNhgTRqpu-8yuBtkVa3rg1dk7dhm4lz3kRHz=s900-c-k-c0x00ffffff-no-rj", width=150) |
|
st.title("Applied Quantitative Methods") |
|
st.header("Exam Question Generator") |
|
st.markdown(custom_footer, unsafe_allow_html=True) |
|
|
|
|
|
name, authentication_status, username = authenticator.login('Login', 'sidebar') |
|
if authentication_status: |
|
authenticator.logout('Logout', 'sidebar') |
|
st.sidebar.write(f'Welcome, {name}') |
|
|
|
app_logic() |
|
elif authentication_status == False: |
|
st.error('Username/password is incorrect') |
|
elif authentication_status == None: |
|
st.warning('Please enter your username and password') |
|
|
|
def app_logic(): |
|
|
|
st.sidebar.header("Insert a Number") |
|
student_seed = st.sidebar.text_input("Enter a number between 1 and 100:") |
|
|
|
|
|
|
|
|
|
|
|
|
|
if st.sidebar.button("Pick up Questions"): |
|
if not student_seed: |
|
st.warning("Please enter a student seed.") |
|
else: |
|
try: |
|
student_seed = int(student_seed) + random.randint(1, 100) |
|
generate_question(student_seed) |
|
except ValueError: |
|
st.warning("Student seed must be an integer.") |
|
|
|
|
|
for _ in range(4): |
|
st.sidebar.text("") |
|
|
|
|
|
|
|
if st.sidebar.button("Reset dataset"): |
|
reset_dataset() |
|
st.success("Dataset has been reset.") |
|
|
|
|
|
def generate_question(student_seed): |
|
random.seed(student_seed) |
|
|
|
|
|
easy_question_1, id1 = select_random_question('Easy') |
|
easy_question_2, id2 = select_random_question('Easy') |
|
very_easy_question, id3 = select_random_question('Very Easy') |
|
moderate_question, id4 = select_random_question('Moderate') |
|
|
|
if all([easy_question_1, easy_question_2, very_easy_question, moderate_question]): |
|
|
|
st.markdown('---') |
|
st.write("### Easy Questions") |
|
st.markdown(f"**ID: {id1}** \n\n <span style='font-size:1.3em; font-weight:bold;'>{easy_question_1}</span>", unsafe_allow_html=True) |
|
st.markdown(f"**ID: {id2}** \n\n <span style='font-size:1.3em; font-weight:bold;'>{easy_question_2}</span>", unsafe_allow_html=True) |
|
|
|
|
|
|
|
|
|
st.markdown('---') |
|
st.write("### Mixed Questions") |
|
st.markdown(f"**ID: {id3}** \n\n <span style='font-size:1.3em; font-weight:bold;'>{very_easy_question}</span>", unsafe_allow_html=True) |
|
st.markdown(f"**ID: {id4}** \n\n <span style='font-size:1.3em; font-weight:bold;'>{moderate_question}</span>", unsafe_allow_html=True) |
|
|
|
|
|
|
|
|
|
def reset_dataset(): |
|
global questions_df |
|
questions_df = load_dataset() |
|
questions_df['Status'] = 'Not Asked' |
|
questions_df['Count'] = 0 |
|
questions_df.to_csv(csv_file, index=False) |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|