diff --git a/tool.py b/tool.py index b02fe22..19d8831 100644 --- a/tool.py +++ b/tool.py @@ -10,7 +10,7 @@ import http.server import socketserver import threading -from tqdm import tqdm +from tqdm import tqdm import shutil import math @@ -114,6 +114,8 @@ def josaa_rounds_year(): steps_completed = int(total * 0.1) display_progress_bar("STEP 1/10 ", steps_completed=steps_completed, total=total, duration=0.3) + applied_filters = {"Counseling Type": "JOSAA"} + josaa_round_year = None # initialize print(Fore.YELLOW + "Select JOSAA round year") print(Fore.GREEN + "1." + Fore.BLUE + "2022") @@ -131,10 +133,10 @@ def josaa_rounds_year(): else: print(Fore.RED + "Invalid input! Please select a number between 1 and 3." + Fore.RESET) - print(josaa_round_year) - josaa_rounds(josaa_round_year) + applied_filters["Year"] = josaa_round_year + josaa_rounds(josaa_round_year, applied_filters) -def josaa_rounds(josaa_round_year): +def josaa_rounds(josaa_round_year, applied_filters): os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) @@ -176,7 +178,8 @@ def josaa_rounds(josaa_round_year): else: print(Fore.RED + f"Invalid input! Please select a number between 1 and {max_option}." + Fore.RESET) - csv_files("josaa", selected_round, josaa_round_year) + applied_filters["Round"] = selected_round + csv_files("josaa", selected_round, josaa_round_year, applied_filters) def csab_rounds_year(): os.system("cls" if os.name == "nt" else "clear") @@ -186,7 +189,8 @@ def csab_rounds_year(): total = 100 steps_completed = int(total * 0.1) display_progress_bar("STEP 1/10 ", steps_completed=steps_completed, total=total, duration=0.3) - + + applied_filters = {"Counseling Type": "CSAB"} csab_round_year = None # initialize print(Fore.YELLOW + "Select CSAB round year") @@ -209,10 +213,10 @@ def csab_rounds_year(): else: print(Fore.RED + "Invalid input! Please select a number between 1 and 4." + Fore.RESET) - print(csab_round_year) - csab_rounds(csab_round_year) + applied_filters["Year"] = csab_round_year + csab_rounds(csab_round_year, applied_filters) -def csab_rounds(csab_round_year): +def csab_rounds(csab_round_year, applied_filters): os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) # progress bar for step-2 @@ -232,11 +236,11 @@ def csab_rounds(csab_round_year): else: print(Fore.RED + "Invalid input! Please select 1 or 2." + Fore.RESET) - csv_files("csab", csab_round, csab_round_year) + applied_filters["Round"] = csab_round + csv_files("csab", csab_round, csab_round_year, applied_filters) -# define the path of csv files for different types of colleges -def csv_files(type, round, year): +def csv_files(type, round, year, applied_filters): # Get path to the temporary folder created by PyInstaller if getattr(sys, 'frozen', False): # If the script is running in a PyInstaller bundle @@ -253,7 +257,7 @@ def csv_files(type, round, year): "NITs": os.path.join(cwd, "josaa", f"{year}", f"round_{josaa_rounds}", "ranks_nits.csv"), "GFTIs": os.path.join(cwd, "josaa", f"{year}", f"round_{josaa_rounds}", "ranks_gftis.csv") } - josaa_institute_types(CSV_FILES) + josaa_institute_types(CSV_FILES, applied_filters) elif type == "csab": csab_rounds = round csv_path = os.path.join( @@ -263,10 +267,9 @@ def csv_files(type, round, year): f"round_{csab_rounds}", "ranks.csv") df = pd.read_csv(csv_path) - csab_institute_types(df) + csab_institute_types(df, applied_filters) -def csab_institute_types(df): - # clear the screen +def csab_institute_types(df, applied_filters): os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) @@ -282,6 +285,7 @@ def csab_institute_types(df): print(Fore.GREEN + "4." + Fore.BLUE + "GFTIs") # loop until valid input option = None + institute_type_name = "" while option is None: user_input = input(Fore.RESET + "Select Option (1 to 4): ").strip() @@ -293,18 +297,22 @@ def csab_institute_types(df): # filter the dataframe based on the selected option if option == "1": df = df[~df['Institute'].str.contains('Indian Institute of Technology')] + institute_type_name = "ALL (IIITs, NITs, GFTIs)" elif option == "2": df = df[df['Institute'].str.contains('Indian Institute of Information Technology')] + institute_type_name = "IIITs" elif option == "3": df = df[df['Institute'].str.contains('National Institute of Technology')] + institute_type_name = "NITs" elif option == "4": df = df[~df['Institute'].str.contains('National Institute of Technology')] df = df[~df['Institute'].str.contains('Indian Institute of Information Technology')] + institute_type_name = "GFTIs" + + applied_filters["Institute Type"] = institute_type_name + main(df, applied_filters) - main(df) - - -def josaa_institute_types(CSV_FILES): +def josaa_institute_types(CSV_FILES, applied_filters): # clear the screen os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) @@ -341,6 +349,8 @@ def josaa_institute_types(CSV_FILES): else: print(Fore.RED + "Invalid option! Please select a number between 1 and 5." + Fore.RESET) + applied_filters["Institute Type"] = college_type + # read the csv file based on the selected college type csv_path = CSV_FILES[college_type] df = pd.read_csv(csv_path) @@ -348,17 +358,17 @@ def josaa_institute_types(CSV_FILES): if option == "1": # Remove all IITs occurrence if "ALL" option was chosen df = df[~df['Institute'].str.contains('Indian Institute of Technology')] - main(df) + main(df, applied_filters) elif option == "5": # fix ranks with strings in them df['Closing Rank'] = df['Closing Rank'].str.extract(r'(\d+)').astype(float) df['Opening Rank'] = df['Opening Rank'].str.extract(r'(\d+)').astype(int) - main(df) + main(df, applied_filters) else: - main(df) + main(df, applied_filters) -def filter_programs(institute_df): +def filter_programs(institute_df, current_filters): os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) #progress bar for step-4 @@ -386,7 +396,7 @@ def filter_programs(institute_df): print("") program_choices = { - 1: '', + 1: 'All', 2: 'Computer Science and Engineering', 3: 'Artificial Intelligence and Data Science', 4: 'Electronics and Communication Engineering', @@ -404,10 +414,24 @@ def filter_programs(institute_df): program_choices_list = program_input.split() filtered_df = institute_df + + selected_program_names = [] + + if '1' in program_choices_list: + selected_program_names.append("All") + else: + # Build a list of selected program names + for choice in program_choices_list: + if choice.isdigit() and int(choice) in program_choices: + selected_program_names.append(program_choices[int(choice)]) + + # Filter the dataframe + if selected_program_names: + filtered_df = institute_df[institute_df["Academic Program Name"].str.contains( + '|'.join(selected_program_names))] + + current_filters["Program"] = ", ".join(selected_program_names) - if '1' not in program_choices_list: - filtered_df = institute_df[institute_df["Academic Program Name"].str.contains( - '|'.join([program_choices.get(int(choice), '') for choice in program_choices_list]))] if len(filtered_df) == 0: print( @@ -416,6 +440,7 @@ def filter_programs(institute_df): Fore.RESET) return filtered_df + # This part for page 2 can be simplified or adjusted as needed if '13' in program_choices_list: os.system("cls" if os.name == "nt" else "clear") programs = filtered_df["Academic Program Name"].unique() @@ -425,14 +450,14 @@ def filter_programs(institute_df): if program_choice >= 14 and program_choice < 14 + len(programs): program = programs[program_choice - 14] filtered_df = filtered_df[filtered_df["Academic Program Name"] == program] + current_filters["Program"] = program # Update with the specific choice else: print(Fore.RED + "Invalid choice. Please try again." + Fore.RESET) return filtered_df return filtered_df - -def display_df_web(df, heading, subheading): +def display_df_web(df, heading, subheading, applied_filters=None): output_dir = 'output' if not os.path.exists(output_dir): os.makedirs(output_dir) @@ -443,6 +468,15 @@ def display_df_web(df, heading, subheading): # convert the DataFrame to an HTML table html_table = df.to_html(index=False, classes='table',table_id="tableID") + + # Prepare the filters section as HTML + filters_html = "" + if applied_filters: + filters_html += "