[BugFix] openbb-platform-api: Formatting Fixes (#6873)

* fix some formatting things

* ytd yoy

* peg ebit

* cyclic-import

* try relative import

* move TO_CAPS_STRINGS

* remove import from change

* fix test
This commit is contained in:
Danglewood
2024-10-28 08:36:41 -07:00
committed by GitHub
parent 251ef3987c
commit 57c2b6ff1f
4 changed files with 77 additions and 56 deletions

View File

@@ -2,6 +2,52 @@
from openbb_core.provider.utils.helpers import to_snake_case
TO_CAPS_STRINGS = [
"Pe",
"Peg",
"Sloos",
"Eps",
"Ebit",
"Ebitda",
"Otc",
"Cpi",
"Pce",
"Gdp",
"Lbma",
"Ipo",
"Nbbo",
"Ameribor",
"Sonia",
"Effr",
"Sofr",
"Iorb",
"Estr",
"Ecb",
"Dpcredit",
"Tcm",
"Us",
"Ice",
"Bofa",
"Hqm",
"Sp500",
"Sec",
"Cftc",
"Cot",
"Etf",
"Eu",
"Tips",
"Rss",
"Sic",
"Cik",
"Bls",
"Fred",
"Cusip",
"Ttm",
"Id",
"Ytd",
"Yoy",
]
def extract_providers(params: list[dict]) -> list[str]:
"""
@@ -319,6 +365,7 @@ def get_data_schema_for_widget(openapi_json, operation_id):
def data_schema_to_columns_defs(openapi_json, operation_id, provider):
"""Convert data schema to column definitions for the widget."""
# Initialize an empty list to hold the schema references
schema_refs: list = []
@@ -420,7 +467,13 @@ def data_schema_to_columns_defs(openapi_json, operation_id, provider):
column_def["pinned"] = "left"
column_def["formatterFn"] = formatterFn
column_def["headerName"] = prop.get("title", key.title())
header_name = prop.get("title", key.title())
column_def["headerName"] = " ".join(
[
(word.upper() if word in TO_CAPS_STRINGS else word)
for word in header_name.split(" ")
]
)
column_def["description"] = prop.get(
"description", prop.get("title", key.title())
)
@@ -449,6 +502,10 @@ def data_schema_to_columns_defs(openapi_json, operation_id, provider):
column_def["headerName"].upper() if k != "symbol" else "Symbol"
)
if k in ["fiscal_year", "year"]:
column_def["cellDataType"] = "number"
column_def["formatterFn"] = "none"
column_defs.append(column_def)
return column_defs

View File

@@ -2,46 +2,6 @@
from copy import deepcopy
TO_CAPS_STRINGS = [
"Pe",
"Sloos",
"Eps",
"Ebitda",
"Otc",
"Cpi",
"Pce",
"Gdp",
"Lbma",
"Ipo",
"Nbbo",
"Ameribor",
"Sonia",
"Effr",
"Sofr",
"Iorb",
"Estr",
"Ecb",
"Dpcredit",
"Tcm",
"Us",
"Ice",
"Bofa",
"Hqm",
"Sp500",
"Sec",
"Cftc",
"Cot",
"Etf",
"Eu",
"Tips",
"Rss",
"Sic",
"Cik",
"Bls",
"Fred",
"Cusip",
]
def modify_query_schema(query_schema: list[dict], provider_value: str):
"""Modify query_schema and the description for the current provider."""
@@ -103,7 +63,11 @@ def modify_query_schema(query_schema: list[dict], provider_value: str):
def build_json(openapi: dict, widget_exclude_filter: list):
"""Build the widgets.json file."""
# pylint: disable=import-outside-toplevel
from .openapi import data_schema_to_columns_defs, get_query_schema_for_widget
from .openapi import (
TO_CAPS_STRINGS,
data_schema_to_columns_defs,
get_query_schema_for_widget,
)
if not openapi:
return {}

View File

@@ -2000,7 +2000,7 @@
}
],
"description": "The element ID of a specific table in the release.",
"title": "Element Id"
"title": "Element ID"
},
"description": "The element ID of a specific table in the release."
},

View File

@@ -943,7 +943,7 @@
{
"field": "element_id",
"formatterFn": null,
"headerName": "Element Id",
"headerName": "Element ID",
"description": "The element id in the parent/child relationship.",
"cellDataType": "text",
"chartDataType": "category"
@@ -951,7 +951,7 @@
{
"field": "parent_id",
"formatterFn": null,
"headerName": "Parent Id",
"headerName": "Parent ID",
"description": "The parent id in the parent/child relationship.",
"cellDataType": "text",
"chartDataType": "category"
@@ -1569,7 +1569,7 @@
{
"field": "balance_percent_of_gdp",
"formatterFn": "normalizedPercent",
"headerName": "Balance Percent Of Gdp",
"headerName": "Balance Percent Of GDP",
"description": "Current Account Balance as Percent of GDP",
"cellDataType": "number",
"chartDataType": "series",
@@ -1850,7 +1850,7 @@
"columnsDefs": [
{
"field": "release_id",
"headerName": "Release Id",
"headerName": "Release ID",
"description": "The release ID for queries.",
"cellDataType": "number",
"chartDataType": "series"
@@ -1859,7 +1859,7 @@
"field": "series_id",
"pinned": "left",
"formatterFn": null,
"headerName": "Series Id",
"headerName": "Series ID",
"description": "The series ID for the item in the release.",
"cellDataType": "text",
"chartDataType": "category"
@@ -2523,7 +2523,7 @@
{
"field": "element_id",
"formatterFn": null,
"headerName": "Element Id",
"headerName": "Element ID",
"description": "The element id in the parent/child relationship.",
"cellDataType": "text",
"chartDataType": "category"
@@ -2531,7 +2531,7 @@
{
"field": "parent_id",
"formatterFn": null,
"headerName": "Parent Id",
"headerName": "Parent ID",
"description": "The parent id in the parent/child relationship.",
"cellDataType": "text",
"chartDataType": "category"
@@ -2885,7 +2885,7 @@
"field": "series_id",
"pinned": "left",
"formatterFn": null,
"headerName": "Series Id",
"headerName": "Series ID",
"description": "The individual series ID for the region.",
"cellDataType": "text",
"chartDataType": "category"
@@ -3213,7 +3213,7 @@
{
"field": "element_id",
"formatterFn": null,
"headerName": "Element Id",
"headerName": "Element ID",
"description": "The element id in the parent/child relationship.",
"cellDataType": "text",
"chartDataType": "category"
@@ -3221,7 +3221,7 @@
{
"field": "parent_id",
"formatterFn": null,
"headerName": "Parent Id",
"headerName": "Parent ID",
"description": "The parent id in the parent/child relationship.",
"cellDataType": "text",
"chartDataType": "category"
@@ -3352,7 +3352,7 @@
},
{
"field": "cik_number",
"headerName": "Cik Number",
"headerName": "CIK Number",
"description": "Central Index Key (CIK)",
"cellDataType": "number",
"chartDataType": "series"
@@ -3519,7 +3519,7 @@
{
"field": "id",
"formatterFn": null,
"headerName": "Id",
"headerName": "ID",
"description": "The identifier associated with the release.",
"cellDataType": "text",
"chartDataType": "category"
@@ -3583,7 +3583,7 @@
"columnsDefs": [
{
"field": "sic_code",
"headerName": "Sic Code",
"headerName": "SIC Code",
"description": "Sector Industrial Code (SIC)",
"cellDataType": "number",
"chartDataType": "series"