Update search.py (#11)
Browse files- Update search.py (d4a856db407dc38a138cfc01842d967e83090be6)
search.py
CHANGED
@@ -1,5 +1,17 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def search_application(df):
|
5 |
user_input = st.text_input("Enter your Application Number (including IRL if applicable):")
|
@@ -24,8 +36,8 @@ def search_application(df):
|
|
24 |
return
|
25 |
application_number = int(user_input)
|
26 |
|
27 |
-
#
|
28 |
-
result = df[df['Application Number'] ==
|
29 |
|
30 |
if not result.empty:
|
31 |
decision = result.iloc[0]['Decision']
|
@@ -38,14 +50,25 @@ def search_application(df):
|
|
38 |
else:
|
39 |
st.warning(f"No record found for Application Number: {application_number}.")
|
40 |
|
41 |
-
# Find nearest application numbers
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
if not nearest_records.empty:
|
47 |
st.subheader("Nearest Application Numbers")
|
48 |
-
nearest_records
|
49 |
-
st.table(nearest_records[['Nearest Application', 'Application Number', 'Decision', 'Difference']].reset_index(drop=True))
|
50 |
else:
|
51 |
st.info("No nearest application numbers found.")
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
+
import bisect
|
4 |
+
|
5 |
+
def binary_search_nearest(df, target):
|
6 |
+
"""Find the nearest values using binary search."""
|
7 |
+
application_numbers = df['Application Number'].tolist()
|
8 |
+
pos = bisect.bisect_left(application_numbers, target)
|
9 |
+
|
10 |
+
# Find the nearest neighbors
|
11 |
+
before = application_numbers[pos - 1] if pos > 0 else None
|
12 |
+
after = application_numbers[pos] if pos < len(application_numbers) else None
|
13 |
+
|
14 |
+
return before, after
|
15 |
|
16 |
def search_application(df):
|
17 |
user_input = st.text_input("Enter your Application Number (including IRL if applicable):")
|
|
|
36 |
return
|
37 |
application_number = int(user_input)
|
38 |
|
39 |
+
# Search for the application number
|
40 |
+
result = df[df['Application Number'] == application_number]
|
41 |
|
42 |
if not result.empty:
|
43 |
decision = result.iloc[0]['Decision']
|
|
|
50 |
else:
|
51 |
st.warning(f"No record found for Application Number: {application_number}.")
|
52 |
|
53 |
+
# Find nearest application numbers using binary search
|
54 |
+
before, after = binary_search_nearest(df, application_number)
|
55 |
+
|
56 |
+
# Display nearest records
|
57 |
+
nearest_records = pd.DataFrame({
|
58 |
+
"Nearest Application": ["Before", "After"],
|
59 |
+
"Application Number": [before, after],
|
60 |
+
"Decision": [
|
61 |
+
df[df['Application Number'] == before]['Decision'].values[0] if before else None,
|
62 |
+
df[df['Application Number'] == after]['Decision'].values[0] if after else None
|
63 |
+
],
|
64 |
+
"Difference": [
|
65 |
+
application_number - before if before else None,
|
66 |
+
after - application_number if after else None
|
67 |
+
]
|
68 |
+
}).dropna()
|
69 |
|
70 |
if not nearest_records.empty:
|
71 |
st.subheader("Nearest Application Numbers")
|
72 |
+
st.table(nearest_records.reset_index(drop=True))
|
|
|
73 |
else:
|
74 |
st.info("No nearest application numbers found.")
|