analyze.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env python3
  2. import pandas as pd
  3. import os
  4. import sys
  5. import datetime
  6. version_major=0
  7. version_minor=0
  8. version_serial=2
  9. version = '.'.join([str(version_major),str(version_minor),str(version_serial)])
  10. def help_file():
  11. print('')
  12. print('Usage: ')
  13. print('')
  14. print('Download the Master Pilot Seniority List from CWA-')
  15. print(' CWA -> Reports -> System Seniority -> Sort By Seniority Number ')
  16. print('')
  17. print('Download the monthly Award file from Crew Planning in .pdf format')
  18. print('')
  19. print('Run SeniorityCalculator.py using these two files as inputs')
  20. print('')
  21. print('Run analyse.py using the resultant .csv file from SeniorityCalculator.py')
  22. print('')
  23. print('The results show the current master seniority to hold various domicile relative seniorities as a Captian')
  24. print('')
  25. def analyse_CA_seniority(mergedfile='merged.csv', empid=88292):
  26. print('')
  27. print('Master Relative Seniority to hold Domicile Seniority')
  28. print('Version: ' + version)
  29. print('')
  30. if os.path.exists(mergedfile):
  31. #Read csv file into DataFrame
  32. df_merged = pd.read_csv(mergedfile)
  33. else:
  34. print("Cannot find file: " + mergedfile)
  35. print("Run python3 parse2.py to build appropriate files")
  36. sys.exit()
  37. # Get list of domiciles for iteration
  38. domiciles = df_merged.Dom.unique()
  39. #Get Total number of pilots on Seniority List
  40. intMaxSen = int(df_merged.TotalSen.max())
  41. SenChart = []
  42. chkpercents = []
  43. x = range(100, 1, -5)
  44. for n in x:
  45. chkpercents.append(n)
  46. for domicile in domiciles:
  47. column_names=['Domicile']
  48. #Populate Dataframe with each domicile's CA list
  49. df_domicile = df_merged.loc[ (df_merged['Dom'] == str(domicile).upper()) & (df_merged['Seat'] == str('CA').upper()) ]
  50. percent_results = []
  51. new_seniority = []
  52. new_seniority.append(domicile)
  53. for item in chkpercents:
  54. sen = int(item)/100
  55. domsen = int(round(sen * df_domicile.DomSen.max()))
  56. totalsen = float(df_domicile.loc[df_merged['DomSen'] == domsen].TotalSen.values[0]) / float(intMaxSen) * 100
  57. new_seniority.append(totalsen)
  58. column_names.append(str(item))
  59. SenChart.append(new_seniority)
  60. dfSeniority = pd.DataFrame(SenChart)
  61. dfSeniority.columns=column_names
  62. dfSeniority = dfSeniority.round(2)
  63. print(dfSeniority.to_string(index=False))
  64. print('')
  65. ## Check inputs ##
  66. if not len(sys.argv) > 1:
  67. help_file()
  68. raise Exception('Missing Arguments filename.csv and [optional] employee number')
  69. if len(sys.argv) > 1 and not sys.argv[1].lower().endswith('.csv'):
  70. raise Exception('Command needs a CSV filename to open')
  71. if not os.path.exists(sys.argv[1]):
  72. raise Exception('File name does not exist.')
  73. if len(sys.argv) > 2:
  74. empid = sys.argv[2].strip()
  75. if not empid.isdigit(): #check if string is digit
  76. if empid[0].lower() == 'e': #check if string starts with an 'e'
  77. empid = empid[1: ] #strip leading char
  78. if not empid.isdigit(): #recheck if its a digit now
  79. raise Exception('Employee numbers is not in a valid format')
  80. else:
  81. raise Exception('Employee number must be a digit or start with an e')
  82. else:
  83. empid=88291
  84. analyse_CA_seniority(sys.argv[1], empid)
  85. ##Known Errors:
  86. # OAK has OAK and OAK ETOPS listngs on vacsen causing duplicte names on merged list
  87. # CAdt has a trailing zero for some reason