PV_ICE#

[1]:
import utils
import pandas as pd

from bokeh.plotting import figure, show
from bokeh.models import HoverTool
from bokeh.transform import jitter
from bokeh.io import output_notebook
[2]:
output_notebook()
Loading BokehJS ...

ReadTheDocs#

[3]:
df = utils.get_rtd_analytics_data('pv-ice')
data_period = df['Date'].min().strftime('%Y-%m-%d') + ' to ' + df['Date'].max().strftime('%Y-%m-%d')
[4]:
total_by_version = df.groupby('Version')['Views'].sum().reset_index()

p = figure(x_range=total_by_version['Version'], height=350, tooltips=[("Version", "@Version"), ("Views", "@Views")],
           title=f"Page views by RTD version ({data_period})",)
p.vbar(x='Version', top='Views', width=0.75, source=total_by_version,
       line_color='white')
p.xaxis.major_label_orientation = 3.14/2
p.yaxis.axis_label = 'Total page views'
show(p)
[5]:
daily_views = df.pivot_table(values='Views', index='Date', columns='Version', aggfunc='sum')[['stable', 'latest']].fillna(0)

p = figure(x_axis_type="datetime", height=350, title=f"Daily views by RTD version")
hover_tool = HoverTool(tooltips=[('Date', '@x{%Y-%m-%d}'), ('Views', '@y')],
                       formatters={'@x': 'datetime'})
hover_tool.point_policy = 'snap_to_data'
p.add_tools(hover_tool)
p.line(daily_views.index, daily_views['stable'], legend_label='stable')
p.line(daily_views.index, daily_views['latest'], legend_label='latest', color='#ff7f0e')
p.yaxis.axis_label = 'Daily page views'
show(p)
[6]:
df2 = df.loc[(df['Version'] == 'latest'), :].copy()
pathviews = df2.groupby('Path')['Views'].sum().reset_index()
[7]:
subset = pathviews.sort_values('Views', ascending=False)
p = figure(y_range=subset['Path'], height=400, tooltips=[("URL", "@Path"), ("Views", "@Views")],
           title=f"Views by URL ({data_period})")
p.hbar(y='Path', right='Views', source=subset, height=0.75,
       line_color='white')
p.xaxis.axis_label = 'Total page views'
show(p)

GitHub#

[8]:
gh = utils.get_github_stars('nrel/PV_ICE')
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[8], line 1
----> 1 gh = utils.get_github_stars('nrel/PV_ICE')

File ~/work/pv-foss-engagement/pv-foss-engagement/sphinx/source/project/utils.py:83, in get_github_stars(repo)
     82 def get_github_stars(repo):
---> 83     data, N = _fetch_gh_api(repo)
     84     for i in range(2, N+1):
     85         data.extend(_fetch_gh_api(repo, i)[0])

File ~/work/pv-foss-engagement/pv-foss-engagement/sphinx/source/project/utils.py:77, in _fetch_gh_api(repo, page)
     74     N = 1
     76 if isinstance(data, dict) and data.get('status', None) != 200:
---> 77     raise Exception(data)
     79 return data, N

Exception: {'message': 'Bad credentials', 'documentation_url': 'https://docs.github.com/rest', 'status': '401'}
[9]:
p = utils.plot_github_stars_timeseries(gh)
show(p)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[9], line 1
----> 1 p = utils.plot_github_stars_timeseries(gh)
      2 show(p)

NameError: name 'gh' is not defined
[10]:
contributor_ts, _ = utils.get_github_contributor_timeseries("nrel/pv_ice")
p = utils.plot_github_contributors_timeseries(contributor_ts)
show(p)
[11]:
contributors = utils.get_github_contributors('nrel/pv_ice')
[12]:
mosaic = utils.make_github_contributors_mosaic(contributors)
mosaic
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[12], line 1
----> 1 mosaic = utils.make_github_contributors_mosaic(contributors)
      2 mosaic

File ~/work/pv-foss-engagement/pv-foss-engagement/sphinx/source/project/utils.py:139, in make_github_contributors_mosaic(contributor_data, n_wide, n_high)
    137 images = []
    138 for contributor in contributor_data:
--> 139     response = requests.get(contributor['avatar_url'], stream=True)
    140     images.append(Image.open(response.raw))
    142 # randomize order

TypeError: string indices must be integers, not 'str'
[ ]: