Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit 55bc312

Browse files
puneeth-chandaaswinshenoy
authored andcommitted
User Base Points queried (#27)
* initialised django * get user_basepoints * token-deleted * create repo app * token removed * remove migration files * Remove Bootstrap
1 parent 15c4bac commit 55bc312

39 files changed

+434
-71
lines changed

algorithms/__init__.py

Whitespace-only changes.

algorithms/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

algorithms/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AlgorithmsConfig(AppConfig):
5+
name = 'algorithms'

algorithms/migrations/__init__.py

Whitespace-only changes.

algorithms/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

algorithms/repository_rating.py

+25-21
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
import json
77
from datetime import timedelta, datetime
88
from dateutil import parser, relativedelta
9-
from script import userTopicResult
9+
from algorithms.script import userTopicResult
1010

1111

1212
import requests
1313

14+
15+
1416
class RepositoryMetrics:
1517

1618
def __init__(self, name, owner, token):
1719
# initialize class variables
1820
self.name = str(name)
1921
self.owner = str(owner)
22+
self.token = str(token)
2023
self.reponame = self.name + '-' + self.owner
24+
self.headers = {"Authorization": "bearer " + self.token}
2125

2226
# User Profile Details
2327
self.fullName = ''
@@ -83,7 +87,7 @@ def fetchBasicDetails(self):
8387
}
8488
"""
8589

86-
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
90+
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=self.headers)
8791

8892
if request.status_code == 200:
8993
result = request.json()
@@ -123,7 +127,7 @@ def calcActivityScore(self):
123127
}
124128
}
125129
"""
126-
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
130+
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=self.headers)
127131

128132
if request.status_code == 200:
129133
result = request.json()
@@ -186,7 +190,7 @@ def calcActivityScore(self):
186190
}
187191
}
188192
"""
189-
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
193+
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=self.headers)
190194

191195
if request.status_code == 200:
192196
result = request.json()
@@ -228,7 +232,7 @@ def calcActivityScore(self):
228232
self.weeklyContributorNames.remove(user)
229233

230234
self.weeklyContributorsChange = len(clist) - self.weeklyContributorsCount
231-
self.weeklyContributorsCount = len(clist)
235+
self.weeklyContributorsCount = len(clist)
232236

233237
# -- ok
234238

@@ -270,8 +274,8 @@ def calcInclusivityScore(self):
270274
}
271275
}
272276
"""
273-
mergedPR = requests.post('https://api.github.com/graphql', json={'query': merged_prs_query}, headers=headers)
274-
totalPR = requests.post('https://api.github.com/graphql', json={'query': total_prs_query}, headers=headers)
277+
mergedPR = requests.post('https://api.github.com/graphql', json={'query': merged_prs_query}, headers=self.headers)
278+
totalPR = requests.post('https://api.github.com/graphql', json={'query': total_prs_query}, headers=self.headers)
275279

