#!/usr/bin/python3

from random_circle_removal import random_circle_removal
from gradings import get_gradings
from PageRank import page_rank
from EM import em
from borda_ordering import borda_ordering

def th(ranking, th):
    limit = int(len(ranking) * th)
    ranking = list(filter(lambda x: x <= limit, ranking))
    rlen = len(ranking)
    cnt = 0
    total = 0

    for i in range(rlen):
        for j in range(i + 1, rlen):
            total = total + 1
            if ranking[i] < ranking[j]:
                cnt = cnt + 1
    return cnt / total

def acc(ranking, acc):
    rlen = len(ranking)
    gap = acc * rlen
    cnt = 0
    total = 0
    for i in range(rlen):
        for j in range(i + 1, rlen):
            if abs(ranking[i] - ranking[j]) >= gap:
                total = total + 1
                if ranking[i] < ranking[j]:
                    cnt = cnt + 1
    return cnt / total

if __name__ == '__main__':
    gradings = get_gradings(1000, 6)
    all2all = []
    th10 = []
    th50 = []
    acc2 = []
    acc5 = []

    ranking = random_circle_removal(gradings)
    all2all.append(th(ranking, 1))
    th10.append(th(ranking, 0.1))
    th50.append(th(ranking, 0.5))
    acc2.append(acc(ranking, 0.02))
    acc5.append(acc(ranking, 0.05))

    ranking = page_rank(gradings)
    all2all.append(th(ranking, 1))
    th10.append(th(ranking, 0.1))
    th50.append(th(ranking, 0.5))
    acc2.append(acc(ranking, 0.02))
    acc5.append(acc(ranking, 0.05))

    ranking = em(gradings)
    all2all.append(th(ranking, 1))
    th10.append(th(ranking, 0.1))
    th50.append(th(ranking, 0.5))
    acc2.append(acc(ranking, 0.02))
    acc5.append(acc(ranking, 0.05))

    ranking = borda_ordering(gradings)
    all2all.append(th(ranking, 1))
    th10.append(th(ranking, 0.1))
    th50.append(th(ranking, 0.5))
    acc2.append(acc(ranking, 0.02))
    acc5.append(acc(ranking, 0.05))

    print(all2all)
    print(th10)
    print(th50)
    print(acc2)
    print(acc5)

@@ -195,16 +195,18 @@
 dering%0A%0A
+# 
 def th(r
@@ -218,16 +218,18 @@
 g, th):%0A
+# 
     limi
@@ -255,20 +255,22 @@
 ) * th)%0A
+#
     
+ 
 ranking 
@@ -315,16 +315,328 @@
 nking))%0A
+#     rlen = len(ranking)%0A#     cnt = 0%0A#     total = 0%0A%0A#     for i in range(rlen):%0A#         for j in range(i + 1, rlen):%0A#             total = total + 1%0A#             if ranking%5Bi%5D %3C ranking%5Bj%5D:%0A#                 cnt = cnt + 1%0A#     return cnt / total%0A%0Adef th(ranking, th):%0A    limit = int(len(ranking) * th)%0A
     rlen
@@ -675,17 +675,31 @@
 total = 
-0
+rlen*(rlen-1)/2
 %0A%0A    fo
@@ -767,34 +767,68 @@
         
-total = total + 1%0A
+if (ranking%5Bi%5D %3C limit) or (ranking%5Bj%5D %3C limit):%0A   
         
@@ -823,35 +823,37 @@
 %0A               
+ 
 if 
+(
 ranking%5Bi%5D %3C ran
@@ -851,34 +851,39 @@
 %5Bi%5D %3C ranking%5Bj%5D
+)
 :%0A
+    
                 

Update the correctness computation for top ranks.