"""simple docstring"""


from statistics import mean

import numpy as np






def      __UpperCAmelCase       (      lowercase ,lowercase ,lowercase ,lowercase		):







  """simple docstring"""
  _UpperCAmelCase    			=   0
  # Number of processes finished
  _UpperCAmelCase    			=   0
  # Displays the finished process.
  # If it is 0, the performance is completed if it is 1, before the performance.
  _UpperCAmelCase    			=   [0] * no_of_process
  # List to include calculation results
  _UpperCAmelCase    			=   [0] * no_of_process

  # Sort by arrival time.
  _UpperCAmelCase    			=   [burst_time[i] for i in np.argsort(lowercase		)]
  _UpperCAmelCase    			=   [process_name[i] for i in np.argsort(lowercase		)]
  arrival_time.sort()

  while no_of_process > finished_process_count:
    _UpperCAmelCase    			=   0
    while finished_process[i] == 1:
      i += 1
    if current_time < arrival_time[i]:
      _UpperCAmelCase    			=   arrival_time[i]

    _UpperCAmelCase    			=   0
    # Index showing the location of the process being performed
    _UpperCAmelCase    			=   0
    # Saves the current response ratio.
    _UpperCAmelCase    			=   0
    for i in range(0 ,lowercase		):
      if finished_process[i] == 0 and arrival_time[i] <= current_time:
        _UpperCAmelCase    			=   (burst_time[i] + (current_time - arrival_time[i])) / burst_time[
            i
        ]
      if response_ratio < temp:
        _UpperCAmelCase    			=   temp
        _UpperCAmelCase    			=   i

        # Calculate the turn around time
    _UpperCAmelCase    			=   current_time + burst_time[loc] - arrival_time[loc]
    current_time += burst_time[loc]
    # Indicates that the process has been performed.
    _UpperCAmelCase    			=   1
    # Increase finished_process_count by 1
    finished_process_count += 1

  return turn_around_time






def      __UpperCAmelCase       (      lowercase ,lowercase ,lowercase ,lowercase		):







  """simple docstring"""
  _UpperCAmelCase    			=   [0] * no_of_process
  for i in range(0 ,lowercase		):
    _UpperCAmelCase    			=   turn_around_time[i] - burst_time[i]
  return waiting_time


if __name__ == "__main__":
    UpperCAmelCase__			=    5
    UpperCAmelCase__			=    ["""A""", """B""", """C""", """D""", """E"""]
    UpperCAmelCase__			=    [1, 2, 3, 4, 5]
    UpperCAmelCase__			=    [1, 2, 3, 4, 5]

    UpperCAmelCase__			=    calculate_turn_around_time(
        process_name, arrival_time, burst_time, no_of_process
    )
    UpperCAmelCase__			=    calculate_waiting_time(
        process_name, turn_around_time, burst_time, no_of_process
    )

    print("""Process name \tArrival time \tBurst time \tTurn around time \tWaiting time""")
    for i in range(0, no_of_process):
        print(
            F'''{process_name[i]}\t\t{arrival_time[i]}\t\t{burst_time[i]}\t\t'''
            F'''{turn_around_time[i]}\t\t\t{waiting_time[i]}'''
        )

    print(F'''average waiting time : {mean(waiting_time):.5f}''')
    print(F'''average turn around time : {mean(turn_around_time):.5f}''')

"""simple docstring"""


from __future__ import annotations

import pandas as pd






def      __UpperCAmelCase       (      lowercase ,lowercase ,lowercase		):







  """simple docstring"""
  _UpperCAmelCase    			=   [0] * no_of_processes
  _UpperCAmelCase    			=   [0] * no_of_processes
  # Copy the burst time into remaining_time[]
  for i in range(lowercase		):
    _UpperCAmelCase    			=   burst_time[i]

  _UpperCAmelCase    			=   0
  _UpperCAmelCase    			=   0
  _UpperCAmelCase    			=   9_99_99_99_99
  _UpperCAmelCase    			=   0
  _UpperCAmelCase    			=   False

  # Process until all processes are completed
  while complete != no_of_processes:
    for j in range(lowercase		):
      if arrival_time[j] <= increment_time and remaining_time[j] > 0:
        if remaining_time[j] < minm:
          _UpperCAmelCase    			=   remaining_time[j]
          _UpperCAmelCase    			=   j
          _UpperCAmelCase    			=   True

    if not check:
      increment_time += 1
      continue
    remaining_time[short] -= 1

    _UpperCAmelCase    			=   remaining_time[short]
    if minm == 0:
      _UpperCAmelCase    			=   9_99_99_99_99

    if remaining_time[short] == 0:
      complete += 1
      _UpperCAmelCase    			=   False

      # Find finish time of current process
      _UpperCAmelCase    			=   increment_time + 1

      # Calculate waiting time
      _UpperCAmelCase    			=   finish_time - arrival_time[short]
      _UpperCAmelCase    			=   finar - burst_time[short]

      if waiting_time[short] < 0:
        _UpperCAmelCase    			=   0

        # Increment time
    increment_time += 1
  return waiting_time






def      __UpperCAmelCase       (      lowercase ,lowercase ,lowercase		):







  """simple docstring"""
  _UpperCAmelCase    			=   [0] * no_of_processes
  for i in range(lowercase		):
    _UpperCAmelCase    			=   burst_time[i] + waiting_time[i]
  return turn_around_time






def      __UpperCAmelCase       (      lowercase ,lowercase ,lowercase		):







  """simple docstring"""
  _UpperCAmelCase    			=   0
  _UpperCAmelCase    			=   0
  for i in range(lowercase		):
    _UpperCAmelCase    			=   total_waiting_time + waiting_time[i]
    _UpperCAmelCase    			=   total_turn_around_time + turn_around_time[i]
  print(f'''Average waiting time = {total_waiting_time / no_of_processes:.5f}'''		)
  print("""Average turn around time =""" ,total_turn_around_time / no_of_processes		)


if __name__ == "__main__":
    print("""Enter how many process you want to analyze""")
    UpperCAmelCase__			=    int(input())
    UpperCAmelCase__			=    [0] * no_of_processes
    UpperCAmelCase__			=    [0] * no_of_processes
    UpperCAmelCase__			=    list(range(1, no_of_processes + 1))

    for i in range(no_of_processes):
        print("""Enter the arrival time and burst time for process:--""" + str(i + 1))
        UpperCAmelCase__		, UpperCAmelCase__			=    map(int, input().split())

    UpperCAmelCase__			=    calculate_waitingtime(arrival_time, burst_time, no_of_processes)

    UpperCAmelCase__			=    burst_time
    UpperCAmelCase__			=    no_of_processes
    UpperCAmelCase__			=    waiting_time
    UpperCAmelCase__			=    calculate_turnaroundtime(bt, n, wt)

    calculate_average_times(waiting_time, turn_around_time, no_of_processes)

    UpperCAmelCase__			=    pd.DataFrame(
        list(zip(processes, burst_time, arrival_time, waiting_time, turn_around_time)),
        columns=[
            """Process""",
            """BurstTime""",
            """ArrivalTime""",
            """WaitingTime""",
            """TurnAroundTime""",
        ],
    )

    # Printing the dataFrame
    pd.set_option("""display.max_rows""", fcfs.shape[0] + 1)
    print(fcfs)
