Advertisement
Rostrup

FIFO

Sep 28th, 2022
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. from openpyxl import load_workbook
  2. wb = load_workbook(filename="cpu-scheduling.xlsx")
  3. sheet = wb.active
  4.  
  5. wt = [] #waiting time list
  6. collected = [[], [], [], []]
  7.  
  8. def fifo():
  9.     for active in sheet.iter_rows():
  10.         if isinstance(active[0].value, str):
  11.             continue
  12.         collected[0].append(active[0].value)
  13.         collected[1].append(active[1].value)
  14.         collected[2].append(active[2].value)
  15.         collected[3].append(active[3].value)
  16.         # These lines get the data from the excel and places them in their own list
  17.  
  18.         # Find waiting time
  19.         def WaitingTime(bursttime, arrival_index):
  20.             waiting_time = bursttime + arrival_index
  21.             return waiting_time
  22.  
  23.         # Find Turnaroundtime
  24.         def tat(bursttime):
  25.             tat = bursttime + WaitingTime()
  26.             return tat
  27.  
  28.     time_unit = 0
  29.  
  30.     for pid, bt in zip(collected[0], collected[2]):
  31.         for btl in range(bt, 0, -1):
  32.             if btl > 1:
  33.                 print(f"Time unit: {time_unit}, PID {pid} executing, remaining burst time: {btl}")
  34.             else:
  35.                 print(f"Time unit: {time_unit}, context switch")
  36.             time_unit += 1
  37.  
  38.     for verdi in sheet.iter_rows():
  39.         for row in sheet.iter_rows():
  40.             temp = []
  41.             for x in range(len(verdi)):
  42.                 temp.append(verdi[1].value)
  43.             collected.append(temp)
  44.  
  45. if __name__ == "__main__":
  46.     fifo()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement