mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 13:32:08 +00:00
* Fixes * Update stocks_helper.py * update git-actions set-output to new format * Update stocks_helper.py * Update terminal_helper.py * removed LineAnnotateDrawer from qa_view * lint * few changes * updates * sdk auto gen modules done * Update stocks_helper.py * updates to changed imports, and remove first sdk_modules * Update generate_sdk.py * Update generate_sdk.py * pylint * revert stocks_helper * Update generate_sdk.py * Update sdk.py * Update generate_sdk.py * full auto generation, added sdk.py/controllers creation * missed enable forecasting * added running black in subprocess after sdk files generation completes * removed deleted sdk_arg_logger * comment out tests * property doc fix * clean up * Update generate_sdk.py * make trailmap classes useable for doc generation * Update generate_sdk.py * added lineon to trailmap class for linking to func in markdown * changed lineon to dict * added full_path to trailmap for linking in docs * updated portfolio * feat: initial files * feat: added meta head * feat: added funcdef * added func_def to trailmap attributes for markdown in docs, added missing type hints to covid functions * feat: added view and merged with jaun * Update generate_sdk.py * Update generate_sdk.py * Update generate_sdk.py * Update generate_sdk.py * init * fix returns * fix: random stuff * fix: random * fixed encoding issue on windows * fix: generate tabs * update * Update generate_sdk_markdown.py * Create .pydocstyle.ini * added type hint classes for views * fixes * alt, ba * alt-economy * Update finviz_compare_model.py * fixs * Update substack_model.py * Update generate_sdk.py * last of my section * porfolio * po * Update optimizer_model.py * fixing more things * few more * keys done * update * fixes * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * mypy forecast fix * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * fixes * forecast fixes * one more fix * Update coinbase_model.py * Update generate_sdk_markdown.py Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> Co-authored-by: jose-donato <zmcdonato@gmail.com> Co-authored-by: andrewkenreich <andrew.kenreich@gmail.com>
132 lines
4.4 KiB
Python
132 lines
4.4 KiB
Python
"""Rekt view"""
|
|
import logging
|
|
import os
|
|
from typing import Optional, List
|
|
|
|
from matplotlib import pyplot as plt
|
|
from matplotlib import ticker
|
|
from openbb_terminal.alternative.oss import runa_model
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.helper_funcs import (
|
|
export_data,
|
|
plot_autoscale,
|
|
lambda_long_number_format,
|
|
print_rich_table,
|
|
is_valid_axes_count,
|
|
)
|
|
from openbb_terminal.config_terminal import theme
|
|
from openbb_terminal.config_plot import PLOT_DPI
|
|
from openbb_terminal.rich_config import console
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def display_rossindex(
|
|
limit: int = 10,
|
|
sortby: str = "Stars AGR [%]",
|
|
ascend: bool = False,
|
|
show_chart: bool = False,
|
|
show_growth: bool = True,
|
|
chart_type: str = "stars",
|
|
export: str = "",
|
|
external_axes: Optional[List[plt.Axes]] = None,
|
|
) -> None:
|
|
"""Plots list of startups from ross index [Source: https://runacap.com/]
|
|
|
|
Parameters
|
|
----------
|
|
limit: int
|
|
Number of startups to search
|
|
sortby: str
|
|
Key by which to sort data. Default: Stars AGR [%]
|
|
ascend: bool
|
|
Flag to sort data descending
|
|
show_chart: bool
|
|
Flag to show chart with startups
|
|
show_growth: bool
|
|
Flag to show growth line chart
|
|
chart_type: str
|
|
Chart type {stars,forks}
|
|
export : str
|
|
Export dataframe data to csv,json,xlsx file
|
|
external_axes : Optional[List[plt.Axes]], optional
|
|
External axes (1 axis is expected in the list), by default None
|
|
"""
|
|
df = runa_model.get_startups()
|
|
|
|
if df.empty:
|
|
console.print("\nError in runa request\n")
|
|
else:
|
|
if sortby in runa_model.SORT_COLUMNS:
|
|
df = df.sort_values(by=sortby, ascending=ascend)
|
|
df = df.head(limit)
|
|
if show_chart:
|
|
if external_axes is None:
|
|
_, ax1 = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
|
elif is_valid_axes_count(external_axes, 2):
|
|
(ax1, _) = external_axes
|
|
else:
|
|
return
|
|
for _, row in df[::-1].iterrows():
|
|
ax1.barh(
|
|
y=row["GitHub"],
|
|
width=row["Forks" if chart_type == "forks" else "Stars"],
|
|
)
|
|
ax1.set_xlabel("Forks" if chart_type == "forks" else "Stars")
|
|
ax1.get_xaxis().set_major_formatter(
|
|
ticker.FuncFormatter(lambda x, _: lambda_long_number_format(x))
|
|
)
|
|
ax1.grid(axis="y")
|
|
ax1.yaxis.set_label_position("left")
|
|
ax1.yaxis.set_ticks_position("left")
|
|
ax1.set_ylabel("Company")
|
|
ax1.yaxis.set_tick_params(labelsize=8)
|
|
title = "Total Forks" if chart_type == "forks" else "Total Stars"
|
|
ax1.set_title(f"ROSS Index - {title}")
|
|
if external_axes is None:
|
|
theme.visualize_output()
|
|
if show_growth:
|
|
if external_axes is None:
|
|
fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
|
elif is_valid_axes_count(external_axes, 2):
|
|
(ax, _) = external_axes
|
|
else:
|
|
return
|
|
for _, row in df[::-1].iterrows():
|
|
ax.barh(
|
|
y=row["GitHub"],
|
|
width=row["FG" if chart_type == "forks" else "SG"],
|
|
)
|
|
ax.yaxis.set_label_position("left")
|
|
ax.yaxis.set_ticks_position("left")
|
|
ax.set_ylabel("Company")
|
|
ax.set_xlabel("Annual Growth [times]")
|
|
ax.yaxis.set_tick_params(labelsize=8)
|
|
title = (
|
|
"Forks Annual Growth"
|
|
if chart_type == "forks"
|
|
else "Stars Annual Growth"
|
|
)
|
|
ax.set_title(f"ROSS Index - {title}")
|
|
fig.tight_layout()
|
|
if external_axes is None:
|
|
theme.visualize_output()
|
|
show_df = df.drop(["SG", "FG"], axis=1)
|
|
show_df = show_df.fillna("")
|
|
show_df["GitHub"] = show_df["GitHub"].str.wrap(10)
|
|
print_rich_table(
|
|
show_df.head(limit),
|
|
headers=list(show_df.columns),
|
|
floatfmt=".1f",
|
|
show_index=False,
|
|
title="ROSS Index - the fastest-growing open-source startups",
|
|
)
|
|
|
|
export_data(
|
|
export,
|
|
os.path.dirname(os.path.abspath(__file__)),
|
|
"runaidx",
|
|
df,
|
|
)
|