Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Flatten Revenue By Geography and Business Line #6624

Merged
merged 15 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
"""Revenue by Business Line Standard Model."""
"""Revenue By Business Line Standard Model."""

from datetime import date as dateType
from typing import Dict, Literal, Optional
from typing import Optional, Union

from pydantic import Field, field_validator

from openbb_core.provider.abstract.data import Data, ForceInt
from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams
from openbb_core.provider.utils.descriptions import (
QUERY_DESCRIPTIONS,
)
from openbb_core.provider.utils.descriptions import QUERY_DESCRIPTIONS


class RevenueBusinessLineQueryParams(QueryParams):
"""Revenue by Business Line Query."""
"""Revenue By Business Line Query."""

symbol: str = Field(description=QUERY_DESCRIPTIONS.get("symbol", ""))
period: Literal["quarter", "annual"] = Field(
default="annual", description=QUERY_DESCRIPTIONS.get("period", "")
)
structure: Literal["hierarchical", "flat"] = Field(
default="flat", description="Structure of the returned data."
) # should always be flat

@field_validator("symbol", mode="before", check_fields=False)
@classmethod
def to_upper(cls, v: str):
"""Convert field to uppercase."""
return v.upper()

@field_validator("period", "structure", mode="before", check_fields=False)
@classmethod
def to_lower(cls, v: Optional[str]) -> Optional[str]:
"""Convert field to lowercase."""
return v.lower() if v else v


class RevenueBusinessLineData(Data):
"""Revenue by Business Line Data."""
"""Revenue By Business Line Data."""

