List of commits:
Subject Hash Author Date (UTC)
Simulation now working correctly for ID's 101, 102 and 103. 1bc2fb65bb75b3a1f63cf7690472152fe1f32564 Jan Allersma 2017-11-28 16:22:53
Autos kunnen gespawned worden en rijden dan de goede richting op. b36ef1cafeda20d5753b72c6f8e6ac8423c42d95 Jan Allersma 2017-11-26 21:44:39
Last changes before test case 5. 258ba4735dfd2078f8e4f034fffed2bbbb086f2a Jan Allersma 2017-11-22 14:08:37
hallo dit is kapot maar het werkt woehoe 4475c2633e962688c71634d633ac8789524f16cf XCBouke 2017-11-22 13:58:54
It's actually working now! With a gameloop and new icons :D 0b65d450fea6d9f679029f2d6765c7e2d1126cdd Jan Allersma 2017-11-20 22:02:23
Something... Works?? 9a6afe028642b571483fccd6d6bdab10dee68e9c Jan Allersma 2017-11-20 15:14:07
User input for sending msg. cdd1c17cfe8cc73985945aad5878e4891e92eab1 Jan Allersma 2017-11-14 23:05:53
prutsen veel prusten f37cf730ff7a0ad2e08cd769da5f488051ac6dd4 XCBouke 2017-11-09 21:32:15
uglyJsonCode created online with Bitbucket ed6c9c541947ec64827b6e80ed959feb1b0f9b85 XCBouke 2017-11-09 14:29:36
Connectie created online with Bitbucket (send en recieve in 1) b484aff52014ff8d1dbaf8387cf1479cf236f33a XCBouke 2017-11-09 14:28:29
Ready for test case 3. Also BIG cleanup. bda906e19e3b82fb91df53eb2208e8def822c6b5 Jan Allersma 2017-11-05 21:38:16
test case 2 fix(?) dd86d637d166707a31b644dad711c7a9e39dbc8d Jan Allersma 2017-11-04 10:55:03
Test case 2 9ea6eadbd85dde0e9522068718092b1f0e9b49f0 Jan Allersma 2017-10-29 22:37:57
Added threading. 4540fe1669c9e145e613edf2459031e7bec500ea Jan Allersma 2017-10-29 20:47:49
Code for testing 16/10/17. Use simulatie/rabbit/combination.py mainly. c5e87d7fe5abbcd3316b1538a0d647fd23faa59f Jan Allersma 2017-10-15 19:13:23
Added more paths. Some of them are WIP. 03ad1039e22bd1ebd301bda99e78f38239a15077 Jan Allersma 2017-09-21 14:40:44
Added paths... 5561d21918f048a40ca9686112638a48805917e3 Jan Allersma 2017-09-21 13:06:43
Added first paths of crossroad. Also added reference of crossroad. 43a5ddf291e38b47bad02a92af58839d86f9d449 Jan Allersma 2017-09-21 12:21:53
Added first paths of crossroad. Also added reference of crossroad. bb687a8152231d0c89fed827baefcfbf067be90c Jan Allersma 2017-09-21 12:21:11
Fixed typo. db82c84f8d834e62cb37333ff973ddc54af5372f Jan Allersma 2017-09-20 20:51:15
Commit 1bc2fb65bb75b3a1f63cf7690472152fe1f32564 - Simulation now working correctly for ID's 101, 102 and 103.
Author: Jan Allersma
Author date (UTC): 2017-11-28 16:22
Committer name: Jan Allersma
Committer date (UTC): 2017-11-28 16:22
Parent(s): b36ef1cafeda20d5753b72c6f8e6ac8423c42d95
Signing key:
Tree: ffd1b2637b914164e7365bda0cf3a347b45b17aa
File Lines added Lines deleted
simulatie/connection.py 5 5
simulatie/model.py 1 1
simulatie/pyg.py 57 13
simulatie/test/connection.py 11 10
simulatie/test/model.py 1 1
simulatie/test/traffic.py 118 5
simulatie/traffic.py 1 1
simulatie/trafficModel.py 150 35
File simulatie/connection.py changed (mode: 100644) (index e40c7ca..eda78d6)
... ... import threading
3 3
4 4 import model import model
5 5 import pyg import pyg
6 '''
6
7 7 creds = pika.PlainCredentials(model.uname, model.passwd) creds = pika.PlainCredentials(model.uname, model.passwd)
8 8 SendConnection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, virtual_host=model.vhost, credentials=creds)) SendConnection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, virtual_host=model.vhost, credentials=creds))
9 9 RecieveConnection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, virtual_host=model.vhost, credentials=creds)) RecieveConnection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, virtual_host=model.vhost, credentials=creds))
 
... ... recieve.queue_declare(
17 17 ) )
18 18
19 19 def callback(ch, method, prop, body): def callback(ch, method, prop, body):
20 print(model.recieveQueue + ': ')
21 #print(body.decode('utf-8', 'ignore'))
22 pyg.update(body)
20 print(model.sendQueue + ': status recieved!')
21 pyg.update(body.decode('utf-8', 'ignore'))
23 22
24 23 def sendMsg(msg): def sendMsg(msg):
25 24 channel.basic_publish ( channel.basic_publish (
 
... ... def sendMsg(msg):
27 26 routing_key=model.sendQueue, routing_key=model.sendQueue,
28 27 body=msg body=msg
29 28 ) )
29 pyg.spawnVehicle(0)
30 30 print('Msg sent.') print('Msg sent.')
31 31
32 32 def listen(): def listen():
 
... ... thread = threading.Thread(target=listen)
42 42 thread.setDaemon(True) thread.setDaemon(True)
43 43 thread.start() thread.start()
44 44 thread.join(0) thread.join(0)
45 '''
45
46 46 gamethread = threading.Thread(target=pyg.gameloop) gamethread = threading.Thread(target=pyg.gameloop)
47 47 gamethread.setDaemon(True) gamethread.setDaemon(True)
48 48 gamethread.start() gamethread.start()
File simulatie/model.py changed (mode: 100644) (index d413a7c..ca92648)
1 1 # Jan Allersma: groep 8. Maakt simulator. # Jan Allersma: groep 8. Maakt simulator.
2 2 uname = 'softdev' uname = 'softdev'
3 3 passwd = 'softdev' passwd = 'softdev'
4 vhost = '/11'
4 vhost = '/8'
5 5 host = '127.0.0.1'#'141.252.237.90' host = '127.0.0.1'#'141.252.237.90'
6 6
7 7 recieveQueue = 'simulator' recieveQueue = 'simulator'
File simulatie/pyg.py changed (mode: 100644) (index 5683e56..0f9270e)
2 2
3 3 import sys, pygame import sys, pygame
4 4 import thread import thread
5 import time
6 import json
5 7
6 8 import trafficModel as tm import trafficModel as tm
7 9
10 vehicles = list()
11
8 12 pygame.init() pygame.init()
9 13
10 14 screen = pygame.display.set_mode((800,800)) screen = pygame.display.set_mode((800,800))
 
