Coverage for C:\checkouts\github\OpenQTSim\openqtsim\customer.py: 9%

# Coverage for C:\checkouts\github\OpenQTSim\openqtsim\customer.py : 9%

## 33 statements 3 run 30 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1

2

3 class Customer:

4 """

5 Customer class for use in the OpenQTSim package

6 """

7

8 def __init__(self, Env, Sim):

9 """

10 Initialization

11 """

12

13 # self.arrival = arrival

14 self.Env = Env

15 self.Sim = Sim

16

17 Sim.customer_nr += 1

18 self.customer_nr = Sim.customer_nr

19

20 def move(self, IAT, AT):

21 """"

22 Method to move Customer through the system

23 """

24

25 # request access to server

26 self.Sim.c_s += 1

27 self.Sim.c_q += 1

28 t_req = AT

29 c_s_req = self.Sim.c_s

30 c_q_req = self.Sim.c_q

31

32 server = yield self.Env.servers.get()

33

34 self.Sim.c_q -= 1

35 t_yield = self.Env.now - self.Env.epoch

36 c_s_yield = self.Sim.c_s

37 c_q_yield = self.Sim.c_q

38

39 if t_req != t_yield: # only log when someone is actually waiting to be served

40 self.Sim.log_system_state(t_req, c_s_req, c_q_req)

41 self.Sim.log_system_state(t_yield, c_s_yield, c_q_yield)

42 else: # otherwise log the yield moment

43 self.Sim.log_system_state(t_yield, c_s_yield, c_q_yield)

44

45 # register if the server was idle

46 ITS = self.Env.now - self.Env.server_info[server.id]['last_active']

47

48 # register which server was used

49 s_id = server.id

50

51 # determine TSB

52 TSB = self.Env.now - self.Env.epoch

53

54 # get ST

55 # ST = server.service_distribution.rvs()

56 ST = self.Sim.queue.S.get_ST(server, customer_nr=self.customer_nr)

57 # server.service_distribution.rvs()

58

59 # move time ST forward

60 yield self.Env.timeout(ST)

61

62 # determine TSE

63 TSE = self.Env.now - self.Env.epoch

64

65 self.Sim.c_s -= 1

66 if self.Sim.c_q == 0:

67 self.Sim.log_system_state(TSE, self.Sim.c_s, self.Sim.c_q)

68 # Todo: when a customer leaves the system while somebody is still in the queue, you get a double logging

69 # (check how this works for more than 1 server)

70

71 # update server_info when server was last active

72 self.Env.server_info.update({server.id: {'last_active': self.Env.now}})

73

74 # release server when done

75 yield self.Env.servers.put(server)

76

77 # add customer info to log

78 self.Sim.log_customer_state(self.customer_nr, IAT, AT, ST, TSB, TSE, ITS, s_id)