Skip to content

[mypy] Add/fix type annotations for scheduling algorithms #4074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions scheduling/first_come_first_served.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# In this Algorithm we just care about the order that the processes arrived
# without carring about their duration time
# https://en.wikipedia.org/wiki/Scheduling_(computing)#First_come,_first_served
from __future__ import annotations
from typing import List


def calculate_waiting_times(duration_times: list[int]) -> list[int]:
def calculate_waiting_times(duration_times: List[int]) -> List[int]:
"""
This function calculates the waiting time of some processes that have a
specified duration time.
Expand All @@ -24,8 +24,8 @@ def calculate_waiting_times(duration_times: list[int]) -> list[int]:


def calculate_turnaround_times(
duration_times: list[int], waiting_times: list[int]
) -> list[int]:
duration_times: List[int], waiting_times: List[int]
) -> List[int]:
"""
This function calculates the turnaround time of some processes.
Return: The time difference between the completion time and the
Expand All @@ -44,7 +44,7 @@ def calculate_turnaround_times(
]


def calculate_average_turnaround_time(turnaround_times: list[int]) -> float:
def calculate_average_turnaround_time(turnaround_times: List[int]) -> float:
"""
This function calculates the average of the turnaround times
Return: The average of the turnaround times.
Expand All @@ -58,7 +58,7 @@ def calculate_average_turnaround_time(turnaround_times: list[int]) -> float:
return sum(turnaround_times) / len(turnaround_times)


def calculate_average_waiting_time(waiting_times: list[int]) -> float:
def calculate_average_waiting_time(waiting_times: List[int]) -> float:
"""
This function calculates the average of the waiting times
Return: The average of the waiting times.
Expand Down
9 changes: 4 additions & 5 deletions scheduling/round_robin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
In Round Robin each process is assigned a fixed time slot in a cyclic way.
https://en.wikipedia.org/wiki/Round-robin_scheduling
"""
from __future__ import annotations

from statistics import mean
from typing import List


def calculate_waiting_times(burst_times: list[int]) -> list[int]:
def calculate_waiting_times(burst_times: List[int]) -> List[int]:
"""
Calculate the waiting times of a list of processes that have a specified duration.

Expand Down Expand Up @@ -41,8 +40,8 @@ def calculate_waiting_times(burst_times: list[int]) -> list[int]:


def calculate_turn_around_times(
burst_times: list[int], waiting_times: list[int]
) -> list[int]:
burst_times: List[int], waiting_times: List[int]
) -> List[int]:
"""
>>> calculate_turn_around_times([1, 2, 3, 4], [0, 1, 3])
[1, 3, 6]
Expand Down
16 changes: 8 additions & 8 deletions scheduling/shortest_job_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
Please note arrival time and burst
Please use spaces to separate times entered.
"""
from __future__ import annotations
from typing import List

import pandas as pd


def calculate_waitingtime(
arrival_time: list[int], burst_time: list[int], no_of_processes: int
) -> list[int]:
arrival_time: List[int], burst_time: List[int], no_of_processes: int
) -> List[int]:
"""
Calculate the waiting time of each processes
Return: list of waiting times.
Return: List of waiting times.
>>> calculate_waitingtime([1,2,3,4],[3,3,5,1],4)
[0, 3, 5, 0]
>>> calculate_waitingtime([1,2,3],[2,5,1],3)
Expand Down Expand Up @@ -72,8 +72,8 @@ def calculate_waitingtime(


def calculate_turnaroundtime(
burst_time: list[int], no_of_processes: int, waiting_time: list[int]
) -> list[int]:
burst_time: List[int], no_of_processes: int, waiting_time: List[int]
) -> List[int]:
"""
Calculate the turn around time of each Processes
Return: list of turn around times.
Expand All @@ -91,8 +91,8 @@ def calculate_turnaroundtime(


def calculate_average_times(
waiting_time: list[int], turn_around_time: list[int], no_of_processes: int
):
waiting_time: List[int], turn_around_time: List[int], no_of_processes: int
) -> None:
"""
This function calculates the average of the waiting & turnaround times
Prints: Average Waiting time & Average Turn Around Time
Expand Down