File size: 4,783 Bytes
dd46682 d660857 dd46682 d660857 dd46682 d660857 dd46682 |
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 pandas as pd
import bisect
from loading_file import precomputed_df
# ------------------------------------------------------------------------------------
# Step 1: Binary Search Utility for Finding Nearest Application Numbers
# ------------------------------------------------------------------------------------
def binary_search_nearest(df, target):
"""
Uses binary search to find the nearest application numbers in the DataFrame.
Args:
df: The DataFrame containing the application numbers.
target: The target application number to search for.
Returns:
Two nearest application numbers (before and after the target).
"""
application_numbers = df["Application Number"].tolist()
pos = bisect.bisect_left(application_numbers, target)
before = application_numbers[pos - 1] if pos > 0 else None
after = application_numbers[pos] if pos < len(application_numbers) else None
return before, after
# ------------------------------------------------------------------------------------
# Step 2: Search Application Status
# ------------------------------------------------------------------------------------
def search_application(df):
"""
Handles the user input and searches for the application number in the DataFrame.
Args:
df: The DataFrame containing application numbers and decisions.
"""
user_input = st.text_input("Enter your Application Number (including IRL if applicable):")
if user_input:
# Validate user input
if "irl" in user_input.lower():
try:
application_number = int("".join(filter(str.isdigit, user_input.lower().split("irl")[-1])))
if len(str(application_number)) < 8:
st.warning("Please enter a valid application number with at least 8 digits after IRL.")
return
except ValueError:
st.error("Invalid input after IRL. Please enter only digits.")
return
else:
if not user_input.isdigit() or len(user_input) < 8:
st.warning("Please enter at least 8 digits for your VISA application number.")
return
elif len(user_input) > 8:
st.warning("The application number cannot exceed 8 digits. Please correct your input.")
return
application_number = int(user_input)
# Convert DataFrame values to integers
df["Application Number"] = df["Application Number"].astype(int)
# Search for the application number in the DataFrame
result = df[df["Application Number"] == application_number]
if not result.empty:
decision = result.iloc[0]["Decision"]
if decision.lower() == "refused":
st.error(f"Application Number: {application_number}\n\nDecision: **Refused**")
elif decision.lower() == "approved":
st.success(f"Application Number: {application_number}\n\nDecision: **Approved**")
else:
st.info(f"Application Number: {application_number}\n\nDecision: **{decision}**")
else:
st.warning(f"No record found for Application Number: {application_number}.")
# Find nearest application numbers using binary search
before, after = binary_search_nearest(df, application_number)
nearest_records = pd.DataFrame({
"Nearest Application": ["Before", "After"],
"Application Number": [before, after],
"Decision": [
df[df["Application Number"] == before]["Decision"].values[0] if before else None,
df[df["Application Number"] == after]["Decision"].values[0] if after else None
],
"Difference": [
application_number - before if before else None,
after - application_number if after else None
]
}).dropna()
if not nearest_records.empty:
st.subheader("Nearest Application Numbers")
st.table(nearest_records.reset_index(drop=True))
else:
st.info("No nearest application numbers found.")
# ------------------------------------------------------------------------------------
# Step 3: Main Streamlit Application Logic
# ------------------------------------------------------------------------------------
def main():
st.title("Visa Application Status Checker")
if precomputed_df is not None:
search_application(precomputed_df)
else:
st.error("Failed to fetch and process the visa decisions data.")
if __name__ == "__main__":
main()
|