nwb_project_analytics.renderstats module
Module with routines for plotting code and git statistics
- class nwb_project_analytics.renderstats.PatchedMPLPlot(data, kind=None, by: IndexLabel | None = None, subplots: bool | Sequence[Sequence[str]] = False, sharex=None, sharey: bool = False, use_index: bool = True, figsize=None, grid=None, legend: bool | str = True, rot=None, ax=None, fig=None, title=None, xlim=None, ylim=None, xticks=None, yticks=None, xlabel: Hashable | None = None, ylabel: Hashable | None = None, fontsize=None, secondary_y: bool | tuple | list | np.ndarray = False, colormap=None, table: bool = False, layout=None, include_bool: bool = False, column: IndexLabel | None = None, **kwds)
Bases:
MPLPlot
- axes: np.ndarray
- class nwb_project_analytics.renderstats.RenderClocStats
Bases:
object
Helper class for rendering code line statistics generated using GitCodeStats, e.g., via GitCodeStats.from_nwb.
- static plot_cloc_sizes_stacked_area(summary_stats: dict, order: list | None = None, colors: list | None = None, title: str | None = None, fontsize: int = 20)
Stacked curve plot of code size statistics
- Parameters:
summary_stats – dict with the results form GitCodeStats.compute_summary_stats
order – List of strings selecting the order in which codes should be stacked in the plot. If set to none then all keys in summary_stats will be used sorted alphabetically.
colors – List of colors to be used. One per repo. Must be the same lenght as order.
- Returns:
Matplotlib axis object used for plotting
- static plot_reposize_code_comment_blank(summary_stats: dict, repo_name: str, title: str | None = None)
Plot repository size broken down by code, comment, and blank for a particular repo
- Parameters:
summary_stats – dict with the results form GitCodeStats.compute_summary_stats
repo_name – Key in dataframes of summary_stats with the name of the code repository to plot.
title – Title of the plot
- Returns:
Matplotlib axis object used for plotting
- static plot_reposize_language(per_repo_lang_stats: dict, languages_used_all: list, repo_name: str, figsize: tuple | None = None, fontsize: int = 18, title: str | None = None)
Plot repository size broken down by language for a particular repo
To compute the language statistics for code repositories we can use
git_code_stats, summary_stats = GitCodeStats.from_nwb(...) ignore_lang = ['SUM', 'header'] languages_used_all = git_code_stats.get_languages_used(ignore_lang) per_repo_lang_stats = git_code_stats.compute_language_stats(ignore_lang)
- Parameters:
per_repo_lang_stats – Dict with per repository language statistics compute via GitCodeStats.compute_language_statistics
languages_used_all – List/array with the languages uses
repo_name – Key in dataframes of summary_stats with the name of the code repository to plot.
figsize – Figure size tuple. Default=(18, 10)
fontsize – Fontsize
title – Title of the plot
- Returns:
Matplotlib axis object used for plotting
- class nwb_project_analytics.renderstats.RenderCodecovInfo
Bases:
object
Helper class for plotting CoedcovInfo data
- classmethod plot_codecov_grid(codecovs: dict, plot_xlim: tuple | None = None, fontsize: int = 16, basefilename: str | None = None)
Plot coverage results for one or more codes as a single figure with one row per code so all codes appear in their own plots but with a shared x-axis for time and creating only a single file
Example for setting for
codecovs
:codecovs = {r: CodecovInfo.get_pulls_or_commits(NWBGitInfo.GIT_REPOS[r], key='commits', state='all', branch=NWBGitInfo.GIT_REPOS[r].mainbranch) for r in ['HDMF', 'PyNWB', 'MatNWB']}
- Parameters:
codecovs – Dictionary where the keys are the names of the codes and the values are the output from CodecovInfo.get_pulls_or_commits defining the coverage timeline for each code.
plot_xlim – Tuple of datatime objects defining the time-range of the x-axis. E.g., plot_xlim=(datetime.strptime(“2021-01-01”, “%Y-%m-%d”), datetime.today())
fontsize – Fontsize to be used for axes label, tickmarks, and titles. (default=16)
basefilename – Base name of the file(s) where the plots should eb saved to. Set to None to only show but not save the plots. Figures will be saved as both PDF and PNG. (default=None)
- classmethod plot_codecov_individual(codecovs: dict, plot_xlim: tuple | None = None, fontsize: int = 16, figsize: tuple | None = None, title: str | None = None)
Plot coverage results for a code as an individual figure
Example for setting for
codecovs
:codecovs = {r: CodecovInfo.get_pulls_or_commits(NWBGitInfo.GIT_REPOS[r], key='commits', state='all', branch=NWBGitInfo.GIT_REPOS[r].mainbranch) for r in ['HDMF', 'PyNWB', 'MatNWB']}
- Parameters:
codecovs – Dictionary where the key is the name of the codes and the values are the output from CodecovInfo.get_pulls_or_commits defining the coverage timeline for each code.
plot_xlim – Tuple of datatime objects defining the time-range of the x-axis. E.g., plot_xlim=(datetime.strptime(“2021-01-01”, “%Y-%m-%d”), datetime.today())
fontsize – Fontsize to be used for axes label, tickmarks, and titles. (default=16)
figsize – Figure size tuple. Default is (18,6)
title – Optional title for the figure
- Returns:
Matplotlib figure
- static plot_codecov_multiline(codecovs: dict, plot_xlim: tuple | None = None, fill_alpha: float = 0.2, fontsize: int = 16, title: str | None = None, figsize: tuple | None = None)
Plot coverage results for one or more codes as a single figure with each code represented by a line plot with optional filled area.
Example for setting for
codecovs
:codecovs = {r: CodecovInfo.get_pulls_or_commits(NWBGitInfo.GIT_REPOS[r], key='commits', state='all', branch=NWBGitInfo.GIT_REPOS[r].mainbranch) for r in ['HDMF', 'PyNWB', 'MatNWB']}
- Parameters:
codecovs – Dictionary where the keys are the names of the codes and the values are the output from CodecovInfo.get_pulls_or_commits defining the coverage timeline for each code.
plot_xlim – Tuple of datatime objects defining the time-range of the x-axis. E.g., plot_xlim=(datetime.strptime(“2021-01-01”, “%Y-%m-%d”), datetime.today())
fill_alpha – Alpha value to be used for the area plots. Set to 0 or less to disable area plots (default=0.2)
fontsize – Fontsize to be used for axes label, tickmarks, and titles. (default=16)
title – Optional title for the figure
figsize – Opitonal tuple of ints with the figure size
- Returns:
Matplotlib figure created here
- class nwb_project_analytics.renderstats.RenderCommitStats
Bases:
object
Helper class for rendering commit history for repos
- COLOR_ADDITIONS = 'darkgreen'
- COLOR_DELETIONS = 'darkred'
- static plot_commit_additions_and_deletions(commits: DataFrame, repo_name: str | None = None, xaxis_dates: bool = False, bar_width: float = 0.8, color_additions: str = 'darkgreen', color_deletions: str = 'darkred', xticks_rotate: int = 90)
Plot the number of additions and deletions for commits as a bar plot
- Parameters:
commits – Pandas DataFrame with the commits generated via GitRepo.get_commits_as_dataframe
repo_name – Name of the Git repository
xaxis_dates – Place bars by date (True) or equally spaced by order of commits (False)
bar_width – Width of the bars. When plotting with xaxis_dates=True using a narrow bar width can help avoid overlap between bars
color_additions – Color to be used for additions
color_deletions – Color to be used for deletions
xticks_rotate – Degrees to rotate x axis labels
- Returns:
Tuple with the Matplotlib figure and axis used
- static plot_commit_additions_and_deletions_summary(commits: dict, bar_width: float = 0.8, color_additions='darkgreen', color_deletions='darkred', xticks_rotate: int = 45, start_date: datetime | None = None, end_date: datetime | None = None)
Plot bar chart with total additions and deletions for a collection of repositories
- Parameters:
commits – Dict where the keys are the nwb_project_analytics.gitstats.GitRepo objects (or the string name of the repo) and the values are pandas DataFrames with the commits generated via GitRepo.get_commits_as_dataframe
bar_width – Width of the bars
color_additions – Color to be used for additions
color_deletions – Color to be used for deletions
xticks_rotate – Degrees to rotate x axis labels
start_date – Optional start date to be rendered in the title
end_date – Optional end data to be rendered in the title
- static plot_commit_cumulative_additions_and_deletions(commits: DataFrame, repo_name: str | None = None, color_additions='darkgreen', color_deletions='darkred')
Plot the cumulative number of additions and deletions for commits as a stacked area plot
- Parameters:
commits – Pandas DataFrame with the commits generated via GitRepo.get_commits_as_dataframe(
repo_name – Name of the Git repository
color_additions – Color to be used for additions
color_deletions – Color to be used for deletions
- Returns:
Tuple with the Matplotlib figure and axis used
- class nwb_project_analytics.renderstats.RenderReleaseTimeline
Bases:
object
Helper class for rendering GitHubRepoInfo release timeslines
- classmethod plot_multiple_release_timeslines(release_timelines: dict, add_releases: dict | None = None, date_range: tuple | None = None, month_intervals: int = 2, fontsize: int = 16, title: str | None = None)
Plot multiple aligned timelines of the releases of a collection of GitHubRepoInfo repo objects
- Parameters:
release_timelines – Dict where the keys are the repo names and the values are tuples with the 1) name of the versions and 2) dates of the versions
add_releases (Dict where the keys are a subset of the keys of the github_repos dict and the values are lists of tuples with "name: str" and "date: datetime.strptime(d[0:10], "%Y-%m-%d")" of additional releases for the given repo. Usually this is set to NWBGitInfo.MISSING_RELEASE_TAGS) – Sometimes libraries did not use git tags to mark releases. With this we can add additional releases that are missing from the git tags. If None this is set to NWBGitInfo.MISSING_RELEASE_TAGS by default. Set to empty dict if no additional releases should be added.
date_range – Tuple of datetime objects with the start and stop time to use along the x axis for rendering. If date_range is None it is automatically set to (NWBGitInfo.NWB2_BETA_RELEASE - timedelta(days=60), datetime.today())
month_intervals – Integer with spacing of month along the x axis. (Default=2)
fontsize – Fontsize to use in the plots
- Returns:
Tuple of matplotlib figure object and list of axes object used for rendering
- static plot_release_timeline(repo_name: str, dates: list, versions: list, figsize: tuple | None = None, fontsize: int = 14, month_intervals: int = 3, xlim: tuple | None = None, ax=None, title_on_yaxis: bool = False, add_releases: list | None = None)
Plot a timeline of the releases for a single GitHubRepoInfo repo
Based on https://matplotlib.org/stable/gallery/lines_bars_and_markers/timeline.html
- Parameters:
repo_info – The GitHubRepoInfo object to plot a release timeline for
figsize – Tuple with the figure size if a new figure is to be created, i.e., if ax is None
fontsize – Fontsize to use for labels (default=14)
month_intervals – Integer indicating the step size in number of month for the y axis
xlim – Optional tuple of datetime objects with the start and end-date for the x axis
ax – Matplotlib axis object to be used for plotting
title_on_yaxis – Show plot title as name of the y-axis (True) or as the main title (False) (default=False)
add_releases (List of tuples with "name: str" and "date: datetime.strptime(d[0:10], "%Y-%m-%d")") – Sometimes libraries did not use git tags to mark releases. With this we can add additional releases that are missing from the git tags.
- Returns:
Matplotlib axis object used for plotting