From d86404c3ae46b6fca7151ab563a788ad7cf09dd6 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Mon, 29 Jun 2015 21:48:28 +0300 Subject: [PATCH] API: Projects - more info in returning JSON --- SE_API/GitHub_API_Connector.py | 17 +++++++++++++---- models/Project.py | 8 ++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/SE_API/GitHub_API_Connector.py b/SE_API/GitHub_API_Connector.py index 66e7479..21f3e26 100644 --- a/SE_API/GitHub_API_Connector.py +++ b/SE_API/GitHub_API_Connector.py @@ -1,6 +1,8 @@ __author__ = 'sagi' import requests from GithubAPI.GithubAPI import GitHubAPI_Keys +from models.Task import Task +from google.appengine.ext import db githubKeys = GitHubAPI_Keys() @@ -29,13 +31,15 @@ def get_repo_weekly_commits(repo_url): except: return [] -def make_macro(stats, info): +def make_macro(stats, info, project_id): macro = {'labels': [], 'data': [[0]]} macro['labels'].append('Commits') macro['labels'].append('Open Issues') + macro['labels'].append('Unfinished Tasks') for stat in stats: macro['data'][0][0] += stat['total'] macro['data'][0].append(info['open_issues']) + macro['data'][0].append(get_unfinished_tasks_number(project_id)) return macro @@ -56,16 +60,21 @@ def get_issue_num(issues, user): numOfIssues += 1 return numOfIssues -def get_github_data(repo_url): +def get_github_data(repo_url, project_id): project_info = {'stats': {}} github_stats = get_repo_stats(repo_url) #first Call project_info['info'] = get_repo_general_info(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 - 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']['weekly_commits'] = weekly_commits project_info['issues'] = issues return project_info + + +def get_unfinished_tasks_number(project_id): + # query = Task.all().filter("isPersonal =", False, "") + return 7 \ No newline at end of file diff --git a/models/Project.py b/models/Project.py index a9de13f..fa1ec70 100644 --- a/models/Project.py +++ b/models/Project.py @@ -2,6 +2,7 @@ import json __author__ = 'Aran' from google.appengine.ext import db +from models.User import User class Project(db.Model): projectName = db.StringProperty(required=True) @@ -14,14 +15,17 @@ class Project(db.Model): info = db.TextProperty(required=False, default="{}") 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, 'courseId' : self.courseId, 'master_id' : self.master_id, 'grade' : self.grade, 'logo_url' : self.logo_url, 'gitRepository' : self.gitRepository, - 'membersId' : self.membersId, + 'members': members, 'info': json.loads(self.info), - 'id' : self.key().id() + 'id': self.key().id() } return json.dumps(data)