Skip to content

Commit e24fdbe

Browse files
committedJan 25, 2017
fixed error querying openhub and add judgement results for hard metrics
1 parent ebd392d commit e24fdbe

File tree

4 files changed

+254
-58
lines changed

4 files changed

+254
-58
lines changed
 

‎query.py

+124-34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding=utf-8
12
# query openhub and github
23
import requests
34
from bs4 import BeautifulSoup
@@ -67,25 +68,55 @@ def queryGithub(searchTerm):
6768
jsonLatest = json.loads(latestJson)
6869
jsonLicense = json.loads(licenseJson)
6970

70-
print '# of stars: ', jsonBasic['watchers_count']
71-
print '# of forks: ', jsonBasic['forks_count']
72-
print 'latest release publish date: ', jsonLatest['published_at']
73-
print 'Licesne: ', jsonLicense['license']['name']
74-
print 'Open Issues Count: ', jsonBasic['open_issues_count']
75-
print 'Subscribers Count: ', jsonBasic['subscribers_count']
71+
# print '# of stars: ', jsonBasic['watchers_count']
72+
# print '# of forks: ', jsonBasic['forks_count']
73+
# print 'latest release publish date: ', jsonLatest['published_at']
74+
# print 'Licesne: ', jsonLicense['license']['name']
75+
# print 'Open Issues Count: ', jsonBasic['open_issues_count']
76+
# print 'Subscribers Count: ', jsonBasic['subscribers_count']
7677

7778
map={}
7879
map["github_url"] = githubURL
79-
map["number_of_starts"] = jsonBasic['watchers_count']
80-
map["number_of_forks"] = jsonBasic['forks_count']
80+
81+
number_of_stars = jsonBasic['watchers_count']
82+
number_of_forks = jsonBasic['forks_count']
83+
open_issues_count = jsonBasic['open_issues_count']
84+
subscribers_count = jsonBasic['subscribers_count']
85+
86+
map["number_of_stars"] = number_of_stars
87+
if number_of_stars >= 100:
88+
map["number_of_stars_filter"] = "√"
89+
else:
90+
map["number_of_stars_filter"] = "×"
91+
92+
map["number_of_forks"] = number_of_forks
93+
if number_of_forks >= 100:
94+
map["number_of_forks_filter"] = "√"
95+
else:
96+
map["number_of_forks_filter"] = "×"
97+
8198
map["latest_release_publish_date"] = jsonLatest['published_at']
99+
82100
map["licesne"] = jsonLicense['license']['name']
83-
map["open_issues_count"] = jsonBasic['open_issues_count']
84-
map["subscribers_count"] = jsonBasic['subscribers_count']
101+
102+
map["open_issues_count"] = open_issues_count
103+
if open_issues_count >= 5:
104+
map["open_issues_count_filter"] = "√"
105+
else:
106+
map["open_issues_count_filter"] = "×"
107+
108+
map["subscribers_count"] = subscribers_count
109+
if subscribers_count >= 50:
110+
map["subscribers_count_filter"] = "√"
111+
else:
112+
map["subscribers_count_filter"] = "×"
113+
114+
#print json.dumps({"result":map})
85115
return json.dumps({"result": map})
86116

87117

88118
def queryOpenHub(queryTerm):
119+
map={}
89120
api_key = "85690631252ec7681f0e7ac7f46725c4fcc8b56cd2f6c38cb4a7cf7961512f98"
90121
#query_term = "electron"
91122
page_num = "1"
@@ -94,36 +125,95 @@ def queryOpenHub(queryTerm):
94125
print url
95126
soup = BeautifulSoup(resp.content, "html.parser")
96127
# we use beautiful soup to get the #1 rank project id & url on Openhub
97-
project_id = soup.find('id').get_text()
128+
try:
129+
map["query_openhub_success"] = "succeeded"
130+
project_id = soup.find('id').get_text()
131+
except:
132+
# query openhub failed, quit
133+
map["query_openhub_success"] = "failed"
134+
project_id = None
98135
print project_id
99-
project_html_url = soup.find('html_url').get_text()
136+
try:
137+
project_html_url = soup.find('html_url').get_text()
138+
except:
139+
project_html_url = ''
100140
print project_html_url
101141

