-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.py
91 lines (73 loc) · 2.98 KB
/
resources.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from random import choice as r_choice
from os import system
class Process:
estado = False
estado2 = False
type = r_choice(["CPU-Bound", "I/O-Bound"])
waiting_time = 0
ordem = 0
tempo_espera = []
tempo_interrompido = 0
def __init__(self, num, tc, te, prio=5):
self.nome = "P" + str(num)
self.arrival_time = int(tc)
self.tempo_exec = int(te)
self.prioridade=int(prio)
# asks for user input. Terminates the program, or sends user back to Main Menu
def exit_menu():
choice = input("Do you wish to return to the Main Menu?\n"
" Yes............1\n"
" No............2 ")
if choice == "1":
system("python Menu.py")
else:
system("cls")
print("See you soon, Bye!!!")
def display_algorithm_name(name):
system("cls")
spaces = (24-len(name))//2*" "
print("##########################################################################\n"
f"#########################{spaces}{name}{spaces}#########################\n"
"##########################################################################\n")
def get_waiting_time_1(current_time, arrival_time):
print("hjhvmvgvhgvhgv", current_time, arrival_time)
if arrival_time>=current_time:
return 0
return current_time-arrival_time
def get_waiting_time_3(processes):
tempos=[]
for p in processes:
tem=[]
for i in p.tempo_espera:
if p.tempo_espera.index(i)==0:
tem.append(i)
else:
if i !=0:
tem.append(i)
tempos.append(sum(tem)/len(tem))
return sum(tempos)/len(tempos)
def get_waiting_time_5(times):
tempo_de_espera = [sum(t)/len(t) for t in times if len(t) !=0]
return sum(tempo_de_espera)/len(tempo_de_espera) if tempo_de_espera != [] else 0
def display_process_end(tempo_atual, tempos_de_espera, p_type=0):
print("dfasdfasdfa", tempos_de_espera)
if p_type==0:
print("\n----------------------------------------------------------------\n"
f"O processamento terminou no instante: {tempo_atual}seg. O tempo médio de espera é:"
f" {sum(tempos_de_espera)/len(tempos_de_espera)} seg\n"
"----------------------------------------------------------------\n")
elif p_type == 1:
print("\n----------------------------------------------------------------\n"
f"O processamento terminou no instante: {tempo_atual}seg. O tempo médio de espera é:"
f" {tempos_de_espera} seg\n"
"----------------------------------------------------------------\n")
def ordenar_processos(processos_in):
proc, tempos = [], []
for processo in processos_in:
tempos.append(processo.arrival_time)
for i in sorted(tempos):
for proce in processos_in:
if proce.arrival_time == i and proce.ordem == 0:
proc.append(proce)
proce.ordem = 1
return proc