... ... bg = pygame.transform.scale(pygame.image.load("./PlattegrondV5.png"), (800,800))
13 17
14 18 class Vehicle(object): class Vehicle(object):
15 19 def __init__(self, x, y, trafficId): def __init__(self, x, y, trafficId):
16 trafficType = tm.lights[trafficId][0]
20 trafficType = tm.lights[trafficId]["Id"]
17 21 print("Traffic type: " + str(trafficType)) print("Traffic type: " + str(trafficType))
18 22 print(trafficType) print(trafficType)
19 23 if trafficType >= 100 and trafficType < 200: # Is een auto if trafficType >= 100 and trafficType < 200: # Is een auto
 
... ... class Vehicle(object):
34 38 self.trafficId = trafficId self.trafficId = trafficId
35 39
36 40 self.wp = 1 self.wp = 1
37 self.rect.x = tm.waypoints[trafficId][0][0]
38 self.rect.y = tm.waypoints[trafficId][0][1]
41 self.waiting = True
42
43 self.rect.x = tm.queues[trafficId][0][0]
44 self.rect.y = tm.queues[trafficId][0][1]
39 45
40 46 if trafficType == 103 or trafficType == 106 or trafficType == 108 or trafficType == 109 or trafficType == 110: if trafficType == 103 or trafficType == 106 or trafficType == 108 or trafficType == 109 or trafficType == 110:
41 47 self.auto = pygame.transform.flip(self.auto, True, False) self.auto = pygame.transform.flip(self.auto, True, False)
42 48
43 49 def update(self): def update(self):
50 screen.blit(self.auto, self.rect)
44 51 self.rect = self.rect.move(self.speed) self.rect = self.rect.move(self.speed)
45 52 if self.dest[0] == self.rect.center[0] or self.dest[0] == self.rect.center[0]+1 or self.dest[0] == self.rect.center[0]-1: if self.dest[0] == self.rect.center[0] or self.dest[0] == self.rect.center[0]+1 or self.dest[0] == self.rect.center[0]-1:
46 53 self.speed[0] = 0 self.speed[0] = 0
 