102-
project_query_url = "https://www.openhub.net/projects/" + str(project_id) + ".xml?api_key=" + api_key
103-
print project_query_url
142+
if map["query_openhub_success"] == "succeeded":
143+
project_query_url = "https://www.openhub.net/projects/" + str(project_id) + ".xml?api_key=" + api_key
144+
print project_query_url
104145

105-
openhub_resp_content = requests.get(project_query_url,verify=False).content
146+
openhub_resp_content = requests.get(project_query_url,verify=False).content
106147

107-
openhub_soup = BeautifulSoup(openhub_resp_content, "html.parser")
108-
project_twelve_month_contributor_count = openhub_soup.find('twelve_month_contributor_count').get_text()
109-
project_total_contributor_count = openhub_soup.find('total_contributor_count').get_text()
110-
project_twelve_month_commit_count = openhub_soup.find('twelve_month_commit_count').get_text()
111-
project_total_commit_count = openhub_soup.find('total_commit_count').get_text()
112-
project_total_code_lines = openhub_soup.find('total_code_lines').get_text()
113-
project_main_language_name = openhub_soup.find('main_language_name').get_text()
114-
project_license = openhub_soup.find('license').find('name').get_text()
115-
project_project_activity_index_description = openhub_soup.find('project_activity_index').find('description').get_text()
148+
# handle exception
116149

117-
map={}
118-
map["project_html_url"] = project_html_url
119-
map["project_twelve_month_contributor_count"] = project_twelve_month_contributor_count
120-
map["project_total_contributor_count"] = project_total_contributor_count
121-
map["project_twelve_month_commit_count"] = project_twelve_month_commit_count
122-
map["project_total_commit_count"] = project_total_commit_count
123-
map["project_total_code_lines"] = project_total_code_lines
124-
map["project_main_language_name"] = project_main_language_name
125-
map["project_license"] = project_license
126-
map["project_project_activity_index_description"] = project_project_activity_index_description
150+
openhub_soup = BeautifulSoup(openhub_resp_content, "html.parser")
151+
try:
152+
project_twelve_month_contributor_count = openhub_soup.find('twelve_month_contributor_count').get_text()
153+
except:
154+
project_twelve_month_contributor_count = None
155+
try:
156+
project_total_contributor_count = openhub_soup.find('total_contributor_count').get_text()
157+
except:
158+
project_total_contributor_count = None
159+
160+
try:
161+
project_twelve_month_commit_count = openhub_soup.find('twelve_month_commit_count').get_text()
162+
except:
163+
project_twelve_month_commit_count = None
164+
165+
try:
166+
project_total_commit_count = openhub_soup.find('total_commit_count').get_text()
167+
except:
168+
project_total_commit_count = None
169+
try:
170+
project_total_code_lines = openhub_soup.find('total_code_lines').get_text()
171+
except:
172+
project_total_code_lines = None
173+
try:
174+
project_main_language_name = openhub_soup.find('main_language_name').get_text()
175+
except:
176+
project_main_language_name = None
177+
try:
178+
project_license = openhub_soup.find('license').find('name').get_text()
179+
except:
180+
project_license = None
181+
try:
182+
project_project_activity_index_description = openhub_soup.find('project_activity_index').find('description').get_text()
183+
except:
184+
project_project_activity_index_description = None
185+
186+
map["project_html_url"] = project_html_url
187+
map["project_twelve_month_contributor_count"] = project_twelve_month_contributor_count
188+
if project_twelve_month_contributor_count >= 2:
189+
map["project_twelve_month_contributor_count_filter"] = "√"
190+
else:
191+
map["project_twelve_month_contributor_count_filter"] = "×"
192+
193+
map["project_total_contributor_count"] = project_total_contributor_count
194+
if project_total_contributor_count >= 3:
195+
map["project_total_contributor_count_filter"] = "√"
196+
else:
197+
map["project_total_contributor_count_filter"] = "×"
198+
199+
map["project_twelve_month_commit_count"] = project_twelve_month_commit_count
200+
if project_twelve_month_commit_count >= 50:
201+
map["project_twelve_month_commit_count_filter"] = "√"
202+
else:
203+
map["project_twelve_month_commit_count_filter"] = "×"
204+
205+
map["project_total_commit_count"] = project_total_commit_count
206+
if project_total_commit_count >= 1000:
207+
map["project_total_commit_count_filter"] = "√"
208+
else:
209+
map["project_total_commit_count_filter"] = "×"
210+
211+
map["project_total_code_lines"] = project_total_code_lines
212+
map["project_main_language_name"] = project_main_language_name
213+
map["project_license"] = project_license
214+
map["project_project_activity_index_description"] = project_project_activity_index_description
215+
216+
print json.dumps({"result": map})
127217

