soufir commited on
Commit
552e109
Β·
verified Β·
1 Parent(s): 9544344

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +35 -2
src/streamlit_app.py CHANGED
@@ -145,6 +145,37 @@ if method == "AHP":
145
 
146
  elif method == "None":
147
  st.subheader("Pilih Metode terlebih dahulu")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  else:
149
  # TOPSIS dan Profile Matching
150
  st.subheader("πŸ“‹ Input Nilai Alternatif terhadap Kriteria")
@@ -231,8 +262,10 @@ if run_calc:
231
  weighted_data = norm_data * w
232
 
233
  # Tentukan ideal positif dan negatif (max/min)
234
- ideal_pos = np.max(weighted_data, axis=0)
235
- ideal_neg = np.min(weighted_data, axis=0)
 
 
236
 
237
  # Jarak ke ideal positif dan negatif
238
  dist_pos = np.sqrt(((weighted_data - ideal_pos) ** 2).sum(axis=1))
 
145
 
146
  elif method == "None":
147
  st.subheader("Pilih Metode terlebih dahulu")
148
+ elif method =="TOPSIS":
149
+ # TOPSIS
150
+ st.subheader("πŸ“‹ Input Nilai Alternatif terhadap Kriteria")
151
+ empty_data = pd.DataFrame(np.nan, index=alternatives, columns=criteria)
152
+ df = st.data_editor(empty_data, use_container_width=True, key="input_matrix")
153
+ if df.isnull().values.any():
154
+ st.warning("⚠ Harap lengkapi semua nilai pada tabel sebelum menjalankan perhitungan untuk TOPSIS/Profile Matching.")
155
+
156
+ st.subheader("βš– Bobot Kriteria (Manual)")
157
+ weight_dict = {}
158
+ cols = st.columns(len(criteria))
159
+ for i, c in enumerate(criteria):
160
+ with cols[i]:
161
+ weight_dict[c] = st.number_input(f"Bobot untuk '{c}'", min_value=1.0, max_value=10.0, value=5.0, step=0.1, key=f"weight_{c}")
162
+
163
+ weights = np.array([weight_dict[c] for c in criteria])
164
+ weights /= weights.sum()
165
+ st.write("🎯 Bobot Kriteria (Ternormalisasi):")
166
+ st.dataframe(pd.Series(weights, index=criteria, name="Bobot"))
167
+
168
+ criteria_default_type= {
169
+ "Building Area" : "benefit",
170
+ "Road Access": "benefit",
171
+ "Distance" : "benefit",
172
+ "Rental Price" : "cost"
173
+ }
174
+ if criteria_default_type == "benefit":
175
+ types = 1
176
+ else:
177
+ types = 0
178
+
179
  else:
180
  # TOPSIS dan Profile Matching
181
  st.subheader("πŸ“‹ Input Nilai Alternatif terhadap Kriteria")
 
262
  weighted_data = norm_data * w
263
 
264
  # Tentukan ideal positif dan negatif (max/min)
265
+ # ideal_pos = np.max(weighted_data, axis=0)
266
+ # ideal_neg = np.min(weighted_data, axis=0)
267
+ ideal_pos = np.where(types == 1, weighted.max(), weighted.min())
268
+ ideal_neg = np.where(types == 1, weighted.min(), weighted.max())
269
 
270
  # Jarak ke ideal positif dan negatif
271
  dist_pos = np.sqrt(((weighted_data - ideal_pos) ** 2).sum(axis=1))