-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
131 lines (105 loc) · 4.17 KB
/
Copy pathapp.py
File metadata and controls
131 lines (105 loc) · 4.17 KB
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
import streamlit as st
import numpy as np
import pandas as pd
import io
# Define constants
criteria = ["Depth Perception", "Clarity", "Halo Effect", "Adjustment", "Contrast", "Weight"]
alternatives = ["NVG A", "NVG B", "NVG C", "NVG D", "NVG E", "NVG F", "NVG G"]
saaty_scale = {
"1 - Equal Importance": 1,
"2 - Between Equal and Moderate": 2,
"3 - Moderate Importance": 3,
"4 - Between Moderate and Strong": 4,
"5 - Strong Importance": 5,
"6 - Between Strong and Very Strong": 6,
"7 - Very Strong Importance": 7,
"8 - Between Very Strong and Extreme": 8,
"9 - Extreme Importance": 9
}
linguistic_scale = {
"Very Poor (VP)": (0, 0, 1),
"Poor (P)": (0, 1, 3),
"Medium Poor (MP)": (1, 3, 5),
"Fair (F)": (3, 5, 7),
"Medium Good (MG)": (5, 7, 9),
"Good (G)": (7, 9, 10),
"Very Good (VG)": (9, 10, 10)
}
st.title("Night Vision Goggle (NVG) Evaluation - User Selections")
if 'step' not in st.session_state:
st.session_state.step = 0
# Step 0: User ID Selection
if st.session_state.step == 0:
st.header("Login")
user_options = [f"User{str(i).zfill(3)}" for i in range(1, 11)] + ["Manual Entry"]
selected_option = st.selectbox("Choose Your User ID", user_options)
if selected_option == "Manual Entry":
manual_input = st.text_input("Enter Your User Number (Digits Only)")
if manual_input.isdigit():
user_id = f"User{manual_input.lstrip('0').zfill(3)}"
else:
user_id = None
st.warning("Please enter **digits only** (e.g., 12 → User012)")
else:
user_id = selected_option
if st.button("Login"):
if not user_id:
st.error("Invalid User ID.")
else:
st.session_state.user_id = user_id
st.success(f"Welcome, {user_id}!")
st.session_state.step = 1
# Step 1: Pairwise Comparison Matrix Input
elif st.session_state.step == 1:
st.header("Step 1: Pairwise Comparison of Criteria")
matrix = np.ones((len(criteria), len(criteria)))
for i in range(len(criteria)):
for j in range(i+1, len(criteria)):
choice = st.selectbox(
f"How much more important is '{criteria[i]}' compared to '{criteria[j]}'?",
options=list(saaty_scale.keys()),
key=f"criteria-{i}-{j}"
)
matrix[i, j] = saaty_scale[choice]
matrix[j, i] = 1 / saaty_scale[choice]
if st.button("Next: Evaluate Alternatives"):
st.session_state.matrix = matrix
st.session_state.step = 2
# Step 2: Alternative Evaluation Input
elif st.session_state.step == 2:
st.header("Step 2: Rate Alternatives under Each Criterion")
evaluations = {}
for alt in alternatives:
evaluations[alt] = {}
for crit in criteria:
choice = st.selectbox(
f"Rate {alt} on {crit}:",
options=list(linguistic_scale.keys()),
key=f"alt-{alt}-{crit}"
)
evaluations[alt][crit] = choice
if st.button("Finish and Download Selections"):
st.session_state.evaluations = evaluations
st.session_state.step = 3
# Step 3: Save selections to Excel
elif st.session_state.step == 3:
st.header("Download Your Selections")
matrix = st.session_state.matrix
evaluations = st.session_state.evaluations
user_id = st.session_state.user_id
output = io.BytesIO()
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
df_id = pd.DataFrame({"User ID": [user_id]})
df_id.to_excel(writer, sheet_name='User Info', index=False)
df_matrix = pd.DataFrame(matrix, index=criteria, columns=criteria)
df_matrix.to_excel(writer, sheet_name='Criteria Comparison')
df_eval = pd.DataFrame(evaluations).T
df_eval.to_excel(writer, sheet_name='Alternative Ratings')
output.seek(0)
st.success("Selections are ready! Please download the Excel file below and send it to the operator.")
st.download_button(
label="📥 Download Selections File",
data=output,
file_name=f"{user_id}_selections.xlsx",
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)