In [1]:
import augur
from augur.localcsv import LocalCSV
import json
import re
from dateutil.parser import parse
import pandas as pd
import github
import numpy as np
import datetime
import requests
from augur import logger
app = augur.Application('../augur.config.json')

github = app.githubapi()

In [7]:
def lines_of_code_changed(self, owner, repo=None): 
    """
    Timeseries of the count of lines added, deleted, and the net change each week

    :param owner: The name of the project owner
    :param repo: The name of the repo
    :return: DataFrame with the associated lines changed information/week
    """
    # get the data we need from the GitHub API
    # see <project_root>/augur/githubapi.py for examples using the GraphQL API
    # get the data we need from the GitHub API
    # see <project_root>/augur/githubapi.py for examples using the GraphQL API
    url = "https://api.github.com/repos/{}/{}/stats/code_frequency".format(owner, repo)
    json = requests.get(url, auth=('user', self.GITHUB_API_KEY)).json()
    # get our data into a dataframe
    df = pd.DataFrame(json, columns=['date', 'additions', 'deletions'])
    # all timeseries metrics need a 'date' column
    df['date'] = pd.to_datetime(df['date'], unit='s', infer_datetime_format=True)
    # normalize our data and create useful aggregates
    df['deletions'] = df['deletions'] * -1
    df['delta'] = df['additions'] - df['deletions']
    df['total_lines'] = df['delta'].cumsum()
    # return the dataframe
    return df

augur.githubapi.lines_of_code_changed = lines_of_code_changed
github.lines_of_code_changed("rails", "rails")


Out[7]:
date additions deletions delta total_lines
0 2004-11-21 31261 253 31008 31008
1 2004-11-28 271 113 158 31166
2 2004-12-05 3436 981 2455 33621
3 2004-12-12 3142 1885 1257 34878
4 2004-12-19 1476 315 1161 36039
5 2004-12-26 3079 1802 1277 37316
6 2005-01-02 1542 764 778 38094
7 2005-01-09 4690 2312 2378 40472
8 2005-01-16 690 369 321 40793
9 2005-01-23 2089 1645 444 41237
10 2005-01-30 0 0 0 41237
11 2005-02-06 3128 1116 2012 43249
12 2005-02-13 24299 16060 8239 51488
13 2005-02-20 6461 4656 1805 53293
14 2005-02-27 1232 250 982 54275
15 2005-03-06 1851 807 1044 55319
16 2005-03-13 641 240 401 55720
17 2005-03-20 4011 2006 2005 57725
18 2005-03-27 3819 2336 1483 59208
19 2005-04-03 1553 801 752 59960
20 2005-04-10 1093 340 753 60713
21 2005-04-17 3143 1128 2015 62728
22 2005-04-24 611 130 481 63209
23 2005-05-01 700 246 454 63663
24 2005-05-08 1535 52 1483 65146
25 2005-05-15 662 184 478 65624
26 2005-05-22 777 403 374 65998
27 2005-05-29 865 311 554 66552
28 2005-06-05 690 365 325 66877
29 2005-06-12 1619 513 1106 67983
... ... ... ... ... ...
683 2017-12-24 411 344 67 466799
684 2017-12-31 327 210 117 466916
685 2018-01-07 959 739 220 467136
686 2018-01-14 739 216 523 467659
687 2018-01-21 3085 2820 265 467924
688 2018-01-28 413 2157 -1744 466180
689 2018-02-04 1035 532 503 466683
690 2018-02-11 1407 1238 169 466852
691 2018-02-18 4303 3616 687 467539
692 2018-02-25 1277 1030 247 467786
693 2018-03-04 1821 481 1340 469126
694 2018-03-11 839 673 166 469292
695 2018-03-18 512 320 192 469484
696 2018-03-25 228 196 32 469516
697 2018-04-01 974 502 472 469988
698 2018-04-08 519 203 316 470304
699 2018-04-15 1290 779 511 470815
700 2018-04-22 2167 1997 170 470985
701 2018-04-29 352 170 182 471167
702 2018-05-06 392 210 182 471349
703 2018-05-13 728 398 330 471679
704 2018-05-20 419 96 323 472002
705 2018-05-27 865 379 486 472488
706 2018-06-03 367 284 83 472571
707 2018-06-10 311 210 101 472672
708 2018-06-17 359 162 197 472869
709 2018-06-24 652 183 469 473338
710 2018-07-01 1325 807 518 473856
711 2018-07-08 594 208 386 474242
712 2018-07-15 0 0 0 474242

713 rows × 5 columns


In [5]:



Out[5]:
date additions deletions delta total_lines
0 2004-11-21 31261 253 31008 31008
1 2004-11-28 271 113 158 31166
2 2004-12-05 3436 981 2455 33621
3 2004-12-12 3142 1885 1257 34878
4 2004-12-19 1476 315 1161 36039
5 2004-12-26 3079 1802 1277 37316
6 2005-01-02 1542 764 778 38094
7 2005-01-09 4690 2312 2378 40472
8 2005-01-16 690 369 321 40793
9 2005-01-23 2089 1645 444 41237
10 2005-01-30 0 0 0 41237
11 2005-02-06 3128 1116 2012 43249
12 2005-02-13 24299 16060 8239 51488
13 2005-02-20 6461 4656 1805 53293
14 2005-02-27 1232 250 982 54275
15 2005-03-06 1851 807 1044 55319
16 2005-03-13 641 240 401 55720
17 2005-03-20 4011 2006 2005 57725
18 2005-03-27 3819 2336 1483 59208
19 2005-04-03 1553 801 752 59960
20 2005-04-10 1093 340 753 60713
21 2005-04-17 3143 1128 2015 62728
22 2005-04-24 611 130 481 63209
23 2005-05-01 700 246 454 63663
24 2005-05-08 1535 52 1483 65146
25 2005-05-15 662 184 478 65624
26 2005-05-22 777 403 374 65998
27 2005-05-29 865 311 554 66552
28 2005-06-05 690 365 325 66877
29 2005-06-12 1619 513 1106 67983
... ... ... ... ... ...
683 2017-12-24 411 344 67 466799
684 2017-12-31 327 210 117 466916
685 2018-01-07 959 739 220 467136
686 2018-01-14 739 216 523 467659
687 2018-01-21 3085 2820 265 467924
688 2018-01-28 413 2157 -1744 466180
689 2018-02-04 1035 532 503 466683
690 2018-02-11 1407 1238 169 466852
691 2018-02-18 4303 3616 687 467539
692 2018-02-25 1277 1030 247 467786
693 2018-03-04 1821 481 1340 469126
694 2018-03-11 839 673 166 469292
695 2018-03-18 512 320 192 469484
696 2018-03-25 228 196 32 469516
697 2018-04-01 974 502 472 469988
698 2018-04-08 519 203 316 470304
699 2018-04-15 1290 779 511 470815
700 2018-04-22 2167 1997 170 470985
701 2018-04-29 352 170 182 471167
702 2018-05-06 392 210 182 471349
703 2018-05-13 728 398 330 471679
704 2018-05-20 419 96 323 472002
705 2018-05-27 865 379 486 472488
706 2018-06-03 367 284 83 472571
707 2018-06-10 311 210 101 472672
708 2018-06-17 359 162 197 472869
709 2018-06-24 652 183 469 473338
710 2018-07-01 1325 807 518 473856
711 2018-07-08 594 208 386 474242
712 2018-07-15 0 0 0 474242

713 rows × 5 columns


In [ ]: