<jupyter_start><jupyter_text>Running OSOSThis notebook demonstrates how you can run OSOS from python. This allows you to dive in deeper to the usage stats, especially the github metrics. If you have not already run OSOS from the CLI, you should do that too. The OSOS CLI is a general purpose tool that you can use to pull usage stats for your projects straight from the command line. You can also run the CLI for several projects using a config file. Try running `osos --help` from the command line to get started with the CLI.<jupyter_code>import datetime
import os
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from osos import Github, Pypi

sns.set_style("darkgrid")
msg = 'You need to set your github token in the GITHUB_TOKEN environment variable or input the string here explicitly'
token = os.getenv('GITHUB_TOKEN', None)
assert token is not None, msg<jupyter_output><empty_output><jupyter_text>Init a Github API<jupyter_code>Github?
gh = Github('NREL', 'reV', token=token)
gh<jupyter_output><empty_output><jupyter_text>Find Closed Issues Statistics<jupyter_code>gh.issues_closed?
gh.issues_closed()
issues = gh.issues_closed(get_lifetimes=True)
issues.keys()
plt.figure(figsize=(10, 5))
median = issues['issues_closed_median_lifetime']
p25 = np.percentile(issues['issues_closed_lifetimes'], 25)
p75 = np.percentile(issues['issues_closed_lifetimes'], 75)
h = plt.hist(issues['issues_closed_lifetimes'], bins=50)[2]
a = plt.plot([p25, p25], [0, 120])[0]
b = plt.plot([median, median], [0, 120])[0]
c = plt.plot([p75, p75], [0, 120])[0]
plt.xlabel('Lifetime of Closed reV Issues (days)')
plt.ylabel('Number of Issues')
plt.legend([h, a, b, c], 
           ['Closed Issue Lifetimes', 
            '25th Percentile ({:.1f} days)'.format(p25),
            'Median ({:.1f} days)'.format(median),
            '75th Percentile ({:.1f} days)'.format(p75)]
          )<jupyter_output><empty_output><jupyter_text>Find Commits<jupyter_code>gh.commits?
date_start = datetime.date.today() - datetime.timedelta(days=180)
commits = gh.commits(date_start=date_start)
commits
fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(111)
commits.plot(ax=ax)
plt.ylabel('reV Commits by Day (Main Branch)')
_ = plt.xticks(rotation=45)<jupyter_output><empty_output><jupyter_text>PyPI Stats<jupyter_code>Pypi.get_data?
pdata = Pypi.get_data('nrel-rev', include_mirrors=False)
pdata
fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(111)
pdata['pypi_daily'].plot()
plt.ylabel('reV PyPI Downloads (per day)')
_ = plt.xticks(rotation=45)
fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(111)
pdata['pypi_180_cumulative'].plot()
plt.ylabel('reV PyPI 180-day Cumulative Downloads')
_ = plt.xticks(rotation=45)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12885662431941924, 'fraction_numerical': 0.0294010889292196, 'mean_word_length': 5.821782178217822, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '471370', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1058, 'n_tokens_neox': 973, 'n_words': 261, 'path': 'examples/running_osos.ipynb', 'repo_name': 'NREL/osos', 'size': '2755'}