Iam_Sandeep

Untitled

Dec 3rd, 2021
1,026
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import bisect
  2. def display(arr):
  3.     print("="*40)
  4.     x,y,z="Event","Task","No of days"
  5.     print(x,"\t",y,"\t",z)
  6.     print("="*40)
  7.     for e,t,n in arr:
  8.         print(e,"\t\t",t,"\t\t",n)
  9.     for i in range(3):
  10.         print()
  11.        
  12. def compute_all_events(arr):
  13.     if not arr:
  14.         print("Total Time Taken will be 0")
  15.         return
  16.     l=arr[-1][0]
  17.     sum=0
  18.     for i in range(1,l+1):
  19.         sum+=compute_finish_event(arr,i)
  20.     print("Total time taken will be",sum)
  21.  
  22. def show_longest_event(arr):
  23.     if not arr:
  24.         print("No events going on")
  25.     n=arr[-1][0]
  26.     fts=[None]*n
  27.     for i in range(n):
  28.         fts[i]=compute_finish_event(arr,i+1)
  29.     i=0
  30.     for j in range(n):
  31.         if fts[j]>fts[i]:
  32.             i=j
  33.     print(fts)
  34.     print("Longest Event",i+1)
  35.        
  36.  
  37. def compute_finish_event(arr,e):
  38.     if not arr:
  39.         return -1
  40.     elif arr[-1][0]<e:
  41.         return -1
  42.     res=0
  43.     for x,y,z in arr:
  44.         if x==e:
  45.             res=max(res,z)
  46.     return res
  47.  
  48. def verify(arr,x,y,z):
  49.     if y<10 or y>30 or z>9 or z<0 or x<1 or x>5:
  50.         return False
  51.        
  52.     for e,t,n in arr:
  53.         if e==x and t==y:
  54.             return False
  55.     return True
  56.  
  57. def add(arr,e,t,n):
  58.     bisect.insort_right(arr,(e,t,n))
  59. def insert_task(arr):
  60.     while True:
  61.         print("Enter the new task information (event number, task number, number of days)")
  62.         temp=input().split()
  63.         if len(temp)<=2:
  64.             print("Invalid insertion")
  65.             continue
  66.         else:
  67.             e,t,n=map(int,temp)
  68.             if verify(arr,e,t,n)==False:
  69.                 print("Invalid INsertion")
  70.                 continue
  71.             else:
  72.                 add(arr,e,t,n)
  73.                 print("New Event added Successfully")
  74.                 return
  75.        
  76. def plot(arr):
  77.     n=len(arr)
  78.     if not arr:
  79.         print("No tasks Found")
  80.         return
  81.     print("-"*40)
  82.     last=arr[-1][0]
  83.     for i in range(1,last+1):
  84.         m=compute_finish_event(arr,i)
  85.         print("Event",i,"*"*m,m)
  86.     print("-"*40)
  87.  
  88. def generateData(arr):
  89.     events=[1, 1, 1, 1, 2, 2, 3, 4, 5, 5, 5]
  90.     tasks=[25, 22, 24, 16, 15, 22, 17, 14, 14, 11, 20]
  91.     days=[1, 7, 6, 2, 3, 6, 5, 2, 4, 6, 7]
  92.     for i in range(10):
  93.         arr.append((events[i],tasks[i],days[i]))
  94. def main():
  95.     cons=[]
  96.     generateData(cons)
  97.     while True:
  98.         print("Critical Path Analysis")
  99.         print("="*40)
  100.         print("1- Display all Tasks")
  101.         print("2- Find the event with longest duration")
  102.         print("3- Compute the time to finish a given event")
  103.         print("4- Compute project completion time")
  104.         print("5- Plot events time chart")
  105.         print("6- Add new task")
  106.         print("7- Exit program")
  107.         c=input()
  108.         if not c.isdigit():
  109.             print("Invalid Choice")
  110.             continue
  111.         c=int(c)
  112.         if c>7 or c<=0:
  113.             continue
  114.         if c==1:
  115.             display(cons)
  116.         elif c==2:
  117.             show_longest_event(cons)
  118.         elif c==3:
  119.             while True:
  120.                 t=int(input(("Enter the event number")))
  121.                 res=compute_finish_event(cons,t)
  122.                 if res==-1:
  123.                     print("Invalid Option")
  124.                     continue
  125.                 else:
  126.                     print("Project",t,"Completed in",res,"days")
  127.                     break
  128.         elif c==4:
  129.             compute_all_events(cons)
  130.         elif c==5:
  131.             plot(cons)
  132.         elif c==6:
  133.             insert_task(cons)
  134.         else:
  135.             yn=input("Are you sure you want to exit the application y/n")
  136.             if yn=='y':
  137.                 print("GoodBye!")
  138.                 break
  139.            
  140.    
  141. main()
  142.            
RAW Paste Data