... ... class Vehicle(object):
61 68 self.speed = [1,1] self.speed = [1,1]
62 69
63 70 def anim(self): def anim(self):
64 if self.speed[0] == 0 and self.speed[1] == 0 and self.wp < len(tm.waypoints[self.trafficId]):
65 self.goto(tm.waypoints[self.trafficId][self.wp][0], tm.waypoints[self.trafficId][self.wp][1])
66 self.wp += 1
67 print(str(self.wp) + " / " + str(len(tm.waypoints[self.trafficId])))
71 if self.speed[0] == 0 and self.speed[1] == 0:
72 if self.waiting and self.wp < len(tm.queues[self.trafficId]):
73 self.goto(tm.queues[self.trafficId][self.wp][0], tm.queues[self.trafficId][self.wp][1])
74 self.wp += 1
75 print("W: " + str(self.wp) + " / " + str(len(tm.queues[self.trafficId])))
76
77 elif self.wp < len(tm.waypoints[self.trafficId]):
78 self.goto(tm.waypoints[self.trafficId][self.wp][0], tm.waypoints[self.trafficId][self.wp][1])
79 self.wp += 1
80 print("NW: " + str(self.wp) + " / " + str(len(tm.waypoints[self.trafficId])))
68 81
82
83
84 def trafficCheck(self):
85 if tm.lights[self.trafficId]["Status"] != 0 and self.waiting and self.wp <= len(tm.queues[self.trafficId]):
86 self.waiting = False
87 self.wp = 0
88 self.update()
69 89
70 90 clock = pygame.time.Clock() clock = pygame.time.Clock()
71 91
72 # moet nog geimplementeerd worden om een nieuw voertuig te spawnen.
73 92 def update(jsonObj): def update(jsonObj):
74 93 result = json.loads(jsonObj) result = json.loads(jsonObj)
75 print(result)
94 tm.lights = result['Lights']
95
96
97 def spawnTrein(naarGroningen):
98 if naarGroningen:
99 train = Vehicle(0,0,28)
100
101 else:
102 train = Vehicle(0,0,29)
103
104 def slagbomenDalen():
105 print("Lichten knipperen & bellen luiden")
106 time.sleep(5)
107 print("Slagbomen dalen..")
108 time.sleep(12)
109 print("Slagbomen zijn dicht.")
110
111 def slagbomenOpenen():
112 print("Slagbomen gaan open..")
113 time.sleep(12)
114 print("Slagbomen zijn open.")
115
116 def spawnVehicle(index):
117 vehicles.append(Vehicle(tm.queues[index][0][0], tm.queues[index][0][1], index))
76 118
77 119 # Mainloop # Mainloop
78 120 def gameloop(): def gameloop():
79 id = 9
80 car = Vehicle(tm.waypoints[id][0][0],tm.waypoints[id][0][1],id)
121 #id = 0
122 #car = Vehicle(tm.queues[id][0][0],tm.queues[id][0][1],id)
81 123 while True: while True:
82 124 clock.tick(60) clock.tick(60)
83 125 for event in pygame.event.get(): for event in pygame.event.get():
 
