Home > other >  Excuse me this when the customer wait for more than a certain time of the function code, how to chan
Excuse me this when the customer wait for more than a certain time of the function code, how to chan

Time:11-28

This my present is randomly generated some time the arrival of customers first, but then when the waiting time is too long, the function of the left thought for a long time didn't write, didn't also a bit idea, excuse me the following code what to change, or what some topic ideas to change
 import datetime 
Import the random
CustomerPR=0.5
The class timeshow:
Def __init__ (self, time) :
Self. Time=time

Def alltime (self) :
Pass
Def closetime (self) :
Pass
# later=datetime. Datetime. Now () + datetime. Timedelta (minutes=self. Time) # open
# print (" closed the business end, store!" Y + later. Strftime (" % % m - H: % d % % m "))

Class a customer: customer #
Def __init__ (self, time, nowtime) :
Self. Time=time
Self. Nowtime=# nowtime business start time
The self. The column customer_num=0 #
the total number of customersSelf. Dicttime={} # dictionary to store the customer arrival time
The self. The temp=0
Def addcustomer (self) :
For I in range (self. Time) :
Self. Nowtime=datetime. Timedelta (minutes=1) + self. # nowtime customer arrival time
If customerPR & gt; Random. The random () : # random number is less than 0.5, add a customer
The self. The temp +=1
Self. Dicttime. Update ({self. Temp: self. Nowtime}) # customer arrival time to join the list
The self. The column customer_num +=1 # number + 1
Return the self. Dicttime
Def showcustomer (self) :
Print (" a total of {} customer ". The format (self. Column customer_num))
Return the self. The column customer_num


The class running: # waiter processing business
Def __init__ (self, num_peopel all_time, dic) :
The self. The solved=0 # number of completed
Self. All_time=# all_time operating time
The self. The temp=1 # record customer order processing
Self. Dic=dic # deposit customer arrival time
Self. Begin_time=self. Dic [self. Temp] # start processing time
End of the self. The end_time=0 # processing time
The self. The rd=0 # randomly generated clerk processing time
Self. Leave=0 # leave customers
The self. The finish=0 # complete customer
Self. TempMan=[] # temporary
Self. Deltemp=[]
Self. K=0
# for x in dic. Values () :
# print (x.s trftime (" % % Y - m - H: % d % % m "))
Def solved_num (self) :
For I in range (self. All_time) :
Try:
Self. Begin_time=self. Dic [self. Temp] # start time is the first element
Self. Rd=random. Randint (1, 5)
Self. End_time=self. Begin_time + datetime. Timedelta (minutes=self. Rd)
For the f in the self. Dic:
Try:
If self. Begin_time & lt; + 1=self. Dic [f] or the self. The dic [f + 1] <=self. End_time: # at the time of processing come
Self. K=list (self. Dic. Keys ()) [list (self) dic) values ()). The index (self. Dic) [f + 1]]
Self. TempMan. Append (self. K)
Except:
Break # beyond index stop
For j in self tempMan: # circulation processing time arrival customers
Try:
# wait for 2 minutes haven't processed
If self. Dic [j] + datetime. Timedelta (minutes=2) & lt; Self. End_time and self. Dic [j] in the self. Dic. The values () :
Self. K=list (self. Dic. Keys ()) [list (self) dic) values ()). The index (self. Dic) [j]]
Self. Deltemp. Append (self. K) haven't handle # 2 minutes to play to join
Del self. TempMan [self. K] # delete join
Self. Leave +=1
Except:
The continue
For x in the self. Deltemp: # circulation within two minutes haven't handle play
Try:
If the x in the self. Dic. Values () : # if two minutes later still in dic
Self. K=list (self. Dic. Keys ()) [list (self) dic) values ()). The index (x)] # to find out the corresponding key
Del self. Dic [self. K] # delete key in dic
Except:
The continue
Del self. Dic [self. Temp] # cycle a successful delete the complete customer
The self. The temp +=1 # customers processing order + 1
The self. The finish +=1 # complete the number of + 1
Except:
The self. The temp +=1 # if the deleted the customer processing order + 1 continue to cycle

Def the main () :
Print (" is the current time is: "+ datetime. Datetime. Now (). The strftime (" % % Y - m - H: % d % % m"))
Business_time=int (input (" please enter the operating time (minutes) "))
Begin_time=datetime. Datetime. Now ()
C=customer (business_time, datetime. Datetime. Now ())
C.a. ddcustomer (#) increase customer
C.s. howcustomer (#) according to the customer
R=running (Arthur c. ustomer_num, business_time c.d icttime)
R.s olved_num ()
Print (" leave number: {} ". The format (r.l eave))
Print (" the number of completed: {} ". The format (r.f inish))
# for x in r.t empMan:
# print (x.s trftime (" % % Y - m - H: % d % % m "))
# for the I in c.d icttime. Values () :
# print (i. trftime (" % % Y - m - H: % d % % m "))
If __name__=="__main__ ':
The main ()
# arrival time waiting time counting time
  • Related