-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (55 loc) · 1.78 KB
/
main.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
import logging
from Roles import Tailor, HajiFirooz
from Threads import *
def read_data():
sons_number = 4 # input("inter number of hajiFirooz sons: ")
file = open("./data.txt", "r")
number_of_orders = int(file.readline())
khayats = sons_number + 1 # 1 is Hajifirooz
order_peer_khayat = number_of_orders // khayats
customers_list = [d.split("\n") for d in file]
# remove empty columns
for f in customers_list:
try:
f.remove('')
except:
print("")
#########
# print(customers_list)
monshi_tagsim_kon(customers_list, order_peer_khayat)
logging.info("Secretary completes his task.")
end_threads()
def monshi_tagsim_kon(customers_list: list, order_peer_khayat: int):
customers = spit_customres_for_each_khayat(
customers_list, order_peer_khayat)
Haji = False
son_index = 1
global threads
for each_khayat_list in customers:
if not Haji:
khayat = HajiFirooz(each_khayat_list)
Haji = True
else:
son_name = "Tailor"+str(son_index)
khayat = Tailor(son_name, each_khayat_list)
son_index = son_index + 1
start_thread(khayat)
def spit_customres_for_each_khayat(customers_list2D, order_peer_khayat):
count = 0
t = []
customers = []
for j in customers_list2D:
for i in j:
if not count < order_peer_khayat:
customers.append(t)
t = []
count = 0
t.append(i)
count = count + 1
customers.append(t)
return customers
if __name__ == "__main__":
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO,
datefmt="%H:%M:%S")
read_data()