API: Projects - more info in returning JSON
This commit is contained in:
parent
d540fc013c
commit
d86404c3ae
2 changed files with 19 additions and 6 deletions
|
@ -1,6 +1,8 @@
|
||||||
__author__ = 'sagi'
|
__author__ = 'sagi'
|
||||||
import requests
|
import requests
|
||||||
from GithubAPI.GithubAPI import GitHubAPI_Keys
|
from GithubAPI.GithubAPI import GitHubAPI_Keys
|
||||||
|
from models.Task import Task
|
||||||
|
from google.appengine.ext import db
|
||||||
|
|
||||||
githubKeys = GitHubAPI_Keys()
|
githubKeys = GitHubAPI_Keys()
|
||||||
|
|
||||||
|
@ -29,13 +31,15 @@ def get_repo_weekly_commits(repo_url):
|
||||||
except:
|
except:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def make_macro(stats, info):
|
def make_macro(stats, info, project_id):
|
||||||
macro = {'labels': [], 'data': [[0]]}
|
macro = {'labels': [], 'data': [[0]]}
|
||||||
macro['labels'].append('Commits')
|
macro['labels'].append('Commits')
|
||||||
macro['labels'].append('Open Issues')
|
macro['labels'].append('Open Issues')
|
||||||
|
macro['labels'].append('Unfinished Tasks')
|
||||||
for stat in stats:
|
for stat in stats:
|
||||||
macro['data'][0][0] += stat['total']
|
macro['data'][0][0] += stat['total']
|
||||||
macro['data'][0].append(info['open_issues'])
|
macro['data'][0].append(info['open_issues'])
|
||||||
|
macro['data'][0].append(get_unfinished_tasks_number(project_id))
|
||||||
|
|
||||||
return macro
|
return macro
|
||||||
|
|
||||||
|
@ -56,16 +60,21 @@ def get_issue_num(issues, user):
|
||||||
numOfIssues += 1
|
numOfIssues += 1
|
||||||
return numOfIssues
|
return numOfIssues
|
||||||
|
|
||||||
def get_github_data(repo_url):
|
def get_github_data(repo_url, project_id):
|
||||||
project_info = {'stats': {}}
|
project_info = {'stats': {}}
|
||||||
github_stats = get_repo_stats(repo_url) #first Call
|
github_stats = get_repo_stats(repo_url) #first Call
|
||||||
project_info['info'] = get_repo_general_info(repo_url)
|
project_info['info'] = get_repo_general_info(repo_url)
|
||||||
issues = get_repo_issues(repo_url)
|
issues = get_repo_issues(repo_url)
|
||||||
weekly_commits = get_repo_weekly_commits(repo_url)
|
weekly_commits = [get_repo_weekly_commits(repo_url)]
|
||||||
github_stats = get_repo_stats(repo_url) #Second Call
|
github_stats = get_repo_stats(repo_url) #Second Call
|
||||||
project_info['stats']['macro'] = make_macro(github_stats, project_info['info'])
|
project_info['stats']['macro'] = make_macro(github_stats, project_info['info'], project_id)
|
||||||
project_info['stats']['micro'] = make_micro(github_stats, issues)
|
project_info['stats']['micro'] = make_micro(github_stats, issues)
|
||||||
project_info['stats']['weekly_commits'] = weekly_commits
|
project_info['stats']['weekly_commits'] = weekly_commits
|
||||||
project_info['issues'] = issues
|
project_info['issues'] = issues
|
||||||
|
|
||||||
return project_info
|
return project_info
|
||||||
|
|
||||||
|
|
||||||
|
def get_unfinished_tasks_number(project_id):
|
||||||
|
# query = Task.all().filter("isPersonal =", False, "")
|
||||||
|
return 7
|
|
@ -2,6 +2,7 @@ import json
|
||||||
|
|
||||||
__author__ = 'Aran'
|
__author__ = 'Aran'
|
||||||
from google.appengine.ext import db
|
from google.appengine.ext import db
|
||||||
|
from models.User import User
|
||||||
|
|
||||||
class Project(db.Model):
|
class Project(db.Model):
|
||||||
projectName = db.StringProperty(required=True)
|
projectName = db.StringProperty(required=True)
|
||||||
|
@ -14,14 +15,17 @@ class Project(db.Model):
|
||||||
info = db.TextProperty(required=False, default="{}")
|
info = db.TextProperty(required=False, default="{}")
|
||||||
|
|
||||||
def to_JSON(self):
|
def to_JSON(self):
|
||||||
|
members = []
|
||||||
|
for id in self.membersId:
|
||||||
|
members.append(dict(json.loads(User.get_by_id(int(id)).to_JSON())))
|
||||||
data = {'projectName' : self.projectName,
|
data = {'projectName' : self.projectName,
|
||||||
'courseId' : self.courseId,
|
'courseId' : self.courseId,
|
||||||
'master_id' : self.master_id,
|
'master_id' : self.master_id,
|
||||||
'grade' : self.grade,
|
'grade' : self.grade,
|
||||||
'logo_url' : self.logo_url,
|
'logo_url' : self.logo_url,
|
||||||
'gitRepository' : self.gitRepository,
|
'gitRepository' : self.gitRepository,
|
||||||
'membersId' : self.membersId,
|
'members': members,
|
||||||
'info': json.loads(self.info),
|
'info': json.loads(self.info),
|
||||||
'id' : self.key().id()
|
'id': self.key().id()
|
||||||
}
|
}
|
||||||
return json.dumps(data)
|
return json.dumps(data)
|
||||||
|
|
Loading…
Reference in a new issue