mayankjoin3

btp mtp allocation divyam

Apr 19th, 2026 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.53 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. # 1. Load the input file
  4. file_path = '/Users/divyamgoel/Desktop/ERP_MAIN/ERP/include/python_codes/old/BTP-ORDER.csv'
  5. #sample - https://www.x.com/scl/fi/0vqoeszcdfpw3623b9z9f/BTP-ORDER.csv?rlkey=afg5et38epsucg9nctoajv4uq&dl=0
  6. df = pd.read_csv(file_path)
  7. OUTPUT_FILE = str(file_path.split('.')[0])+"_allocation.csv"
  8. # Added the new output file path
  9. PREF_COUNT_FILE = str(file_path.split('.')[0])+"_pref_count.csv"
  10.  
  11. print(OUTPUT_FILE)
  12. print(PREF_COUNT_FILE)
  13.  
  14. # 2. Sort students by CGPA in decreasing order
  15. df_sorted = df.sort_values(by='CGPA', ascending=False, kind='stable').reset_index(drop=True)
  16.  
  17. # 3. Identify professor preference columns
  18. prof_cols = [col for col in df.columns if 'Supervisor Preference [' in col]
  19. num_profs = len(prof_cols)
  20.  
  21. allocation_results = []
  22. available_profs = set()
  23.  
  24. # 4. Allocation Logic (Unchanged)
  25. for i, row in df_sorted.iterrows():
  26.     if i % num_profs == 0:
  27.         available_profs = set(prof_cols)
  28.    
  29.     student_prefs = row[prof_cols].sort_values().index.tolist()
  30.    
  31.     allotted_prof_col = None
  32.     rank_of_allotment = None
  33.    
  34.     for prof_col in student_prefs:
  35.         if prof_col in available_profs:
  36.             allotted_prof_col = prof_col
  37.             rank_of_allotment = row[prof_col]
  38.             available_profs.remove(prof_col)
  39.             break
  40.            
  41.     prof_name = allotted_prof_col.replace('Supervisor Preference [', '').replace(']', '')
  42.    
  43.     allocation_results.append({
  44.         'Roll Number': row['Roll Number'],
  45.         'Full Name': row['Full Name'],
  46.         'CGPA': row['CGPA'],
  47.         'Allotted Professor': prof_name,
  48.         'Preference Rank': int(rank_of_allotment)
  49.     })
  50.  
  51. # 5. Save the final allocation output to CSV
  52. output_df = pd.DataFrame(allocation_results)
  53. output_df.to_csv(OUTPUT_FILE, index=False)
  54.  
  55. # --- NEW SECTION: Preference Count Logic ---
  56.  
  57. # Calculate how many times each rank (1, 2, 3...) appears for each professor
  58. # We transpose it so professors are rows and ranks (1, 2, 3...) are columns
  59. pref_counts = df[prof_cols].apply(pd.Series.value_counts).fillna(0).astype(int).T
  60.  
  61. # Clean the index (Professor names) to match your previous formatting
  62. pref_counts.index = [name.replace('Supervisor Preference [', '').replace(']', '') for name in pref_counts.index]
  63. pref_counts.index.name = 'Professor'
  64.  
  65. # Save the preference counts to CSV
  66. pref_counts.to_csv(PREF_COUNT_FILE)
  67.  
  68. # --- END NEW SECTION ---
  69.  
  70. print(f"Allocation complete. Results saved to {OUTPUT_FILE}")
  71. print(f"Preference counts saved to {PREF_COUNT_FILE}")
Advertisement
Add Comment
Please, Sign In to add comment