File size: 3,545 Bytes
76e2d7a
 
 
 
 
 
d4040f5
 
 
76e2d7a
140daf4
76e2d7a
140daf4
 
 
 
 
 
 
76e2d7a
 
140daf4
 
76e2d7a
140daf4
 
 
 
76e2d7a
d4040f5
76e2d7a
 
 
 
 
 
 
 
 
d4040f5
76e2d7a
140daf4
76e2d7a
140daf4
 
76e2d7a
 
d4040f5
 
 
 
 
 
140daf4
 
 
76e2d7a
140daf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d4040f5
 
 
 
 
 
 
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
import streamlit as st
import random
import json
import os
from datetime import datetime

# Configuration for authentication
USERNAME = "admin"
PASSWORD = "password123"

# List of team members
team_members = [
    "Akhil", "Sarthak", "Sai Charitha", "Prasad K", "Anand S",
    "Harsh Naik", "Divya Singh", "Ritesh Kumar Tiwary",
    "Balamurali Ommi", "Lalit Singh", "Bhavana K", "Bickramjit Basu",
    "C R Tejavardhan", "Ashok M", "Harshitha T", "Man Mohan Nayak",
    "Prasad Dattatray Amale", "Praveena Bharathi", "Ranga Bhashyams",
    "Sahil Singh Diwan", "Sathwika", "Sayali Vinod", "Yashwanth Gundala",
    "Gopinath", "Arun Kumar Tiwary"
]

# File path to store history
HISTORY_FILE = "selection_history.json"

# Initialize the history file if it doesn't exist
if not os.path.exists(HISTORY_FILE):
    with open(HISTORY_FILE, 'w') as f:
        json.dump([], f)

# Function to select random team members
def select_members(members, last_selected, num_to_select=2):
    available_members = [member for member in members if member not in last_selected]
    if len(available_members) < num_to_select:
        raise ValueError("Not enough members to select from without repeating the last pair.")
    selected_members = random.sample(available_members, num_to_select)
    last_selected.clear()
    last_selected.extend(selected_members)
    return selected_members

# Function to save history
def save_history(selection):
    with open(HISTORY_FILE, 'r') as f:
        history = json.load(f)
    history.append(selection)
    with open(HISTORY_FILE, 'w') as f:
        json.dump(history, f)

# Function to clear history
def clear_history():
    with open(HISTORY_FILE, 'w') as f:
        json.dump([], f)

# Authentication
def authenticate(username, password):
    return username == USERNAME and password == PASSWORD

# Streamlit UI
st.title("AI Learning Presentation - Team Member Selection")

# Login
if 'authenticated' not in st.session_state or not st.session_state.authenticated:
    username = st.text_input("Username")
    password = st.text_input("Password", type="password")
    if st.button("Login"):
        if authenticate(username, password):
            st.session_state.authenticated = True
            st.success("Logged in successfully!")
        else:
            st.error("Invalid username or password")
else:
    st.write("Select random team members for the next session.")

    num_selections = st.slider("Number of times to run the selection", 1, 10, 3)

    if st.button("Run Selection"):
        last_selected = []

        for i in range(num_selections):
            try:
                selected_members = select_members(team_members, last_selected)
                timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                st.write(f"Run {i + 1} - Selected members: {', '.join(selected_members)} at {timestamp}")
                save_history({"run": i + 1, "members": selected_members, "timestamp": timestamp})
            except ValueError as e:
                st.error(e)

    if st.button("View History"):
        with open(HISTORY_FILE, 'r') as f:
            history = json.load(f)
        st.write("Selection History:")
        for entry in history:
            # Handle the absence of 'timestamp' in older entries
            timestamp = entry.get('timestamp', 'N/A')
            st.write(f"Run {entry['run']} - Selected members: {', '.join(entry['members'])} at {timestamp}")

    if st.button("Clear History"):
        clear_history()
        st.success("History cleared successfully!")