276280
if totalPR.status_code == 200 and mergedPR.status_code ==200:
277281
PRmergedData = mergedPR.json()
@@ -308,7 +312,7 @@ def calcInclusivityScore(self):
308312
}
309313
}
310314
"""
311-
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
315+
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=self.headers)
312316

313317
if request.status_code == 200:
314318
flag = 0
@@ -327,7 +331,7 @@ def calcInclusivityScore(self):
327331
self.firstTimeContributorsThisWeek = self.firstTimeContributorsThisWeek + 1
328332

329333

330-
request = requests.get('https://api.github.com/repos/' + str(self.owner) + '/' + str(self.name) + '/contributors?page=1&per_page=100&access_token='+accessToken)
334+
request = requests.get('https://api.github.com/repos/' + str(self.owner) + '/' + str(self.name) + '/contributors?page=1&per_page=100&access_token='+self.token)
331335

332336
if request.status_code == 200:
333337
result = request.json()
@@ -346,7 +350,7 @@ def calcInclusivityScore(self):
346350

347351
while(flag!=0):
348352
i = i+1
349-
request = requests.get('https://api.github.com/repos/' + str(self.owner) + '/' + str(self.name) + '/contributors?page='+ str(i) +'&per_page=100&access_token='+accessToken)
353+
request = requests.get('https://api.github.com/repos/' + str(self.owner) + '/' + str(self.name) + '/contributors?page='+ str(i) +'&per_page=100&access_token='+self.token)
350354

351355
if request.status_code == 200:
352356

@@ -365,8 +369,8 @@ def calcInclusivityScore(self):
365369

366370
def calcMeritScore(self):
367371

368-
369-
# repo complexity
372+
373+
# repo complexity
370374

371375
query = """
372376
{
@@ -381,21 +385,21 @@ def calcMeritScore(self):
381385
}
382386
}
383387
"""
384-
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
388+
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=self.headers)
385389
if request.status_code == 200:
386390
result = request.json()
387391
clist = list()
388392
for topic in result["data"]["repository"]["repositoryTopics"]["nodes"]:
389393
clist.append(topic["topic"]["name"])
390-
394+
391395
to_delete = set()
392-
fileTopicList = open("topics.txt", "r").read().split('\n')
396+
fileTopicList = open("algorithms/topics.txt", "r").read().split('\n')
393397
for topic in clist:
394398
if topic not in fileTopicList:
395399
to_delete.add(topic)
396400
clist = list(set(clist)-to_delete)
397401

398-
request = requests.get("https://api.github.com/repos/"+str(self.owner) + '/' + str(self.name) + "/contributors?page=1&per_page=5&access_token="+accessToken)
402+
request = requests.get("https://api.github.com/repos/"+str(self.owner) + '/' + str(self.name) + "/contributors?page=1&per_page=5&access_token="+self.token)
399403
if request.status_code == 200:
400404
result = request.json()
401405
usernameList = list()
@@ -413,19 +417,19 @@ def calcMeritScore(self):
413417
def calcRepoScore(self):
414418
self.repoPoints = self.basePoints + self.activityPoints + self.inclusivityPoints + self.meritPoints
415419

420+
"""
421+
RepositoryMetrics.token = "<token>"
416422
417-
418-
accessToken = "03e5d817f468829fd9b3307f55de055461460c1a"
419-
headers = {"Authorization": "bearer "+ accessToken }
420423
421424
username = input("Enter the owner name: ")
422425
reponame = input("Enter the repository name: ")
423-
r=RepositoryMetrics(str(reponame), str(username), accessToken)
426+
r=RepositoryMetrics(str(reponame), str(username), RepositoryMetrics.token)
424427
425428
print()
426429
print("The Base Points: " + str(r.basePoints))
427430
print("The Activity Points: " + str(r.activityPoints))
428431
print("The Inclusivity Points: " + str(r.inclusivityPoints))
429432
print("The Merit Points: " + str(r.meritPoints))
430433
print()
431-
print("The Repository Score is " + str(r.repoPoints))
434+
print("The Repository Score is " + str(r.repoPoints))
435+
"""

algorithms/script.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
import collections
44

5-
accessToken = "03e5d817f468829fd9b3307f55de055461460c1a"
5+
accessToken = "<access-token>"
66
headers = {"Authorization": "bearer "+ accessToken }
77

88
class userTopicResult:
@@ -98,7 +98,7 @@ def getTopicList(self):
9898
contributedTopicList.append(j["topic"]["name"])
9999

100100

101-
fileTopicList = open("topics.txt", "r").read().split('\n')
101+
fileTopicList = open("algorithms/topics.txt", "r").read().split('\n')
102102

103103
topicOccurenceSelf = dict(collections.Counter(x for x in selfTopicList if x))
104104
topicOccurenceContributed = dict(collections.Counter(x for x in contributedTopicList if x))

algorithms/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

algorithms/user_rating.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -462,18 +462,19 @@ def updateSkillsetValue(topicDict):
462462
updateSkillsetValue(self.topicSkill)
463463
self.topicSkill = dict(sorted(self.topicSkill.items(), key=lambda x: x[1], reverse=True))
464464

465-
465+
"""
466466
username = input("Enter the username: ")
467-
user = UserMetrics(username, "03e5d817f468829fd9b3307f55de055461460c1a")
467+
user = UserMetrics(username, "<token-here>")
468468
469469
print()
470470
print("The Base Score is " + str(user.basePoints))
471-
print("The Creation Points is " + str(user.creationPoints))
472-
print("The Activity Points is " + str(user.activityPoints))
473-
print("The Contribution Points is " + str(user.contributionPoints))
471+
print("The Creation Points is " + str(usermetrics.creationPoints))
472+
print("The Activity Points is " + str(usermetrics.activityPoints))
473+
print("The Contribution Points is " + str(usermetrics.contributionPoints))
474474
print()
475-
print("The Topic Interests are \n" + str(user.topicInterestDict))
475+
print("The Topic Interests are \n" + str(usermetrics.topicInterestDict))
476476
print()
477-
print("The Topic Skill are \n" + str(user.topicSkillDict))
477+
print("The Topic Skill are \n" + str(usermetrics.topicSkillDict))
478478
print()
479-
print("The User Points is " + str(user.userPoints))
479+
print("The User Points is " + str(usermetrics.userPoints))
480+
"""

algorithms/views.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

manage.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'portal.settings')
9+
try:
10+
from django.core.management import execute_from_command_line
11+
except ImportError as exc:
12+
raise ImportError(
13+
"Couldn't import Django. Are you sure it's installed and "
14+
"available on your PYTHONPATH environment variable? Did you "
15+
"forget to activate a virtual environment?"
16+
) from exc
17+
execute_from_command_line(sys.argv)
18+
19+
20+
if __name__ == '__main__':
21+
main()

portal/requirements.txt

+9-40
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,10 @@
1-
aniso8601==3.0.2
2-
cachetools==3.0.0
3-
certifi==2018.11.29
1+
certifi==2019.6.16
42
chardet==3.0.4
5-
defusedxml==0.5.0
6-
Django==2.1.4
7-
django-decouple==2.1
8-
django-sass-processor==0.7.2
9-
google-api-core==1.6.0
10-
google-auth==1.6.1
11-
google-cloud-bigquery==1.7.0
12-
google-cloud-core==0.28.1
13-
google-resumable-media==0.3.1
14-
googleapis-common-protos==1.5.5
15-
graphene==2.1.3
16-
graphql-core==2.1
17-
graphql-relay==0.4.5
18-
hamlpy==0.82.2
19-
idna==2.7
20-
libsass==0.16.1
21-
Markdown==3.0.1
22-
oauthlib==2.1.0
23-
Pillow==5.3.0
24-
promise==2.2.1
25-
protobuf==3.6.1
26-
pyasn1==0.4.4
27-
pyasn1-modules==0.2.2
28-
Pygments==2.3.0
29-
PyJWT==1.7.1
30-
python3-openid==3.1.0
31-
pytz==2018.7
32-
pyyaml>=4.2b1
33-
requests==2.20.1
34-
requests-oauthlib==1.0.0
35-
rsa==4.0
36-
ruamel.yaml==0.15.80
37-
Rx==1.6.1
38-
six==1.11.0
39-
social-auth-app-django==3.1.0
40-
social-auth-core==2.0.0
41-
urllib3==1.24.1
3+
Django==2.2.2
4+
idna==2.8
5+
python-dateutil==2.8.0
6+
pytz==2019.1
7+
requests==2.22.0
8+
six==1.12.0
9+
sqlparse==0.3.0
10+
urllib3==1.25.3

0 commit comments

Comments
 (0)