Skip to content

Commit baf52cf

Browse files
authored
Merge pull request #313 from parthsharma2/dev
dev: Added & updated augur_db tests & refactor metric implementations
2 parents c4a9116 + c76d9a9 commit baf52cf

File tree

4 files changed

+246
-47
lines changed

4 files changed

+246
-47
lines changed

augur/datasources/augur_db/augur_db.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def code_changes(self, repo_group_id, repo_id=None, period='day', begin_date=Non
110110
FROM commits
111111
WHERE repo_id = :repo_id
112112
AND cmt_committer_date BETWEEN :begin_date AND :end_date
113-
GROUP BY commit_date
114-
ORDER BY commit_date
113+
GROUP BY date
114+
ORDER BY date
115115
""")
116116

117117
results = pd.read_sql(code_changes_SQL, self.db, params={'repo_id': repo_id, 'period': period,
@@ -529,15 +529,15 @@ def code_changes_lines(self, repo_group_id, repo_id=None, period='day', begin_da
529529
if not repo_id:
530530
code_changes_lines_SQL = s.sql.text("""
531531
SELECT
532-
date_trunc(:period, cmt_author_date::DATE) as commit_date,
532+
date_trunc(:period, cmt_author_date::DATE) as date,
533533
repo_id,
534534
SUM(cmt_added) as added,
535535
SUM(cmt_removed) as removed
536536
FROM commits
537537
WHERE repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id)
538538
AND cmt_author_date BETWEEN :begin_date AND :end_date
539-
GROUP BY commit_date, repo_id
540-
ORDER BY repo_id, commit_date
539+
GROUP BY date, repo_id
540+
ORDER BY repo_id, date
541541
""")
542542

543543
results = pd.read_sql(code_changes_lines_SQL, self.db, params={'repo_group_id': repo_group_id, 'period': period,
@@ -548,14 +548,14 @@ def code_changes_lines(self, repo_group_id, repo_id=None, period='day', begin_da
548548
else:
549549
code_changes_lines_SQL = s.sql.text("""
550550
SELECT
551-
date_trunc(:period, cmt_author_date::DATE) as commit_date,
551+
date_trunc(:period, cmt_author_date::DATE) as date,
552552
SUM(cmt_added) AS added,
553553
SUM(cmt_removed) as removed
554554
FROM commits
555555
WHERE repo_id = :repo_id
556556
AND cmt_author_date BETWEEN :begin_date AND :end_date
557-
GROUP BY commit_date
558-
ORDER BY commit_date;
557+
GROUP BY date
558+
ORDER BY date;
559559
""")
560560

561561
results = pd.read_sql(code_changes_lines_SQL, self.db, params={'repo_id': repo_id, 'period': period,
@@ -583,14 +583,14 @@ def issues_new(self, repo_group_id, repo_id=None, period='day', begin_date=None,
583583
if not repo_id:
584584
issues_new_SQL = s.sql.text("""
585585
SELECT
586-
date_trunc(:period, created_at::DATE) as issue_date,
586+
date_trunc(:period, created_at::DATE) as date,
587587
repo_id,
588588
COUNT(issue_id) as issues
589589
FROM issues
590590
WHERE repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id)
591591
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')
592-
GROUP BY issue_date, repo_id
593-
ORDER BY repo_id, issue_date
592+
GROUP BY date, repo_id
593+
ORDER BY repo_id, date
594594
""")
595595

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

601601
else:
602602
issues_new_SQL = s.sql.text("""
603-
SELECT date_trunc(:period, created_at::DATE) as issue_date, COUNT(issue_id) as issues
603+
SELECT date_trunc(:period, created_at::DATE) as date, COUNT(issue_id) as issues
604604
FROM issues
605605
WHERE repo_id = :repo_id
606606
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')
607-
GROUP BY issue_date
608-
ORDER BY issue_date;
607+
GROUP BY date
608+
ORDER BY date;
609609
""")
610610

611611
results = pd.read_sql(issues_new_SQL, self.db, params={'repo_id': repo_id, 'period': period,

augur/datasources/augur_db/routes.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,17 @@ def get_repo(owner, repo):
136136
@apiSuccessExample {json} Success-Response:
137137
[
138138
{
139-
"commit_date": "2018-01-01T00:00:00.000Z",
139+
"date": "2018-01-01T00:00:00.000Z",
140140
"repo_id": 1,
141141
"commit_count": 5140
142142
},
143143
{
144-
"commit_date": "2019-01-01T00:00:00.000Z",
144+
"date": "2019-01-01T00:00:00.000Z",
145145
"repo_id": 1,
146146
"commit_count": 711
147147
},
148148
{
149-
"commit_date": "2015-01-01T00:00:00.000Z",
149+
"date": "2015-01-01T00:00:00.000Z",
150150
"repo_id": 25001,
151151
"commit_count": 1071
152152
}
@@ -168,19 +168,19 @@ def get_repo(owner, repo):
168168
@apiSuccessExample {json} Success-Response:
169169
[
170170
{
171-
"commit_date": "2018-01-01T00:00:00.000Z",
171+
"date": "2018-01-01T00:00:00.000Z",
172172
"commit_count": 2287
173173
},
174174
{
175-
"commit_date": "2018-02-01T00:00:00.000Z",
175+
"date": "2018-02-01T00:00:00.000Z",
176176
"commit_count": 1939
177177
},
178178
{
179-
"commit_date": "2018-03-01T00:00:00.000Z",
179+
"date": "2018-03-01T00:00:00.000Z",
180180
"commit_count": 1979
181181
},
182182
{
183-
"commit_date": "2018-04-01T00:00:00.000Z",
183+
"date": "2018-04-01T00:00:00.000Z",
184184
"commit_count": 2159
185185
}
186186
]
@@ -200,25 +200,25 @@ def get_repo(owner, repo):
200200
@apiSuccessExample {json} Success-Response:
201201
[
202202
{
203-
"commit_date": "2018-01-01T00:00:00.000Z",
203+
"date": "2018-01-01T00:00:00.000Z",
204204
"repo_id": 1,
205205
"added": 640098,
206206
"removed": 694608
207207
},
208208
{
209-
"commit_date": "2019-01-01T00:00:00.000Z",
209+
"date": "2019-01-01T00:00:00.000Z",
210210
"repo_id": 1,
211211
"added": 56549,
212212
"removed": 48962
213213
},
214214
{
215-
"commit_date": "2014-01-01T00:00:00.000Z",
215+
"date": "2014-01-01T00:00:00.000Z",
216216
"repo_id": 25001,
217217
"added": 19,
218218
"removed": 1
219219
},
220220
{
221-
"commit_date": "2015-01-01T00:00:00.000Z",
221+
"date": "2015-01-01T00:00:00.000Z",
222222
"repo_id": 25001,
223223
"added": 429535,
224224
"removed": 204015
@@ -241,22 +241,22 @@ def get_repo(owner, repo):
241241
@apiSuccessExample {json} Success-Response:
242242
[
243243
{
244-
"commit_date": "2014-01-01T00:00:00.000Z",
244+
"date": "2014-01-01T00:00:00.000Z",
245245
"added": 19,
246246
"removed": 1
247247
},
248248
{
249-
"commit_date": "2015-01-01T00:00:00.000Z",
249+
"date": "2015-01-01T00:00:00.000Z",
250250
"added": 429535,
251251
"removed": 204015
252252
},
253253
{
254-
"commit_date": "2016-01-01T00:00:00.000Z",
254+
"date": "2016-01-01T00:00:00.000Z",
255255
"added": 2739765,
256256
"removed": 944568
257257
},
258258
{
259-
"commit_date": "2017-01-01T00:00:00.000Z",
259+
"date": "2017-01-01T00:00:00.000Z",
260260
"added": 3945001,
261261
"removed": 1011396
262262
}
@@ -277,12 +277,12 @@ def get_repo(owner, repo):
277277
@apiSuccessExample {json} Success-Response:
278278
[
279279
{
280-
"issue_date": "2019-05-01T00:00:00.000Z",
280+
"date": "2019-05-01T00:00:00.000Z",
281281
"repo_id": 1,
282282
"issues": 3
283283
},
284284
{
285-
"issue_date": "2019-05-01T00:00:00.000Z",
285+
"date": "2019-05-01T00:00:00.000Z",
286286
"repo_id": 25001,
287287
"issues": 1
288288
}
@@ -304,11 +304,11 @@ def get_repo(owner, repo):
304304
@apiSuccessExample {json} Success-Response:
305305
[
306306
{
307-
"issue_date": "2019-05-01T00:00:00.000Z",
307+
"date": "2019-05-01T00:00:00.000Z",
308308
"issues": 1
309309
},
310310
{
311-
"issue_date": "2019-06-01T00:00:00.000Z",
311+
"date": "2019-06-01T00:00:00.000Z",
312312
"issues": 31
313313
}
314314
]

augur/datasources/augur_db/test_augur_db.py

+88-9
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,73 @@ def test_code_changes_lines(augur_db):
5151

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

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

5959
#begin_date & end_date
6060
assert augur_db.issues_new(24, 21979, period='week', begin_date='2017',
6161
end_date='2017-05').iloc[1]['issues'] == 4
6262
assert augur_db.issues_new(24, period='month', begin_date='2017-05',
63-
end_date='2018').iloc[2]['issues'] == 7
63+
end_date='2018').iloc[2]['issues'] == 2
64+
65+
def test_issues_active(augur_db):
66+
# repo
67+
assert augur_db.issues_active(22, 21326, period='year').iloc[0]['issues'] == 98
68+
69+
# repo_group
70+
assert augur_db.issues_active(22, period='year').iloc[5]['issues'] == 20
71+
72+
# begin_date & end_date
73+
assert augur_db.issues_active(22, 21326, period='month', begin_date='2015',
74+
end_date='2015-09').iloc[0]['issues'] == 32
75+
76+
assert augur_db.issues_active(22, period='week', begin_date='2015-01',
77+
end_date='2015-08-05') .iloc[0]['issues'] == 32
78+
79+
def test_issues_closed(augur_db):
80+
# repo
81+
assert augur_db.issues_closed(24, 21681, period='year').iloc[0]['issues'] == 189
82+
83+
#repo_group
84+
assert augur_db.issues_closed(24, period='year').iloc[1]['issues'] == 97
85+
86+
# begin_date & end_date
87+
assert augur_db.issues_closed(24, 21681, period='week', begin_date='2012',
88+
end_date='2012-07').iloc[0]['issues'] == 10
89+
90+
assert augur_db.issues_closed(24, period='month', begin_date='2012-05',
91+
end_date='2012-08-15').iloc[0]['issues'] == 50
92+
93+
def test_issue_duration(augur_db):
94+
# repo
95+
assert augur_db.issue_duration(24, 21681).iloc[0]['duration'] == '0 days 01:06:31.000000000'
96+
97+
# repo_group
98+
assert augur_db.issue_duration(24).iloc[3]['duration'] == '5 days 05:18:21.000000000'
99+
100+
def test_issue_participants(augur_db):
101+
# repo
102+
assert augur_db.issue_participants(23, 21403).iloc[0]['participants'] == 1
103+
104+
# repo_group
105+
assert augur_db.issue_participants(22).iloc[4]['participants'] == 4
106+
107+
def test_issue_throughput(augur_db):
108+
# repo
109+
assert augur_db.issue_throughput(20, 21009).iloc[0]['throughput'] == 0.263158
110+
111+
# repo_group
112+
assert augur_db.issue_throughput(24).iloc[0]['throughput'] == 0.861896
64113

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

69118
#repo_group_id
70-
assert augur_db.issue_backlog(21).iloc[2]['issue_backlog'] == 3
71-
119+
assert augur_db.issue_backlog(21).iloc[2]['issue_backlog'] == 20
120+
72121

73122
def test_issues_first_time_closed(augur_db):
74123

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

200+
def test_open_issues_count(augur_db):
201+
# repo
202+
assert augur_db.open_issues_count(22, 21326).iloc[0]['open_count'] == 1
203+
204+
# repo_group
205+
assert augur_db.open_issues_count(23).iloc[1]['open_count'] == 4
206+
207+
def test_closed_issues_count(augur_db):
208+
# repo
209+
assert augur_db.closed_issues_count(24, 21684).iloc[0]['closed_count'] == 3
210+
211+
# repo_group
212+
assert augur_db.closed_issues_count(20).iloc[0]['closed_count'] == 1
213+
151214
def test_issues_open_age(augur_db):
152215
#repo group
153216
assert augur_db.issues_open_age(24).iloc[0]['datedifference'] > 100
154-
# repo
217+
# repo
155218
assert augur_db.issues_open_age(20,21000).iloc[0]['datedifference'] > 100
156219

157220
def test_issues_closed_resolution_duration(augur_db):
158-
# repo group
221+
# repo group
159222
assert augur_db.issues_closed_resolution_duration(24).iloc[0]['diffdate'] >= 0
160-
# repo
223+
# repo
161224
assert augur_db.issues_closed_resolution_duration(24,21682).iloc[0]['diffdate'] >= 0
162225

163226
def test_get_repo(augur_db):
164-
assert augur_db.get_repo_by_name('Comcast','zucchini').iloc[0].repo_id == 21116
227+
assert augur_db.get_repo_by_name('Comcast','zucchini').iloc[0].repo_id == 21116
228+
229+
def test_cii_best_practices_badge(augur_db):
230+
# repo
231+
assert augur_db.cii_best_practices_badge(21, 21252).iloc[0]['badge_level'] == 'in_progress'
232+
233+
# repo_group
234+
assert augur_db.cii_best_practices_badge(21).iloc[0]['badge_level'] == 'passing'
235+
236+
def test_languages(augur_db):
237+
# TODO
238+
pass
239+
240+
def test_license_declared(augur_db):
241+
assert augur_db.license_declared(21, 21252).iloc[0]['license'] == 'Apache-2.0'
242+
243+
assert augur_db.license_declared(21).iloc[0]['license'] == 'Apache-2.0'

0 commit comments

Comments
 (0)