Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bisect
- """
- input:
- I will use some 10 points of data
- i will create a list if tuples where each tuple is size of 3.
- Then i use different functions defined and use them vividly.
- functions where i use inputs:
- main(): takes choics
- finish time event:take event number
- add new task:takes 3 integers from user
- output:
- menu of the activities till we exit
- on each selection a function revokes based on input.
- """
- #for the purpose of showing event table
- def displayAllTasks(arr):
- print("="*40)
- x,y,z="Event","Task","No of days"
- print(x,"\t",y,"\t",z)
- print("="*40)
- for e,t,n in arr:
- print(e,"\t\t",t,"\t\t",n)
- for i in range(3):
- print()
- #show menu
- def display():
- print("Critical Path Analysis")
- print("="*40)
- print("1- display all Tasks")
- print("2- Find the event with longest duration")
- print("3- Compute the time to finish a given event")
- print("4- Compute project completion time")
- print("5- plot Chart events time chart")
- print("6- Add new task")
- print("7- Exit program")
- print("Enter choice")
- #finds the sum of all events
- def computeProjectTime(arr):
- if not arr:
- print("Total Time Taken will be 0")
- return
- l=arr[-1][0]
- sum=0
- for i in range(1,l+1):
- sum+=computeEventTime(arr,i)
- print("Total time taken will be",sum)
- #shows the longest event
- def computeLongestEvent(arr):
- if not arr:
- print("No events going on")
- n=arr[-1][0]
- fts=[None]*n
- for i in range(n):
- fts[i]=computeEventTime(arr,i+1)
- i=0
- for j in range(n):
- if fts[j]>fts[i]:
- i=j
- print(" longest event time is",fts[i] ,"days, for the event(s) ",i+1)
- #it computes the finishing time of an event
- def computeEventTime(arr,e):
- if not arr:
- return -1
- elif arr[-1][0]<e:
- return -1
- res=0
- for x,y,z in arr:
- if x==e:
- res=max(res,z)
- return res
- #this verifies whether we have to add new task or not
- def verify(arr,x,y,z):
- if y<10 or y>30 or z>9 or z<0 or x<1 or x>5:
- return False
- for e,t,n in arr:
- if e==x and t==y:
- return False
- return True
- def add(arr,e,t,n):
- bisect.insort_right(arr,(e,t,n))
- #for inserting task
- def addNewTask(arr):
- while True:
- print("Enter the new task information (event number, task number, number of days)")
- temp=input().split()
- if len(temp)<=2:
- print("Invalid insertion")
- continue
- else:
- e,t,n=map(int,temp)
- if verify(arr,e,t,n)==False:
- print("Invalid INsertion")
- continue
- else:
- add(arr,e,t,n)
- print("New Event added Successfully")
- return
- #plotEventTimeChart graph
- def plotEventTimeChart(arr):
- n=len(arr)
- if not arr:
- print("No tasks Found")
- return
- print("-"*40)
- last=arr[-1][0]
- for i in range(1,last+1):
- m=computeEventTime(arr,i)
- print("Event",i,"*"*m,m)
- print("-"*40)
- #generates the data
- def generateData(arr):
- events=[1, 1, 1, 1, 2, 2, 3, 4, 5, 5, 5]
- tasks=[25, 22, 24, 16, 15, 22, 17, 14, 14, 11, 20]
- days=[1, 7, 6, 2, 3, 6, 5, 2, 4, 6, 7]
- for i in range(10):
- arr.append((events[i],tasks[i],days[i]))
- # main func
- def main():
- cons=[]
- generateData(cons)
- while True:
- display()
- c=input()
- if not c.isdigit():
- print("Invalid Choice")
- continue
- c=int(c)
- if c>7 or c<=0:
- print("Invalid Choice")
- continue
- if c==1:
- displayAllTasks(cons)
- elif c==2:
- computeLongestEvent(cons)
- elif c==3:
- while True:
- t=int(input(("Enter the event number")))
- res=computeEventTime(cons,t)
- if res==-1:
- print("Invalid Option")
- continue
- else:
- print("Event numbeer",t,"can be Completed in",res,"days")
- break
- elif c==4:
- computeProjectTime(cons)
- elif c==5:
- plotEventTimeChart(cons)
- elif c==6:
- addNewTask(cons)
- else:
- yn=input("Are you sure you want to exit the application y/n")
- if yn=='y':
- print("GoodBye!")
- break
- elif yn=='n':
- continue
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement