-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
155 lines (121 loc) · 3.46 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import json
import matplotlib
import random
import time
from matplotlib import pyplot
class BloodMessage:
Owner = ''
AreaNumber = 0
WorldNumber = 0
XCoord = 0
YCoord = 0
ZCoord = 0
Angle = 0
TextID1 = 0
TextID2 = 0
Text = ''
PositiveRatings = 0
NegativeRatings = 0
UnixTime = ''
TimeString = ''
def __init__(self, Owner, WorldNumber, XCoord, YCoord, ZCoord, Text):
self.Owner = Owner
self.WorldNumber = WorldNumber
self.XCoord = XCoord
self.YCoord = YCoord
self.ZCoord = ZCoord
self.Text = Text
def __str__(self):
return self.Text
def __lt__(self, other):
if(self.WorldNumber == other.WorldNumber):
return self.Owner < other.Owner
return self.WorldNumber < other.WorldNumber
def __le__(self, other):
if(self.WorldNumber == other.WorldNumber):
return self.Owner <= other.Owner
return self.WorldNumber <= other.WorldNumber
file = open("BloodMessages.json", "r")
jsondata = file.read()
jdata = json.loads(jsondata)
data = jdata['BloodMessages'] # Lista de dicionarios de BloodMessages
messages = []
for message in data:
messages.append(BloodMessage(message['Owner'], message['WorldNumber'], message['XCoord'], message['YCoord'], message['ZCoord'], message['Text']))
mergeIteration = 0
def mergeSort(arr):
global mergeIteration
if len(arr) > 1:
mid = len(arr)//2
L = arr[:mid]
R = arr[mid:]
mergeSort(L)
mergeSort(R)
i = j = k = 0
while i < len(L) and j < len(R):
if L[i] < R[j]:
arr[k] = L[i]
mergeIteration+=1
i+=1
else:
arr[k] = R[j]
mergeIteration+=1
j+=1
k+=1
while i < len(L):
arr[k] = L[i]
mergeIteration+=1
i+=1
k+=1
while j < len(R):
arr[k] = R[j]
mergeIteration+=1
j+=1
k+=1
quickIteration = 0
def partition(arr,low,high):
global quickIteration
i = (low-1)
pivot = arr[high]
for j in range(low , high):
if arr[j] <= pivot:
i = i+1
arr[i],arr[j] = arr[j],arr[i]
quickIteration+=2
arr[i+1],arr[high] = arr[high],arr[i+1]
quickIteration+=2
return (i+1)
def quickSort(arr,low,high):
if low < high:
pi = partition(arr,low,high)
quickSort(arr, low, pi-1)
quickSort(arr, pi+1, high)
print("Foram lidos: " + str(len(data)) + " Blood Messages")
arr1 = messages
begin = time.time()
quickSort(arr1, 0, len(arr1)-1)
end = time.time()
quick_time = end - begin
arr2 = messages
begin = time.time()
mergeSort(arr2)
end = time.time()
merge_time = end - begin
print('O Merge sort, algoritmo estavel, demorou {} segundos, tendo feito {} atribuicoes e o Quick sort, instavel, demorou {} segundos, tendo feito {} atribuicoes'.format(merge_time, mergeIteration, quick_time, quickIteration))
Messages_per_world_X = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [],
6: [], 7: [], 8: [], 9: [], 10: [], 11: [],
12: [], 13: [], 14: [], 15: [], 16: [], 17: [], 18: []}
Messages_per_world_Y = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [],
6: [], 7: [], 8: [], 9: [], 10: [], 11: [],
12: [], 13: [], 14: [], 15: [], 16: [], 17: [], 18: []}
for each in arr1:
Messages_per_world_X[each.WorldNumber].append(each.XCoord)
Messages_per_world_Y[each.WorldNumber].append(each.YCoord)
# Ignorando os mundos [1:9] pois nao possuem mensagens
for i in range(9):
fig, ax = pyplot.subplots()
pyplot.xlabel('Position X')
pyplot.ylabel('Position Y')
ax.scatter(Messages_per_world_X[i+10], Messages_per_world_Y[i+10], label='World: '+str(i+10))
pyplot.legend()
pyplot.show()