1+ from dataclasses import dataclass , field
12import string
23import random
34from typing import List , Callable
45
56
6- def generate_id (length = 8 ) :
7+ def generate_id (length : int = 8 ) -> str :
78 # helper function for generating an id
89 return '' .join (random .choices (string .ascii_uppercase , k = length ))
910
1011
12+ @dataclass
1113class SupportTicket :
14+ id : str = field (init = False , default_factory = generate_id )
15+ customer : str
16+ issue : str
1217
13- def __init__ (self , customer , issue ):
14- self .id = generate_id ()
15- self .customer = customer
16- self .issue = issue
1718
19+ SupportTickets = List [SupportTicket ]
1820
19- def fifoOrdering (list : List [SupportTicket ]) -> List [SupportTicket ]:
21+ Ordering = Callable [[SupportTickets ], SupportTickets ]
22+
23+
24+ def fifo_ordering (list : SupportTickets ) -> SupportTickets :
2025 return list .copy ()
2126
2227
23- def filoOrdering (list : List [ SupportTicket ] ) -> List [ SupportTicket ] :
28+ def filo_ordering (list : SupportTickets ) -> SupportTickets :
2429 list_copy = list .copy ()
2530 list_copy .reverse ()
2631 return list_copy
2732
2833
29- def randomOrdering (list : List [ SupportTicket ] ) -> List [ SupportTicket ] :
34+ def random_ordering (list : SupportTickets ) -> SupportTickets :
3035 list_copy = list .copy ()
3136 random .shuffle (list_copy )
3237 return list_copy
3338
3439
35- def blackHoleOrdering ( list : List [ SupportTicket ] ) -> List [ SupportTicket ] :
40+ def black_hole_ordering ( _ : SupportTickets ) -> SupportTickets :
3641 return []
3742
3843
3944class CustomerSupport :
4045
4146 def __init__ (self ):
42- self .tickets = []
47+ self .tickets : SupportTickets = []
4348
4449 def create_ticket (self , customer , issue ):
4550 self .tickets .append (SupportTicket (customer , issue ))
4651
47- def process_tickets (self , ordering : Callable [[ List [ SupportTicket ]], List [ SupportTicket ]] ):
52+ def process_tickets (self , ordering : Ordering ):
4853 # create the ordered list
4954 ticket_list = ordering (self .tickets )
5055
@@ -65,13 +70,20 @@ def process_ticket(self, ticket: SupportTicket):
6570 print ("==================================" )
6671
6772
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 )
7086
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." )
7587
76- # process the tickets
77- app . process_tickets ( blackHoleOrdering )
88+ if __name__ == '__main__' :
89+ main ( )
0 commit comments