... ... def gameloop():
85 127
86 128 screen.fill((255,255,255)) screen.fill((255,255,255))
87 129 screen.blit(bg, bg.get_rect()) screen.blit(bg, bg.get_rect())
88 car.update()
89 screen.blit(car.auto, car.rect)
130 for vehicle in vehicles:
131 vehicle.trafficCheck()
132 #car.trafficCheck()
133 #screen.blit(car.auto, car.rect)
90 134 pygame.display.flip() pygame.display.flip()
File simulatie/test/connection.py changed (mode: 100644) (index 2c56479..cdc4e25)
... ... import pika
2 2 import model import model
3 3 import threading import threading
4 4 import json import json
5 import time
5 6
6 7 creds = pika.PlainCredentials(model.uname, model.passwd) creds = pika.PlainCredentials(model.uname, model.passwd)
7 connection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, virtual_host=model.vhost, credentials=creds))
8 channel = connection.channel()
9 recieve = connection.channel()
8 SendConnection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, virtual_host=model.vhost, credentials=creds))
9 RecieveConnection = pika.BlockingConnection(pika.ConnectionParameters(host=model.host, virtual_host=model.vhost, credentials=creds))
10 channel = SendConnection.channel()
11 recieve = RecieveConnection.channel()
10 12
11 13 recieve.queue_declare( recieve.queue_declare(
12 14 queue=model.recieveQueue, queue=model.recieveQueue,
 
... ... recieve.queue_declare(
16 18
17 19 def callback(ch, method, prop, body): def callback(ch, method, prop, body):
18 20 print(model.recieveQueue + ': ') print(model.recieveQueue + ': ')
19 print(body.decode('utf-8', 'ignore'))
21 #print(body.decode('utf-8', 'ignore'))
20 22 msg = json.dumps({ msg = json.dumps({
21 23 "Lights": [ "Lights": [
22 24 { {
 
... ... def callback(ch, method, prop, body):
139 141
140 142 sendMsg(msg) sendMsg(msg)
141 143
142 recieve.basic_consume (
143 callback,
144 queue=model.recieveQueue,
145 no_ack=True
146 )
147
148 144 def sendMsg(msg): def sendMsg(msg):
149 145 channel.basic_publish ( channel.basic_publish (
150 146 exchange='', exchange='',
 
... ... def sendMsg(msg):
155 151
156 152 def listen(): def listen():
157 153 print('Waiting for a sign..') print('Waiting for a sign..')
154 recieve.basic_consume (
155 callback,
156 queue=model.recieveQueue,
157 no_ack=True
158 )
158 159 recieve.start_consuming() recieve.start_consuming()
159 160
160 161 thread = threading.Thread(target=listen) thread = threading.Thread(target=listen)
File simulatie/test/model.py changed (mode: 100644) (index 2e7628a..beb8a8f)
1 1 # Jan Allersma: groep 8. Maakt simulator. # Jan Allersma: groep 8. Maakt simulator.
2 2 uname = 'softdev' uname = 'softdev'
3 3 passwd = 'softdev' passwd = 'softdev'
4 vhost = '/2'
4 vhost = '/8'
5 5 host = '127.0.0.1'#'141.252.237.17' host = '127.0.0.1'#'141.252.237.17'
6 6
7 7 recieveQueue = 'controller' recieveQueue = 'controller'
File simulatie/test/traffic.py changed (mode: 100644) (index c067ce0..d5eef73)
... ... def update(index, amountOfCars, dirRequests):
39 39 lights[index][2] = dirRequests lights[index][2] = dirRequests
40 40
41 41 msg = json.dumps({ msg = json.dumps({
42 "TrafficUpdate": {
43 "LightId": lights[index][0],
44 "Count": lights[index][1],
45 "DirectionRequests": lights[index][2]
46 }
42 "Lights": [
43 {
44 "Id": 101,
45 "Status": 2,
46 "Time": -1
47 },
48 {
49 "Id": 102,
50 "Status": 1,
51 "Time": -1
52 },
53 {
54 "Id": 103,
55 "Status": 0,
56 "Time": -1
57 },
58 {
59 "Id": 104,
60 "Status": 0,
61 "Time": -1
62 },
63 {
64 "Id": 105,
65 "Status": 0,
66 "Time": -1
67 },
68 {
69 "Id": 106,
70 "Status": 0,
71 "Time": -1
72 },
73 {
74 "Id": 107,
75 "Status": 0,
76 "Time": -1
77 },
78 {
79 "Id": 108,
80 "Status": 0,
81 "Time": -1
82 },
83 {
84 "Id": 109,
85 "Status": 0,
86 "Time": -1
87 },
88 {
89 "Id": 110,
90 "Status": 0,
91 "Time": -1
92 },
93 {
94 "Id": 201,
95 "Status": 4,
96 "Time": -1
97 },
98 {
99 "Id": 301,
100 "Status": 0,
101 "Time": 7
102 },
103 {
104 "Id": 302,
105 "Status": 0,
106 "Time": 14
107 },
108 {
109 "Id": 303,
110 "Status": 0,
111 "Time": -1
112 },
113 {
114 "Id": 304,
115 "Status": 0,
116 "Time": -1
117 },
118 {
119 "Id": 305,
120 "Status": 0,
121 "Time": -1
122 },
123 {
124 "Id": 401,
125 "Status": 0,
126 "Time": -1
127 },
128 {
129 "Id": 402,
130 "Status": 0,
131 "Time": -1
132 },
133 {
134 "Id": 403,
135 "Status": 0,
136 "Time": -1
137 },
138 {
139 "Id": 404,
140 "Status": 0,
141 "Time": -1
142 },
143 {
144 "Id": 405,
145 "Status": 0,
146 "Time": -1
147 },
148 {
149 "Id": 406,
150 "Status": 0,
151 "Time": -1
152 },
153 {
154 "Id": 601,
155 "Status": 2,
156 "Time": -1
157 }
158 ]
47 159 }, sort_keys=True, indent=4, separators=(',',': ')) }, sort_keys=True, indent=4, separators=(',',': '))
48 160
161 print(msg)
49 162 connection.sendMsg(msg) connection.sendMsg(msg)
50 163
51 164 while True: while True:
File simulatie/traffic.py changed (mode: 100644) (index afdc321..af2c9a5)
... ... def update(index, amountOfCars, dirRequests):
46 46 } }
47 47 }, sort_keys=True, indent=4, separators=(',',': ')) }, sort_keys=True, indent=4, separators=(',',': '))
48 48
49 #connection.sendMsg(msg)
49 connection.sendMsg(msg)
50 50
51 51 while True: while True:
52 52 ui = raw_input() ui = raw_input()
File simulatie/trafficModel.py changed (mode: 100644) (index de865c2..118f34e)
... ... import json
21 21 0 = Stoppen. 0 = Stoppen.
22 22 2 = Doorrijden/lopen. 2 = Doorrijden/lopen.
23 23 ''' '''
24 # lights = [[id, status]]
24
25 25 lights = [ lights = [
26 [101, 0],
27 [102, 0],
28 [103, 0],
29 [104, 0],
30 [105, 0],
31 [106, 0],
32 [107, 0],
33 [108, 0],
34 [109, 0],
35 [110, 0],
36 [201, 0],
37 [301, 0],
38 [302, 0],
39 [303, 0],
40 [304, 0],
41 [305, 0],
42 [401, 0],
43 [402, 0],
44 [403, 0],
45 [404, 0],
46 [405, 0],
47 [406, 0],
48 [501, 0],
49 [601, 0]
26 {
27 "Id": 101,
28 "Status": 0
29 },
30 {
31 "Id": 102,
32 "Status": 0
33 },
34 {
35 "Id": 103,
36 "Status": 0
37 },
38 {
39 "Id": 104,
40 "Status": 0
41 },
42 {
43 "Id": 105,
44 "Status": 0
45 },
46 {
47 "Id": 106,
48 "Status": 0
49 },
50 {
51 "Id": 107,
52 "Status": 0
53 },
54 {
55 "Id": 108,
56 "Status": 0
57 },
58 {
59 "Id": 109,
60 "Status": 0
61 },
62 {
63 "Id": 110,
64 "Status": 0
65 },
66 {
67 "Id": 201,
68 "Status": 0
69 },
70 {
71 "Id": 301,
72 "Status": 0
73 },
74 {
75 "Id": 302,
76 "Status": 0
77 },
78 {
79 "Id": 303,
80 "Status": 0
81 },
82 {
83 "Id": 304,
84 "Status": 0
85 },
86 {
87 "Id": 305,
88 "Status": 0
89 },
90 {
91 "Id": 401,
92 "Status": 0
93 },
94 {
95 "Id": 402,
96 "Status": 0
97 },
98 {
99 "Id": 403,
100 "Status": 0
101 },
102 {
103 "Id": 404,
104 "Status": 0
105 },
106 {
107 "Id": 405,
108 "Status": 0
109 },
110 {
111 "Id": 406,
112 "Status": 0
113 },
114 {
115 "Id": 407,
116 "Status": 0
117 },
118 {
119 "Id": 408,
120 "Status": 0
121 },
122 {
123 "Id": 409,
124 "Status": 0
125 },
126 {
127 "Id": 410,
128 "Status": 0
129 },
130 {
131 "Id": 411,
132 "Status": 0
133 },
134 {
135 "Id": 412,
136 "Status": 0
137 },
138 {
139 "Id": 501,
140 "Status": 0
141 },
142 {
143 "Id": 502,
144 "Status": 0
145 },
146 {
147 "Id": 601,
148 "Status": 0
149 }
50 150 ] ]
51 151
52 waypoints = [
53 [ # 101
152 queues = [
153 [ #101
54 154 [300, -50], [300, -50],
55 155 [300, 0], [300, 0],
156 [300, 140]
157 ],
158 [ #102
159 [350, -50],
160 [350, 0],
161 [350, 140]
162 ],
163 [ #103
164 [400, -50],
165 [400, 0],
166 [400, 140]
167 ]
168 ]
169
170 waypoints = [
171 [ # 101
172 #[300, -50],
173 #[300, 0],
174 #[300, 140]
56 175 [300, 280], [300, 280],
57 176 [-50, 300] [-50, 300]
58 177 ], ],
59 178 [ # 102 [ # 102
60 [350, -50],
61 [350, 0],
179 #[350, -50],
180 #[350, 0],
62 181 [350, 300], [350, 300],
63 182 [310, 600], [310, 600],
64 183 [310, 850] [310, 850]
65 184 ], ],
66 185 [ # 103 [ # 103
67 [400, -50],
68 [400, 0],
186 #[400, -50],
187 #[400, 0],
69 188 [400, 350], [400, 350],
70 189 [850, 450] [850, 450]
71 190 ], ],
 
... ... waypoints = [
109 228 ] ]
110 229
111 230 ] ]
112
113 def update(jsonObj):
114 result = json.loads(jsonObj)
115 print(result)
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/kapstok/NHL-SoftDev

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/kapstok/NHL-SoftDev

Clone this repository using git:
git clone git://git.rocketgit.com/user/kapstok/NHL-SoftDev

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main