1
+ from dataclasses import dataclass , field
1
2
import string
2
3
import random
3
4
from typing import List , Callable
4
5
5
6
6
- def generate_id (length = 8 ) :
7
+ def generate_id (length : int = 8 ) -> str :
7
8
# helper function for generating an id
8
9
return '' .join (random .choices (string .ascii_uppercase , k = length ))
9
10
10
11
12
+ @dataclass
11
13
class SupportTicket :
14
+ id : str = field (init = False , default_factory = generate_id )
15
+ customer : str
16
+ issue : str
12
17
13
- def __init__ (self , customer , issue ):
14
- self .id = generate_id ()
15
- self .customer = customer
16
- self .issue = issue
17
18
19
+ SupportTickets = List [SupportTicket ]
18
20
19
- def fifoOrdering (list : List [SupportTicket ]) -> List [SupportTicket ]:
21
+ Ordering = Callable [[SupportTickets ], SupportTickets ]
22
+
23
+
24
+ def fifo_ordering (list : SupportTickets ) -> SupportTickets :
20
25
return list .copy ()
21
26
22
27
23
- def filoOrdering (list : List [ SupportTicket ] ) -> List [ SupportTicket ] :
28
+ def filo_ordering (list : SupportTickets ) -> SupportTickets :
24
29
list_copy = list .copy ()
25
30
list_copy .reverse ()
26
31
return list_copy
27
32
28
33
29
- def randomOrdering (list : List [ SupportTicket ] ) -> List [ SupportTicket ] :
34
+ def random_ordering (list : SupportTickets ) -> SupportTickets :
30
35
list_copy = list .copy ()
31
36
random .shuffle (list_copy )
32
37
return list_copy
33
38
34
39
35
- def blackHoleOrdering ( list : List [ SupportTicket ] ) -> List [ SupportTicket ] :
40
+ def black_hole_ordering ( _ : SupportTickets ) -> SupportTickets :
36
41
return []
37
42
38
43
39
44
class CustomerSupport :
40
45
41
46
def __init__ (self ):
42
- self .tickets = []
47
+ self .tickets : SupportTickets = []
43
48
44
49
def create_ticket (self , customer , issue ):
45
50
self .tickets .append (SupportTicket (customer , issue ))
46
51
47
- def process_tickets (self , ordering : Callable [[ List [ SupportTicket ]], List [ SupportTicket ]] ):
52
+ def process_tickets (self , ordering : Ordering ):
48
53
# create the ordered list
49
54
ticket_list = ordering (self .tickets )
50
55
@@ -65,13 +70,20 @@ def process_ticket(self, ticket: SupportTicket):
65
70
print ("==================================" )
66
71
67
72
68
- # create the application
69
- app = CustomerSupport ()
73
+ def main () -> None :
74
+ # create the application
75
+ app = CustomerSupport ()
76
+
77
+ # register a few tickets
78
+ app .create_ticket ("John Smith" , "My computer makes strange sounds!" )
79
+ app .create_ticket ("Linus Sebastian" ,
80
+ "I can't upload any videos, please help." )
81
+ app .create_ticket (
82
+ "Arjan Egges" , "VSCode doesn't automatically solve my bugs." )
83
+
84
+ # process the tickets
85
+ app .process_tickets (random_ordering )
70
86
71
- # register a few tickets
72
- app .create_ticket ("John Smith" , "My computer makes strange sounds!" )
73
- app .create_ticket ("Linus Sebastian" , "I can't upload any videos, please help." )
74
- app .create_ticket ("Arjan Egges" , "VSCode doesn't automatically solve my bugs." )
75
87
76
- # process the tickets
77
- app . process_tickets ( blackHoleOrdering )
88
+ if __name__ == '__main__' :
89
+ main ( )
0 commit comments