diff --git a/augur/datasources/augur_db/augur_db.py b/augur/datasources/augur_db/augur_db.py index e96ea6244f..a99b4c3f46 100644 --- a/augur/datasources/augur_db/augur_db.py +++ b/augur/datasources/augur_db/augur_db.py @@ -1405,6 +1405,50 @@ def issues_maintainer_response_duration(self, repo_group_id, repo_id=None, begin return results + ##################################### + ### VALUE ### + ##################################### + + @annotate(tag='stars') + def stars(self, repo_group_id, repo_id=None): + """ + Returns a time series of the stars count + + :param repo_group_id: The repository's repo_group_id + :param repo_id: The repository's repo_id, defaults to None + :return: Time series of stars count + """ + if not repo_id: + stars_SQL = s.sql.text(""" + SELECT + repo_info.repo_id, + repo_name, + repo_info.data_collection_date as date, + stars_count AS stars + FROM repo_info JOIN repo ON repo_info.repo_id = repo.repo_id + WHERE repo_info.repo_id IN + (SELECT repo_id FROM repo + WHERE repo_group_id = :repo_group_id) + ORDER BY repo_info.repo_id, date + """) + + results = pd.read_sql(stars_SQL, self.db, params={'repo_group_id': repo_group_id}) + return results + + else: + stars_SQL = s.sql.text(""" + SELECT + repo_name, + repo_info.data_collection_date as date, + stars_count AS stars + FROM repo_info JOIN repo ON repo_info.repo_id = repo.repo_id + WHERE repo_info.repo_id = :repo_id + ORDER BY date + """) + + results = pd.read_sql(stars_SQL, self.db, params={'repo_id': repo_id}) + return results + ##################################### ### EXPERIMENTAL ### ##################################### diff --git a/augur/datasources/augur_db/routes.py b/augur/datasources/augur_db/routes.py index 2c5cd430de..8e5c9b89d1 100644 --- a/augur/datasources/augur_db/routes.py +++ b/augur/datasources/augur_db/routes.py @@ -1573,6 +1573,69 @@ def get_repos_for_dosocs(): """ server.addRepoMetric(augur_db.license_declared, 'license-declared') + ##################################### + ### VALUE ### + ##################################### + + """ + @api {get} /repo-groups/:repo_group_id/stars Stars (Repo Group) + @apiName stars-repo-group + @apiGroup Value + @apiDescription A time series of stars count. + @apiParam {string} repo_group_id Repository Group ID + @apiSuccessExample {json} Success-Response: + [ + { + "repo_id": 21491, + "repo_name": "commons-io", + "date": "2019-07-03T23:23:36.000Z", + "stars": 600 + }, + { + "repo_id": 21491, + "repo_name": "commons-io", + "date": "2019-07-04T16:36:27.000Z", + "stars": 601 + }, + { + "repo_id": 21524, + "repo_name": "maven", + "date": "2019-07-03T23:21:14.000Z", + "stars": 1730 + }, + { + "repo_id": 21524, + "repo_name": "maven", + "date": "2019-07-04T16:34:04.000Z", + "stars": 1733 + } + ] + """ + server.addRepoGroupMetric(augur_db.stars, 'stars') + + """ + @api {get} /repo-groups/:repo_group_id/repos/:repo_id/stars Stars (Repo) + @apiName stars-repo + @apiGroup Value + @apiDescription A time series of stars count. + @apiParam {string} repo_group_id Repository Group ID. + @apiParam {string} repo_id Repository ID. + @apiSuccessExample {json} Success-Response: + [ + { + "repo_name": "graphiql", + "date": "2019-07-03T23:27:42.000Z", + "stars": 8652 + }, + { + "repo_name": "graphiql", + "date": "2019-07-04T16:40:44.000Z", + "stars": 8653 + } + ] + """ + server.addRepoMetric(augur_db.stars, 'stars') + ##################################### ### EXPERIMENTAL ### #####################################