From 151948dbb1511dae01230e7ccefd2e26837d7064 Mon Sep 17 00:00:00 2001 From: janton01 Date: Sat, 17 Dec 2016 18:01:43 -0500 Subject: [PATCH 1/3] No need to pass packetID as since it creates a randomly generated number within the initialization --- cloud.py | 6 +++--- packet.py | 2 +- testCloud.py | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cloud.py b/cloud.py index a452c6f..fa0633a 100644 --- a/cloud.py +++ b/cloud.py @@ -7,7 +7,7 @@ MED_P_CLOUD_DELAY = 5 LOW_P_CLOUD_DELAY = 3 NUM_PLAYERS = 10 -ks + class Cloud(object): def __init__(self, gameTraffic, location, timeout): @@ -27,7 +27,7 @@ def __init__(self, gameTraffic, location, timeout): def updateTime(self, time): # is this how it works? self.timeMS = time - return processResponse(self) + return processResponinterse(self) def processResponse(self): @@ -36,7 +36,7 @@ def processResponse(self): if (time - headPacket.timestamp) > timeout: return None else: - responsePackets[] + responsePackets = [] for i in range(1,NUM_PLAYERS): newPacket = headPacket diff --git a/packet.py b/packet.py index 7a6cc17..92a2a58 100644 --- a/packet.py +++ b/packet.py @@ -2,7 +2,7 @@ class Packet(object): - def __init__(self, packet_id, event, timestamp, receiverAddress, senderAddress): + def __init__(self, event, timestamp, receiverAddress, senderAddress): self._init_packet_id() self.event = event self.timestamp = timestamp diff --git a/testCloud.py b/testCloud.py index d6f7140..50e8da3 100644 --- a/testCloud.py +++ b/testCloud.py @@ -1,7 +1,20 @@ import cloud - +import packet if __name__ == "__main__": + +def __init__(self, packet_id, event, timestamp, receiverAddress, senderAddress): + self._init_packet_id() + self.event = event + self.timestamp = timestamp + self.position = position + self.receiverAddress = receiverAddress + self.senderAddress = senderAddress + + + packet1 = packet() + + packet1.id = 0 packet1.sendAddress = 1 packet1.receiveAddress = 0 From f543769ca4d948b3792ffd518f9e7385a122ebcc Mon Sep 17 00:00:00 2001 From: janton01 Date: Sat, 17 Dec 2016 18:21:14 -0500 Subject: [PATCH 2/3] New changes to cloud, can run now --- cloud.py | 13 ++++++------- packet.py | 2 +- testCloud.py | 35 ++++++++--------------------------- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/cloud.py b/cloud.py index fa0633a..2fbcf3b 100644 --- a/cloud.py +++ b/cloud.py @@ -10,7 +10,7 @@ class Cloud(object): - def __init__(self, gameTraffic, location, timeout): + def __init__(self, gameTraffic, location, timeout, num_players): self.requestList = Queue.Queue() @@ -27,13 +27,12 @@ def __init__(self, gameTraffic, location, timeout): def updateTime(self, time): # is this how it works? self.timeMS = time - return processResponinterse(self) + return self.processResponse(time) - def processResponse(self): - - if self.timeMS % timeToProcess == 0 and not self.requestList.empty() : + def processResponse(self, time): + if self.timeMS % self.timeToProcess == 0 and not self.requestList.empty() : headPacket = self.requestList.get(); - if (time - headPacket.timestamp) > timeout: + if (time - headPacket.timestamp) > self.timeout: return None else: responsePackets = [] @@ -43,7 +42,7 @@ def processResponse(self): # update packet newPacket.sendAddress = 0 newPacket.receiveAddress = i - responsePackets[i].append(newPacket) + responsePackets.append(newPacket) return responsePackets else: return None diff --git a/packet.py b/packet.py index 92a2a58..1c3b786 100644 --- a/packet.py +++ b/packet.py @@ -2,7 +2,7 @@ class Packet(object): - def __init__(self, event, timestamp, receiverAddress, senderAddress): + def __init__(self, event, timestamp, position, receiverAddress, senderAddress): self._init_packet_id() self.event = event self.timestamp = timestamp diff --git a/testCloud.py b/testCloud.py index 50e8da3..0ed0441 100644 --- a/testCloud.py +++ b/testCloud.py @@ -3,39 +3,20 @@ if __name__ == "__main__": -def __init__(self, packet_id, event, timestamp, receiverAddress, senderAddress): - self._init_packet_id() - self.event = event - self.timestamp = timestamp - self.position = position - self.receiverAddress = receiverAddress - self.senderAddress = senderAddress + packet1 = packet.Packet(0, 100, 0, 0, 1) + packet2 = packet.Packet(0, 100, 0, 0, 2) + cloud = cloud.Cloud(0, 0, 10, 10) + cloud.receiveRequest(packet1) + cloud.receiveRequest(packet2) - packet1 = packet() + time = 90 - - packet1.id = 0 - packet1.sendAddress = 1 - packet1.receiveAddress = 0 - packet1.timestamp = 100 - packet2.id = 1 - packet2.sendAddress = 2 - packet2.receiveAddress = 0 - packet2.timestamp = 0 - - cloud = Cloud(0, 0, 10) - - cloud.receiveRequest(packet1) - cloud.receiveRequest(packet2) - - time = 90 - - for i in range(0,10): + for i in range(0,10): time = time + 1 packetList = cloud.updateTime(time) if packetList != None: - print packetList[0].id + print packetList[0].packet_id From cd61056b908e3f78df80b73e34a25cd6ae129322 Mon Sep 17 00:00:00 2001 From: janton01 Date: Sat, 17 Dec 2016 18:23:56 -0500 Subject: [PATCH 3/3] Simple tests for cloud --- cloud.py | 4 ++-- testCloud.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cloud.py b/cloud.py index 2fbcf3b..79daf83 100644 --- a/cloud.py +++ b/cloud.py @@ -6,7 +6,6 @@ HI_P_CLOUD_DELAY = 10 MED_P_CLOUD_DELAY = 5 LOW_P_CLOUD_DELAY = 3 -NUM_PLAYERS = 10 class Cloud(object): @@ -21,6 +20,7 @@ def __init__(self, gameTraffic, location, timeout, num_players): else: self.timeToProcess = HIGH_P_CLOUD_DELAY + self.num_players = num_players self.location = location self.timeMS = 0 self.timeout = timeout @@ -36,7 +36,7 @@ def processResponse(self, time): return None else: responsePackets = [] - for i in range(1,NUM_PLAYERS): + for i in range(1,self.num_players): newPacket = headPacket # update packet diff --git a/testCloud.py b/testCloud.py index 0ed0441..37e951b 100644 --- a/testCloud.py +++ b/testCloud.py @@ -4,7 +4,7 @@ if __name__ == "__main__": packet1 = packet.Packet(0, 100, 0, 0, 1) - packet2 = packet.Packet(0, 100, 0, 0, 2) + packet2 = packet.Packet(0, 0, 0, 0, 2) cloud = cloud.Cloud(0, 0, 10, 10) cloud.receiveRequest(packet1)