forked from makena-kungu/queue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueGenerator.py
97 lines (82 loc) · 2.99 KB
/
QueueGenerator.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
92
93
94
95
96
97
from dataclasses import dataclass
from typing import List
import LinearCon
import CombinedLinearCon
import xlsxwriter
@dataclass
class CustomerData:
inter_arrival_time: int
service_time: int
@dataclass
class ProcessedCustomerData:
customer: int
inter_arrival_time: int
arrival_time: int
service_time: int
time_service_begins: int
waiting_time:int
time_service_ends: int
time_customer_spent: int
idle_time: int
def generateCustomerData():
lcm = LinearCon.LinearCon()
clcm = CombinedLinearCon.CLCM()
data:List[CustomerData] = []
for i in range(10):
data.append(CustomerData(int(lcm.next()*10), int(clcm.next()*7)))
return data
def process_data():
data:List[ProcessedCustomerData] = []
customers = generateCustomerData()
i= 1
previous_time_service_end= 0
arrival_time=0
for item in customers:
inter_arrival_time= item.inter_arrival_time
inter_arrival_time = 0 if i==1 else inter_arrival_time
arrival_time += inter_arrival_time
time_service_begins= arrival_time if previous_time_service_end< arrival_time else previous_time_service_end
waiting_time= time_service_begins-arrival_time
service_time = item.service_time
time_service_ends=service_time + time_service_begins
time_customer_spent= time_service_ends-arrival_time
difference=arrival_time - previous_time_service_end
idle_time= 0 if difference < 0 else difference
previous_time_service_end = time_service_ends
data.append(ProcessedCustomerData(i,
inter_arrival_time,
arrival_time,
service_time,
time_service_begins,
waiting_time,
time_service_ends,
time_customer_spent,
idle_time))
print('iteration {0}'.format(i))
i+=1
return data
data = process_data()
book = xlsxwriter.Workbook("Queue.xlsx")
sheet = book.add_worksheet()
sheet.write(0,0,"Customer")
sheet.write(0,1,"Inter Arrival Time")
sheet.write(0,2,"Arrival Time")
sheet.write(0,3,"Service Time")
sheet.write(0,4, "Time Service Begins")
sheet.write(0,5, "Waiting Time")
sheet.write(0,6, "Time Service Ends")
sheet.write(0,7, "Time Customer Spent")
sheet.write(0,8, "Idle Time")
i = 1
for item in data:
sheet.write(i, 0, item.customer)
sheet.write(i, 1, item.inter_arrival_time)
sheet.write(i, 2, item.arrival_time)
sheet.write(i, 3, item.service_time)
sheet.write(i, 4, item.time_service_begins)
sheet.write(i, 5, item.waiting_time)
sheet.write(i, 6, item.time_service_ends)
sheet.write(i, 7, item.time_customer_spent)
sheet.write(i, 8, item.idle_time)
i += 1
book.close()