File size: 4,047 Bytes
9d1eac9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import random
import json
import os
from datetime import datetime
import hashlib
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Configuration
HISTORY_FILE = "selection_history.json"

# 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"
]

# Initialize history file
def initialize_history_file():
    if not os.path.exists(HISTORY_FILE):
        with open(HISTORY_FILE, 'w') as f:
            json.dump([], f)

# Hash password
def hash_password(password):
    return hashlib.sha256(password.encode()).hexdigest()

# Authenticate user
def authenticate(username, password):
    stored_username = os.getenv("APP_USERNAME")
    stored_password_hash = os.getenv("APP_PASSWORD_HASH")
    return username == stored_username and hash_password(password) == stored_password_hash

# Team member selection
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

# Save history
def save_history(selection):
    with open(HISTORY_FILE, 'r+') as f:
        history = json.load(f)
        history.append(selection)
        f.seek(0)
        json.dump(history, f)
        f.truncate()

# Clear history
def clear_history():
    with open(HISTORY_FILE, 'w') as f:
        json.dump([], f)
    st.success("History cleared.")

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

    initialize_history_file()

    if 'authenticated' not in st.session_state:
        st.session_state.authenticated = False

    if 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}, Time: {timestamp} \n Selected members: {', '.join(selected_members)}")
                    save_history({"run": i + 1, "timestamp": timestamp, "members": selected_members})
                except ValueError as e:
                    st.error(str(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:
                timestamp = entry.get('timestamp', 'No timestamp available')
                st.write(f"Run {entry['run']}, Time: {timestamp}, Selected members: {', '.join(entry['members'])}")

        if st.button("Clear History"):
            clear_history()

        if st.button("Logout"):
            st.session_state.authenticated = False

if __name__ == "__main__":
    main()