|
@@ -3,7 +3,10 @@
|
|
|
# "is2 Thi1s T4est 3a" --> "Thi1s is2 3a T4est"
|
|
|
# "4of Fo1r pe6ople g3ood th5e the2" --> "Fo1r the2 g3ood 4of th5e pe6ople"
|
|
|
|
|
|
-#
|
|
|
+from operator import itemgetter
|
|
|
+from numpy import block
|
|
|
+
|
|
|
+
|
|
|
def order(sentence):
|
|
|
my_list = sentence.split(' ')
|
|
|
new_list = []
|
|
@@ -27,6 +30,7 @@ def order(sentence):
|
|
|
|
|
|
# print(order("is2 Thi1s T4est 3a"))
|
|
|
|
|
|
+# ------------------------------------------------------------------------------- #
|
|
|
|
|
|
#
|
|
|
def find_even_index(arr):
|
|
@@ -63,3 +67,91 @@ def find_even_index(arr):
|
|
|
# print(find_even_index([1,2,3,4,3,2,1]))
|
|
|
# print(find_even_index([1,2,3,4,5,6]))
|
|
|
|
|
|
+# ------------------------------------------------------------------------------- #
|
|
|
+
|
|
|
+class StatisticalSummary(object):
|
|
|
+
|
|
|
+ BOXPLOT = 0
|
|
|
+ BOX_AND_WHISKER = 1
|
|
|
+ BOX_AND_DECILE_WHISKER = 2
|
|
|
+ TUKEY_BOX_AND_WHISKER = 3
|
|
|
+
|
|
|
+ def __init__(self, seq):
|
|
|
+ self.seq = seq
|
|
|
+ self.le = 0
|
|
|
+ self.eu = 0
|
|
|
+ self.median = 0
|
|
|
+ self.q1 = 0
|
|
|
+ self.q3 = 0
|
|
|
+
|
|
|
+ def boxplot(self, plot=BOXPLOT, precision=None):
|
|
|
+ result = []
|
|
|
+ temp_list = []
|
|
|
+ number = 0
|
|
|
+
|
|
|
+ if type(self.seq[0]) == tuple:
|
|
|
+ print("Пока не обрабатываем картежи")
|
|
|
+ else:
|
|
|
+ temp_list = self.clear_list(self.seq)
|
|
|
+ temp_list.sort()
|
|
|
+ self.calculation(temp_list)
|
|
|
+
|
|
|
+ result.append(('Sample', number))
|
|
|
+
|
|
|
+ return result
|
|
|
+
|
|
|
+ def calculation(self, data):
|
|
|
+ self.le = min(data)
|
|
|
+ self.eu = max(data)
|
|
|
+ self.median = self.calculate_median(data)
|
|
|
+ self.calculate_quartile(data)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def clear_list(self, data):
|
|
|
+ cleared_list = []
|
|
|
+ for i in data:
|
|
|
+ if type(i) == int or type(i) == float:
|
|
|
+ cleared_list.append(i)
|
|
|
+ return cleared_list
|
|
|
+
|
|
|
+ def calculate_median(self, data):
|
|
|
+ data_len = len(data)
|
|
|
+ if data_len%2 == 0:
|
|
|
+ return ((data[int(data_len/2) - 1] + data[int(data_len/2)]))/2
|
|
|
+ else:
|
|
|
+ return data[data_len//2]
|
|
|
+
|
|
|
+ def calculate_quartile(self, data):
|
|
|
+ data_len = len(data)
|
|
|
+
|
|
|
+ if data_len%4 == 0:
|
|
|
+ index = int(data_len/4)
|
|
|
+ q1 = (data[index] - data[index - 1])*0.25 + data[index - 1]
|
|
|
+ index = int(data_len/4*3)
|
|
|
+ q3 = (data[index] - data[index - 1])*0.75 + data[index - 1]
|
|
|
+ print(data)
|
|
|
+ print(q1)
|
|
|
+ print(q3)
|
|
|
+ return q1, q3
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+data = list(range(1, 33)) + list(range(12, 21)) + list(range(12, 21)) + list(range(12, 21)) + [16]
|
|
|
+d1 = list(range(1, 33)) + list(range(12, 21)) + list(range(12, 21)) + list(range(12, 21)) + [16]
|
|
|
+
|
|
|
+# print(data)
|
|
|
+
|
|
|
+# d1 = range(1, 33) + range(12, 21) + range(12, 21) + range(12, 21) + [16]
|
|
|
+d2 = [d - 2 for d in d1[:len(data)//2]] + [d + 2 for d in d1[len(data)//2:]]
|
|
|
+data2 = [("A", n) for n in d1] + [("B", n) for n in d2]
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# print(data2)
|
|
|
+# print(type(data2))
|
|
|
+# print(d2)
|
|
|
+test_list = [1, 2, 5, 2, 3, 'asdfasd', 2, 3, 12, 45, 3, 6, 25, 54, 32, 12, 14]
|
|
|
+
|
|
|
+summary1 = StatisticalSummary(test_list)
|
|
|
+summary1.boxplot()
|