/
deps.py
80 lines (65 loc) · 2.92 KB
/
deps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#SPDX-License-Identifier: MIT
"""
Metrics that provide data about software dependencies.
"""
import sqlalchemy as s
import pandas as pd
import datetime
from flask import current_app
from augur.api.util import register_metric
@register_metric()
def deps(repo_group_id, repo_id=None, period='day', begin_date=None, end_date=None):
"""
Returns a list of all the dependencies in a project/repo/repo_group.
:param repo_id: The repository's id
:param repo_group_id: The repository's group id
:param period: To set the periodicity to 'day', 'week', 'month' or 'year', defaults to 'day'
:param begin_date: Specifies the begin date, defaults to '1970-1-1 00:00:00'
:param end_date: Specifies the end date, defaults to datetime.now()
:return: DataFrame of persons/period
"""
if not begin_date:
begin_date = '1970-1-1 00:00:01'
if not end_date:
end_date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
if repo_id:
depsSQL = s.sql.text("""
SELECT
augur_data.repo_dependencies.*,
augur_data.repo_groups.repo_group_id
FROM
augur_data.repo_dependencies,
augur_data.repo_groups,
augur_data.repo,
( SELECT MAX ( date_trunc( 'day', augur_data.repo_dependencies.data_collection_date ) ) AS data_collection_date FROM repo_dependencies WHERE repo_id = repo_id ) C
WHERE
repo_dependencies.repo_id = repo.repo_id
AND repo.repo_group_id = repo_groups.repo_group_id
AND date_trunc( 'day', repo_dependencies.data_collection_date ) = C.data_collection_date
AND repo_dependencies.repo_id = :repo_id
""")
with current_app.engine.connect() as conn:
results = pd.read_sql(depsSQL, conn, params={'repo_id': repo_id})
else:
depsSQL = s.sql.text("""
SELECT
augur_data.repo_dependencies.*,
augur_data.repo_groups.repo_group_id
FROM
augur_data.repo_dependencies,
augur_data.repo_groups,
augur_data.repo,
( SELECT MAX ( date_trunc( 'day', augur_data.repo_dependencies.data_collection_date ) ) AS data_collection_date
FROM repo_dependencies, repo, repo_groups
WHERE repo.repo_group_id = repo_groups.repo_group_id and
repo_dependencies.repo_id = repo.repo_id and
repo_groups.repo_group_id = :repo_group_id ) C
WHERE
repo_dependencies.repo_id = repo.repo_id
AND repo.repo_group_id = repo_groups.repo_group_id
AND date_trunc( 'day', repo_dependencies.data_collection_date ) = C.data_collection_date
AND repo.repo_group_id = :repo_group_id
""")
with current_app.engine.connect() as conn:
results = pd.read_sql(depsSQL, conn, params={'repo_group_id': repo_group_id})
return results