summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Radovanovic <74266147+IgorWounds@users.noreply.github.com>2024-01-29 12:15:21 +0100
committerGitHub <noreply@github.com>2024-01-29 11:15:21 +0000
commit4755711be6e6d9d4d52124ed85e3984cd811d1f1 (patch)
tree3fc0a5b681fd693047325437d3a2e645fcea2136
parente7798c211ecc50912a4cfd96dbf30097ec9fe4de (diff)
[Feature] - Field order added to the OBBject extra as preference (#5999)
* Disable auto_build on test run * Add field order to OBBject * Improvements * Remove noxfile * Disable auto_build on test run * Add field order to OBBject * Revert * lint * Add docs * Not sure how this happened * lint
-rw-r--r--openbb_platform/core/openbb_core/app/command_runner.py29
-rw-r--r--openbb_platform/core/openbb_core/app/model/preferences.py8
-rw-r--r--website/content/platform/usage/index.md1
3 files changed, 38 insertions, 0 deletions
diff --git a/openbb_platform/core/openbb_core/app/command_runner.py b/openbb_platform/core/openbb_core/app/command_runner.py
index ab04c87ffad..982c389ab11 100644
--- a/openbb_platform/core/openbb_core/app/command_runner.py
+++ b/openbb_platform/core/openbb_core/app/command_runner.py
@@ -338,6 +338,35 @@ class StaticCommandRunner:
route=route,
**kwargs,
)
+ try:
+ if (
+ obbject.results
+ and execution_context.user_settings.preferences.field_order
+ ):
+ if isinstance(obbject.results, list):
+ fields = obbject.results[0].model_dump().keys()
+ else:
+ fields = obbject.results.model_dump().keys()
+
+ obbject.extra["field_order"] = list(fields)
+ except Exception as e:
+ if Env().DEBUG_MODE:
+ raise OpenBBError(e) from e
+
+ try:
+ if (
+ obbject.results
+ and execution_context.user_settings.preferences.field_order
+ ):
+ if isinstance(obbject.results, list):
+ fields = obbject.results[0].model_dump().keys()
+ else:
+ fields = obbject.results.model_dump().keys()
+
+ obbject.extra["field_order"] = list(fields)
+ except Exception as e:
+ if Env().DEBUG_MODE:
+ raise OpenBBError(e) from e
except Exception as e:
raise OpenBBError(e) from e
diff --git a/openbb_platform/core/openbb_core/app/model/preferences.py b/openbb_platform/core/openbb_core/app/model/preferences.py
index 61e3db5c6c0..0fb2a555500 100644
--- a/openbb_platform/core/openbb_core/app/model/preferences.py
+++ b/openbb_platform/core/openbb_core/app/model/preferences.py
@@ -1,3 +1,5 @@
+"""Preferences for the OpenBB platform."""
+
from pathlib import Path
from typing import Literal
@@ -5,6 +7,8 @@ from pydantic import BaseModel, ConfigDict, Field, PositiveInt
class Preferences(BaseModel):
+ """Preferences for the OpenBB platform."""
+
data_directory: str = str(Path.home() / "OpenBBUserData")
export_directory: str = str(Path.home() / "OpenBBUserData" / "exports")
user_styles_directory: str = str(Path.home() / "OpenBBUserData" / "styles" / "user")
@@ -20,6 +24,9 @@ class Preferences(BaseModel):
table_style: Literal["dark", "light"] = "dark"
request_timeout: PositiveInt = 15
metadata: bool = True
+ field_order: bool = (
+ False # Whether to display the field order by which the data was defined
+ )
output_type: Literal["OBBject", "dataframe", "polars", "numpy", "dict", "chart"] = (
Field(default="OBBject", description="Python default output type.")
)
@@ -27,6 +34,7 @@ class Preferences(BaseModel):
model_config = ConfigDict(validate_assignment=True)
def __repr__(self) -> str:
+ """Return a string representation of the model."""
return f"{self.__class__.__name__}\n\n" + "\n".join(
f"{k}: {v}" for k, v in self.model_dump().items()
)
diff --git a/website/content/platform/usage/index.md b/website/content/platform/usage/index.md
index 3483a3662d8..13ce82322ae 100644
--- a/website/content/platform/usage/index.md
+++ b/website/content/platform/usage/index.md
@@ -145,6 +145,7 @@ HTTP_PROXY="http://10.10.10.10:8000"
| table_style | dark | ["dark", "light"] | "The default color style to use with the OpenBB Charting Extension tables. Options are "dark" and "light"" |
| request_timeout | 15 | Any positive integer. | Specifies the timeout duration for HTTP requests. |
| metadata | True | [True, False] | Enables or disables the collection of metadata which provides information about operations including arguments duration route and timestamp. Disabling this feature may improve performance in cases where contextual information is not needed or when the additional computation time and storage space are a concern. |
+| field_order | False | [True, False] | Enables or disables the information on the field order defined with Pydantic models. Useful for frontend as the API returns JSON which is an unordered collection. |
| output_type | OBBject | ["OBBject", "dataframe", "numpy", "dict", "chart", "polars"] | Specifies the type of data the application will output when a command or endpoint is accessed. Note that choosing data formats only available in Python such as `dataframe` | `numpy` or `polars` will render the application's API non-functional. |
User settings can be set from the Python interface directly.