forked from i5o/GCILeaderboard-old
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
183 lines (149 loc) · 5.12 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import sys
from HTMLParser import HTMLParser
from flask import *
app = Flask(__name__)
parser = HTMLParser()
BASEURL = "http://www.google-melange.com/gci/org/google/gci2014/" \
"{orgname}?fmt=json&limit=1000&idx=1"
orglist = ['sugarlabs',
'mifos',
'apertium',
'brlcad',
'sahana',
'copyleftgames',
'openmrs',
'wikimedia',
'kde',
'haiku',
'drupal',
'fossasia']
@app.context_processor
def utility_processor():
def shorten(text, max_len=250):
if len(text) < max_len:
return text
word_wrap = text[:max_len].rfind(' ')
word_wrap = max_len if word_wrap == -1 else word_wrap
return text[:word_wrap] + '..'
def noun_form(num, singular_form, plural_form):
if num > 1 or num == 0:
return plural_form
return singular_form
def org_tabactive_attr(org, tab_org):
if tab_org.lower() == org.lower():
return 'class=pure-menu-selected'
return dict(
shorten=shorten,
noun_form=noun_form,
org_tabactive_attr=org_tabactive_attr
)
@app.errorhandler(404)
def page_not_found(e):
return render_template('errors/404.html', org=''), 404
@app.route('/')
def index():
return redirect('all')
@app.route('/student/<name>-count=<int:e>-org<org>')
def student(name, e=0, org=None):
tasks = []
code = 0
interface = 0
quality = 0
doc = 0
research = 0
total = 0
isAll = False
if u'All' in org:
isAll = True
for orgname in orglist:
page_json_f = open("orgs/%s.json" % orgname, "r")
page_json = json.loads(page_json_f.read())
page_json_f.close()
data = page_json['data']['']
for row in data:
student_name = row['columns']['student']
if student_name == name and (isAll or orgname == org):
total += 1
student_name = row['columns']['student']
title = parser.unescape(row['columns']['title']).capitalize()
link = "http://www.google-melange.com" + \
row['operations']['row']['link']
type_ = row['columns']['types']
if "Code" in type_:
code += 1
type_ = 'Code'
elif "Documentation" in type_:
doc += 1
type_ = 'Documentation'
elif "Research" in type_:
research += 1
type_ = 'Outreach / Research'
elif "Quality" in type_:
quality += 1
type_ = 'Quality Assurance'
elif "User Interface" in type_:
interface += 1
type_ = 'User Interface'
task = (title, link, type_, orgname)
if task in tasks:
continue
tasks.append(task)
tasks.sort()
return render_template(
"student.html",
tasks=tasks,
total=total,
code=code,
interface=interface,
quality=quality,
documentation=doc,
research=research,
name=name,
org=org)
@app.route('/org/<org>/')
def leaderboard(org):
page_json_f = open("orgs/%s.json" % org, "r")
page_json = json.loads(page_json_f.read())
page_json_f.close()
final_dict = {}
data = page_json['data']['']
for row in data:
student_name = row['columns']['student']
if student_name in final_dict:
final_dict[student_name] += 1
else:
final_dict[student_name] = 1
sorted_dict = sorted(final_dict.iteritems(), key=lambda x: x[1],
reverse=True)
total = sum([int(tup[1]) for tup in final_dict.iteritems()])
total_students = len(set([tup[0] for tup in final_dict.iteritems()]))
return render_template("org.html", leaderboard=sorted_dict,
org=org,
total=total,
students=total_students)
@app.route('/all/')
def allorgs(draw=True):
final_dict = {}
current = 0
for org in orglist:
page_json_f = open("orgs/%s.json" % org, "r")
page_json = json.loads(page_json_f.read())
page_json_f.close()
data = page_json['data']['']
for row in data:
student_name = row['columns']['student']
if student_name in final_dict:
final_dict[student_name] += 1
else:
final_dict[student_name] = 1
current += 1
sorted_dict = sorted(final_dict.iteritems(), key=lambda x: x[1],
reverse=True)
total = sum([int(tup[1]) for tup in final_dict.iteritems()])
total_students = len(set([tup[0] for tup in final_dict.iteritems()]))
return render_template("org.html", leaderboard=sorted_dict,
org="All Organizations",
total=total,
students=total_students)
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0", port=int(sys.argv[1]))