diff --git a/openbb_platform/extensions/platform_api/openbb_platform_api/utils/openapi.py b/openbb_platform/extensions/platform_api/openbb_platform_api/utils/openapi.py index a59cc274b5c..195b94b2446 100644 --- a/openbb_platform/extensions/platform_api/openbb_platform_api/utils/openapi.py +++ b/openbb_platform/extensions/platform_api/openbb_platform_api/utils/openapi.py @@ -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 diff --git a/openbb_platform/extensions/platform_api/openbb_platform_api/utils/widgets.py b/openbb_platform/extensions/platform_api/openbb_platform_api/utils/widgets.py index 45a597fd3a0..cb05b822825 100644 --- a/openbb_platform/extensions/platform_api/openbb_platform_api/utils/widgets.py +++ b/openbb_platform/extensions/platform_api/openbb_platform_api/utils/widgets.py @@ -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 {} diff --git a/openbb_platform/extensions/platform_api/tests/mock_openapi.json b/openbb_platform/extensions/platform_api/tests/mock_openapi.json index 46822bebb32..00aca8cfdee 100644 --- a/openbb_platform/extensions/platform_api/tests/mock_openapi.json +++ b/openbb_platform/extensions/platform_api/tests/mock_openapi.json @@ -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." }, diff --git a/openbb_platform/extensions/platform_api/tests/mock_widgets.json b/openbb_platform/extensions/platform_api/tests/mock_widgets.json index 6c4b8d325cf..c7a530d323d 100644 --- a/openbb_platform/extensions/platform_api/tests/mock_widgets.json +++ b/openbb_platform/extensions/platform_api/tests/mock_widgets.json @@ -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"