Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stable demo: Added & updated augur_db tests & refactor metric implementations #312

Merged
merged 5 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions augur/datasources/augur_db/augur_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def code_changes(self, repo_group_id, repo_id=None, period='day', begin_date=Non
FROM commits
WHERE repo_id = :repo_id
AND cmt_committer_date BETWEEN :begin_date AND :end_date
GROUP BY commit_date
ORDER BY commit_date
GROUP BY date
ORDER BY date
""")

results = pd.read_sql(code_changes_SQL, self.db, params={'repo_id': repo_id, 'period': period,
Expand Down Expand Up @@ -625,15 +625,15 @@ def code_changes_lines(self, repo_group_id, repo_id=None, period='day', begin_da
if not repo_id:
code_changes_lines_SQL = s.sql.text("""
SELECT
date_trunc(:period, cmt_author_date::DATE) as commit_date,
date_trunc(:period, cmt_author_date::DATE) as date,
repo_id,
SUM(cmt_added) as added,
SUM(cmt_removed) as removed
FROM commits
WHERE repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id)
AND cmt_author_date BETWEEN :begin_date AND :end_date
GROUP BY commit_date, repo_id
ORDER BY repo_id, commit_date
GROUP BY date, repo_id
ORDER BY repo_id, date
""")

results = pd.read_sql(code_changes_lines_SQL, self.db, params={'repo_group_id': repo_group_id, 'period': period,
Expand All @@ -644,14 +644,14 @@ def code_changes_lines(self, repo_group_id, repo_id=None, period='day', begin_da
else:
code_changes_lines_SQL = s.sql.text("""
SELECT
date_trunc(:period, cmt_author_date::DATE) as commit_date,
date_trunc(:period, cmt_author_date::DATE) as date,
SUM(cmt_added) AS added,
SUM(cmt_removed) as removed
FROM commits
WHERE repo_id = :repo_id
AND cmt_author_date BETWEEN :begin_date AND :end_date
GROUP BY commit_date
ORDER BY commit_date;
GROUP BY date
ORDER BY date;
""")

results = pd.read_sql(code_changes_lines_SQL, self.db, params={'repo_id': repo_id, 'period': period,
Expand Down Expand Up @@ -679,14 +679,14 @@ def issues_new(self, repo_group_id, repo_id=None, period='day', begin_date=None,
if not repo_id:
issues_new_SQL = s.sql.text("""
SELECT
date_trunc(:period, created_at::DATE) as issue_date,
date_trunc(:period, created_at::DATE) as date,
repo_id,
COUNT(issue_id) as issues
FROM issues
WHERE repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id)
AND created_at BETWEEN to_timestamp(:begin_date, 'YYYY-MM-DD HH24:MI:SS') AND to_timestamp(:end_date, 'YYYY-MM-DD HH24:MI:SS')
GROUP BY issue_date, repo_id
ORDER BY repo_id, issue_date
GROUP BY date, repo_id
ORDER BY repo_id, date
""")

results = pd.read_sql(issues_new_SQL, self.db, params={'repo_group_id': repo_group_id, 'period': period,
Expand All @@ -696,12 +696,12 @@ def issues_new(self, repo_group_id, repo_id=None, period='day', begin_date=None,

else:
issues_new_SQL = s.sql.text("""
SELECT date_trunc(:period, created_at::DATE) as issue_date, COUNT(issue_id) as issues
SELECT date_trunc(:period, created_at::DATE) as date, COUNT(issue_id) as issues
FROM issues
WHERE repo_id = :repo_id
AND created_at BETWEEN to_timestamp(:begin_date, 'YYYY-MM-DD HH24:MI:SS') AND to_timestamp(:end_date, 'YYYY-MM-DD HH24:MI:SS')
GROUP BY issue_date
ORDER BY issue_date;
GROUP BY date
ORDER BY date;
""")

results = pd.read_sql(issues_new_SQL, self.db, params={'repo_id': repo_id, 'period': period,
Expand Down
38 changes: 19 additions & 19 deletions augur/datasources/augur_db/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ def get_repo(owner, repo):
@apiSuccessExample {json} Success-Response:
[
{
"commit_date": "2018-01-01T00:00:00.000Z",
"date": "2018-01-01T00:00:00.000Z",
"repo_id": 1,
"commit_count": 5140
},
{
"commit_date": "2019-01-01T00:00:00.000Z",
"date": "2019-01-01T00:00:00.000Z",
"repo_id": 1,
"commit_count": 711
},
{
"commit_date": "2015-01-01T00:00:00.000Z",
"date": "2015-01-01T00:00:00.000Z",
"repo_id": 25001,
"commit_count": 1071
}
Expand All @@ -170,19 +170,19 @@ def get_repo(owner, repo):
@apiSuccessExample {json} Success-Response:
[
{
"commit_date": "2018-01-01T00:00:00.000Z",
"date": "2018-01-01T00:00:00.000Z",
"commit_count": 2287
},
{
"commit_date": "2018-02-01T00:00:00.000Z",
"date": "2018-02-01T00:00:00.000Z",
"commit_count": 1939
},
{
"commit_date": "2018-03-01T00:00:00.000Z",
"date": "2018-03-01T00:00:00.000Z",
"commit_count": 1979
},
{
"commit_date": "2018-04-01T00:00:00.000Z",
"date": "2018-04-01T00:00:00.000Z",
"commit_count": 2159
}
]
Expand All @@ -202,25 +202,25 @@ def get_repo(owner, repo):
@apiSuccessExample {json} Success-Response:
[
{
"commit_date": "2018-01-01T00:00:00.000Z",
"date": "2018-01-01T00:00:00.000Z",
"repo_id": 1,
"added": 640098,
"removed": 694608
},
{
"commit_date": "2019-01-01T00:00:00.000Z",
"date": "2019-01-01T00:00:00.000Z",
"repo_id": 1,
"added": 56549,
"removed": 48962
},
{
"commit_date": "2014-01-01T00:00:00.000Z",
"date": "2014-01-01T00:00:00.000Z",
"repo_id": 25001,
"added": 19,
"removed": 1
},
{
"commit_date": "2015-01-01T00:00:00.000Z",
"date": "2015-01-01T00:00:00.000Z",
"repo_id": 25001,
"added": 429535,
"removed": 204015
Expand All @@ -243,22 +243,22 @@ def get_repo(owner, repo):
@apiSuccessExample {json} Success-Response:
[
{
"commit_date": "2014-01-01T00:00:00.000Z",
"date": "2014-01-01T00:00:00.000Z",
"added": 19,
"removed": 1
},
{
"commit_date": "2015-01-01T00:00:00.000Z",
"date": "2015-01-01T00:00:00.000Z",
"added": 429535,
"removed": 204015
},
{
"commit_date": "2016-01-01T00:00:00.000Z",
"date": "2016-01-01T00:00:00.000Z",
"added": 2739765,
"removed": 944568
},
{
"commit_date": "2017-01-01T00:00:00.000Z",
"date": "2017-01-01T00:00:00.000Z",
"added": 3945001,
"removed": 1011396
}
Expand All @@ -279,12 +279,12 @@ def get_repo(owner, repo):
@apiSuccessExample {json} Success-Response:
[
{
"issue_date": "2019-05-01T00:00:00.000Z",
"date": "2019-05-01T00:00:00.000Z",
"repo_id": 1,
"issues": 3
},
{
"issue_date": "2019-05-01T00:00:00.000Z",
"date": "2019-05-01T00:00:00.000Z",
"repo_id": 25001,
"issues": 1
}
Expand All @@ -306,11 +306,11 @@ def get_repo(owner, repo):
@apiSuccessExample {json} Success-Response:
[
{
"issue_date": "2019-05-01T00:00:00.000Z",
"date": "2019-05-01T00:00:00.000Z",
"issues": 1
},
{
"issue_date": "2019-06-01T00:00:00.000Z",
"date": "2019-06-01T00:00:00.000Z",
"issues": 31
}
]
Expand Down
95 changes: 87 additions & 8 deletions augur/datasources/augur_db/test_augur_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,73 @@ def test_code_changes_lines(augur_db):

def test_issues_new(augur_db):
#repo_id
assert augur_db.issues_new(23, 21430, period='year').iloc[0]['issues'] == 2
assert augur_db.issues_new(23, 21403, period='year').iloc[0]['issues'] == 1

#repo_group_id
assert augur_db.issues_new(23, period='year').iloc[0]['issues'] == 2
assert augur_db.issues_new(23, period='year').iloc[1]['issues'] == 1

#begin_date & end_date
assert augur_db.issues_new(24, 21979, period='week', begin_date='2017',
end_date='2017-05').iloc[1]['issues'] == 4
assert augur_db.issues_new(24, period='month', begin_date='2017-05',
end_date='2018').iloc[2]['issues'] == 7
end_date='2018').iloc[2]['issues'] == 2

def test_issues_active(augur_db):
# repo
assert augur_db.issues_active(22, 21326, period='year').iloc[0]['issues'] == 98

# repo_group
assert augur_db.issues_active(22, period='year').iloc[5]['issues'] == 20

# begin_date & end_date
assert augur_db.issues_active(22, 21326, period='month', begin_date='2015',
end_date='2015-09').iloc[0]['issues'] == 32

assert augur_db.issues_active(22, period='week', begin_date='2015-01',
end_date='2015-08-05') .iloc[0]['issues'] == 32

def test_issues_closed(augur_db):
# repo
assert augur_db.issues_closed(24, 21681, period='year').iloc[0]['issues'] == 189

#repo_group
assert augur_db.issues_closed(24, period='year').iloc[1]['issues'] == 97

# begin_date & end_date
assert augur_db.issues_closed(24, 21681, period='week', begin_date='2012',
end_date='2012-07').iloc[0]['issues'] == 10

assert augur_db.issues_closed(24, period='month', begin_date='2012-05',
end_date='2012-08-15').iloc[0]['issues'] == 50

def test_issue_duration(augur_db):
# repo
assert augur_db.issue_duration(24, 21681).iloc[0]['duration'] == '0 days 01:06:31.000000000'

# repo_group
assert augur_db.issue_duration(24).iloc[3]['duration'] == '5 days 05:18:21.000000000'

def test_issue_participants(augur_db):
# repo
assert augur_db.issue_participants(23, 21403).iloc[0]['participants'] == 1

# repo_group
assert augur_db.issue_participants(22).iloc[4]['participants'] == 4

def test_issue_throughput(augur_db):
# repo
assert augur_db.issue_throughput(20, 21009).iloc[0]['throughput'] == 0.263158

# repo_group
assert augur_db.issue_throughput(24).iloc[0]['throughput'] == 0.861896

def test_issue_backlog(augur_db):
#repo_id
assert augur_db.issue_backlog(21, 21166).iloc[0]['issue_backlog'] == 4

#repo_group_id
assert augur_db.issue_backlog(21).iloc[2]['issue_backlog'] == 3
assert augur_db.issue_backlog(21).iloc[2]['issue_backlog'] == 20


def test_issues_first_time_closed(augur_db):

Expand Down Expand Up @@ -148,20 +197,50 @@ def test_contributors_new(augur_db):
assert augur_db.contributors_new(24, repo_id=21524, period='year', begin_date='2019-1-1 00:00:00',
end_date='2019-12-31 23:59:59').isin([pd.Timestamp('2019-01-01 00:00:00', tz='UTC')]).any().any()

def test_open_issues_count(augur_db):
# repo
assert augur_db.open_issues_count(22, 21326).iloc[0]['open_count'] == 1

# repo_group
assert augur_db.open_issues_count(23).iloc[1]['open_count'] == 4

def test_closed_issues_count(augur_db):
# repo
assert augur_db.closed_issues_count(24, 21684).iloc[0]['closed_count'] == 3

# repo_group
assert augur_db.closed_issues_count(20).iloc[0]['closed_count'] == 1

def test_issues_open_age(augur_db):
#repo group
assert augur_db.issues_open_age(24).iloc[0]['open_date'] > 0
# repo
assert augur_db.issues_open_age(20,21000).iloc[0]['open_date'] > 0

def test_issues_closed_resolution_duration(augur_db):
# repo group
# repo group
assert augur_db.issues_closed_resolution_duration(24).iloc[0]['diffdate'] >= 0
# repo
# repo
assert augur_db.issues_closed_resolution_duration(24,21682).iloc[0]['diffdate'] >= 0

def test_get_repo(augur_db):
assert augur_db.get_repo('rails','rails').iloc[0].repo_group_id == 20
assert augur_db.get_repo_by_name('Comcast','zucchini').iloc[0].repo_id == 21116

def test_cii_best_practices_badge(augur_db):
# repo
assert augur_db.cii_best_practices_badge(21, 21252).iloc[0]['badge_level'] == 'in_progress'

# repo_group
assert augur_db.cii_best_practices_badge(21).iloc[0]['badge_level'] == 'passing'

def test_languages(augur_db):
# TODO
pass

def test_license_declared(augur_db):
assert augur_db.license_declared(21, 21252).iloc[0]['license'] == 'Apache-2.0'

assert augur_db.license_declared(21).iloc[0]['license'] == 'Apache-2.0'

def test_lines_changed_by_author(augur_db):
assert augur_db.lines_changed_by_author(20).iloc[0].additions > 0
Expand Down
Loading