-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain2_chinese_trueskill.py
More file actions
74 lines (53 loc) · 1.42 KB
/
main2_chinese_trueskill.py
File metadata and controls
74 lines (53 loc) · 1.42 KB
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
from trueskill import *
import pagerank
from Question import Question
from common2 import *
graph = []
edges_dict = {}
def addEdge(e):
if e not in edges_dict:
edges_dict[e] = True
graph.append(e)
counter = 0
for user in user_questions.keys(): #iterate over the users
counter += 1
if counter % 100 == 0:
print counter, "# edges:", len(graph)
try:
non_best_answers = user_non_best_answers_question_id[user]
best_answers = user_best_answers_question_id[user]
except:
continue
for best_answer_question_id in best_answers:
for non_best_answer_question_id in non_best_answers:
addEdge((int(non_best_answer_question_id), int(best_answer_question_id)))
# from hits_nx import hits_nx
# import networkx as nx
# G=nx.Graph()
# for edge in graph:
# G.add_edge(*edge)
# h,a=hits_nx(G)
# difficulty = dict()
# for i in questions.keys():
# if(h.has_key(int(i))):
# difficulty[int(i)] = h[int(i)]
# else:
# difficulty[int(i)]=0
# computeAccuracy(difficulty)
ratings = {}
counter = 0
for (v1, v2) in graph:
counter += 1
if counter % 1000 == 0:
print counter
if v1 not in ratings:
ratings[v1] = Rating()
if v2 not in ratings:
ratings[v2] = Rating()
ratings[v2], ratings[v1] = rate_1vs1(ratings[v2], ratings[v1])
f = open('edges_chinese.txt','w')
for edge in graph:
f.write(str(edge[0]) + " " + str(edge[1]) + "\n")
f.close()
# ratings = pagerank.pagerank(graph)[0]
computeAccuracy(ratings)