128218
return json.dumps({"result": map})
129219

‎query.pyc

901 Bytes
Binary file not shown.

‎templates/base.html

+42-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,50 @@
2828
</nav>
2929
<h3 class="text-muted">Quick Assessment</h3>
3030
</div>
31-
</div>
31+
</div>
32+
<br>
33+
<div class="container">
34+
<div class="row">
35+
<div class="col-sm-12">
36+
<p class="text-muted">
37+
The <b>objective</b> of the quick assessment tool is to help the OSSpal admin team to efficiently evaluate and identify high quality FOSS projects based on quantifiable hard criteria. We evaluated the contributed projects using the quick assessment tool on a periodical basis, and then perform a team review on the results. After careful review and thorough consideration, we finally post the high quality FOSS projects that can meet our rigorous screening standard on OSSpal.
38+
</p>
39+
<p class="text-muted">
40+
The ideal <b>use case</b> for the quick assessment tool is as the following. When a user type the project name into the search bar, after a few seconds, a detailed page will pop up, showing key quantifiable information of the project acquired from Open Hub and GitHub, such as number of project contributors, number of commits, lines of code, and project activity.
41+
</p>
42+
</div>
43+
</div>
44+
</div>
3245

3346
{% block content %}
3447
{% endblock %}
48+
49+
<br>
50+
51+
<div class="container">
52+
<div class="row">
53+
<div class="col-sm-12 ">
54+
55+
<p class="text-muted"> The most updated hard <b> criteria </b> we used to screen FOSS projects for inclusion on OSSpal are listed below. Please note that the hard criteria will also be updated on a regular basis. </p>
56+
57+
<div class="row">
58+
<div class="col-sm-6 col-sm-offset-3">
59+
<p class="text-muted" text-align="center"> Open Hub Metrics with Optimal Thresholds (as of January 2017): </p>
60+
<p class="text-muted" text-align="center"> # of 12 Month Contributors ≥ 2 </p>
61+
<p class="text-muted" text-align="center"> # of Total Contributors ≥ 3 </p>
62+
<p class="text-muted" text-align="center"> # of 12 Month Commits ≥ 50 </p>
63+
<p class="text-muted" text-align="center"> # of Total Commits ≥ 1000 </p>
64+
65+
<p class="text-muted" text-align="center"> GitHub Metrics with Optimal Thresholds (as of January 2017): </p>
66+
<p class="text-muted" text-align="center"> # of Starts ≥ 100 </p>
67+
<p class="text-muted" text-align="center"> # of Forks ≥ 100 </p>
68+
<p class="text-muted" text-align="center"> # of Open Issues ≥ 5 </p>
69+
<p class="text-muted" text-align="center"> # of Subscribers ≥ 50 </p>
70+
</div>
71+
</div>
72+
73+
</div>
74+
</div>
75+
</div>
3576
</body>
3677
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.