period_ending: dateType = Field(description="The end date of the reporting period.")
fiscal_period: Optional[str] = Field(
Expand All @@ -49,6 +35,11 @@ class RevenueBusinessLineData(Data):
filing_date: Optional[dateType] = Field(
default=None, description="The filing date of the report."
)
business_line: Dict[str, ForceInt] = Field(
description="Dictionary containing the revenue of the business line."
business_line: Optional[str] = Field(
default=None,
description="The business line represented by the revenue data.",
)
revenue: Union[int, float] = Field(
description="The total revenue attributed to the business line.",
json_schema_extra={"x-unit_measurement": "currency"},
)
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
"""Revenue by Geographic Segments Standard Model."""

from datetime import date as dateType
from typing import Dict, Literal, Optional
from typing import Optional, Union

from pydantic import Field, field_validator

from openbb_core.provider.abstract.data import Data, ForceInt
from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams
from openbb_core.provider.utils.descriptions import (
QUERY_DESCRIPTIONS,
)
from openbb_core.provider.utils.descriptions import QUERY_DESCRIPTIONS


class RevenueGeographicQueryParams(QueryParams):
"""Revenue by Geographic Segments Query."""

symbol: str = Field(description=QUERY_DESCRIPTIONS.get("symbol", ""))
period: Literal["quarter", "annual"] = Field(
default="annual", description=QUERY_DESCRIPTIONS.get("period", "")
)
structure: Literal["hierarchical", "flat"] = Field(
default="flat", description="Structure of the returned data."
) # should always be flat

@field_validator("symbol", mode="before", check_fields=False)
@classmethod
def to_upper(cls, v: str):
"""Convert field to uppercase."""
return v.upper()

@field_validator("period", "structure", mode="before", check_fields=False)
@classmethod
def to_lower(cls, v: Optional[str]) -> Optional[str]:
"""Convert field to lowercase."""
return v.lower() if v else v


class RevenueGeographicData(Data):
"""Revenue by Geographic Segments Data."""
Expand All @@ -49,6 +35,11 @@ class RevenueGeographicData(Data):
filing_date: Optional[dateType] = Field(
default=None, description="The filing date of the report."
)
geographic_segment: Dict[str, ForceInt] = Field(
description="Dictionary of the revenue by geographic segment."
region: Optional[str] = Field(
default=None,
description="The region represented by the revenue data.",
)
revenue: Union[int, float] = Field(
description="The total revenue attributed to the region.",
json_schema_extra={"x-unit_measurement": "currency"},
)
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def test_equity_fundamental_ratios(params, headers):

@parametrize(
"params",
[({"symbol": "AAPL", "period": "annual", "structure": "flat", "provider": "fmp"})],
[({"symbol": "AAPL", "period": "annual", "provider": "fmp"})],
)
@pytest.mark.integration
def test_equity_fundamental_revenue_per_geography(params, headers):
Expand All @@ -877,7 +877,7 @@ def test_equity_fundamental_revenue_per_geography(params, headers):

@parametrize(
"params",
[({"symbol": "AAPL", "period": "annual", "structure": "flat", "provider": "fmp"})],
[({"symbol": "AAPL", "period": "annual", "provider": "fmp"})],
)
@pytest.mark.integration
def test_equity_fundamental_revenue_per_segment(params, headers):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,6 @@ def test_equity_fundamental_ratios(params, obb):
{
"symbol": "AAPL",
"period": "annual",
"structure": "flat",
"provider": "fmp",
}
),
Expand All @@ -840,7 +839,6 @@ def test_equity_fundamental_revenue_per_geography(params, obb):
{
"symbol": "AAPL",
"period": "annual",
"structure": "flat",
"provider": "fmp",
}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ async def ratios(
APIEx(
parameters={
"symbol": "AAPL",
"period": "annual",
"structure": "flat",
"period": "quarter",
"provider": "fmp",
}
),
Expand All @@ -385,7 +384,7 @@ async def revenue_per_geography(
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get the revenue geographic breakdown for a given company over time."""
"""Get the geographic breakdown of revenue for a given company over time."""
return await OBBject.from_query(Query(**locals()))


Expand All @@ -396,8 +395,7 @@ async def revenue_per_geography(
APIEx(
parameters={
"symbol": "AAPL",
"period": "annual",
"structure": "flat",
"period": "quarter",
"provider": "fmp",
}
),
Expand Down
72 changes: 40 additions & 32 deletions openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -22178,8 +22178,8 @@
"flag": null,
"message": null
},
"description": "Get the revenue geographic breakdown for a given company over time.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.equity.fundamental.revenue_per_geography(symbol='AAPL', provider='fmp')\nobb.equity.fundamental.revenue_per_geography(symbol='AAPL', period='annual', structure='flat', provider='fmp')\n```\n\n",
"description": "Get the geographic breakdown of revenue for a given company over time.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.equity.fundamental.revenue_per_geography(symbol='AAPL', provider='fmp')\nobb.equity.fundamental.revenue_per_geography(symbol='AAPL', period=quarter, provider='fmp')\n```\n\n",
"parameters": {
"standard": [
{
Expand All @@ -22189,25 +22189,21 @@
"default": "",
"optional": false,
"choices": null
},
}
],
"fmp": [
{
"name": "period",
"type": "Literal['quarter', 'annual']",
"description": "Time period of the data to return.",
"default": "annual",
"optional": true,
"choices": null
},
{
"name": "structure",
"type": "Literal['hierarchical', 'flat']",
"description": "Structure of the returned data.",
"default": "flat",
"optional": true,
"choices": null
"choices": [
"quarter",
"annual"
]
}
],
"fmp": []
]
},
"returns": {
"OBBject": [
Expand Down Expand Up @@ -22273,9 +22269,17 @@
"choices": null
},
{
"name": "geographic_segment",
"type": "int",
"description": "Dictionary of the revenue by geographic segment.",
"name": "region",
"type": "str",
"description": "The region represented by the revenue data.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "revenue",
"type": "Union[int, float]",
"description": "The total revenue attributed to the region.",
"default": "",
"optional": false,
"choices": null
Expand All @@ -22291,7 +22295,7 @@
"message": null
},
"description": "Get the revenue breakdown by business segment for a given company over time.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.equity.fundamental.revenue_per_segment(symbol='AAPL', provider='fmp')\nobb.equity.fundamental.revenue_per_segment(symbol='AAPL', period='annual', structure='flat', provider='fmp')\n```\n\n",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.equity.fundamental.revenue_per_segment(symbol='AAPL', provider='fmp')\nobb.equity.fundamental.revenue_per_segment(symbol='AAPL', period=quarter, provider='fmp')\n```\n\n",
"parameters": {
"standard": [
{
Expand All @@ -22301,25 +22305,21 @@
"default": "",
"optional": false,
"choices": null
},
}
],
"fmp": [
{
"name": "period",
"type": "Literal['quarter', 'annual']",
"description": "Time period of the data to return.",
"default": "annual",
"optional": true,
"choices": null
},
{
"name": "structure",
"type": "Literal['hierarchical', 'flat']",
"description": "Structure of the returned data.",
"default": "flat",
"optional": true,
"choices": null
"choices": [
"quarter",
"annual"
]
}
],
"fmp": []
]
},
"returns": {
"OBBject": [
Expand Down Expand Up @@ -22386,8 +22386,16 @@
},
{
"name": "business_line",
"type": "int",
"description": "Dictionary containing the revenue of the business line.",
"type": "str",
"description": "The business line represented by the revenue data.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "revenue",
"type": "Union[int, float]",
"description": "The total revenue attributed to the business line.",
"default": "",
"optional": false,
"choices": null
Expand Down
Loading
Loading