Skip to content

Commit

Permalink
Fixed bug w/ Statement object that caused concept_name of initial obj…
Browse files Browse the repository at this point in the history
…ect to be dropped. Added supporting methods for Statement/StatementHistory. Data objects now subclass BaseDataObjectMixin, which allows data object instances to be converted to json w/ 'to_json'
  • Loading branch information
McKalvan committed Feb 13, 2022
1 parent edee5c0 commit cba0295
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
31 changes: 23 additions & 8 deletions secpy/company_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from secpy.core.bulk_data import BulkDataEndpoint
from secpy.core.endpoint_enum import EndpointEnum
from secpy.core.mixins.base_data_object_mixin import BaseDataObjectMixin
from secpy.core.mixins.base_endpoint_mixin import BaseEndpointMixin
from types import SimpleNamespace

Expand Down Expand Up @@ -34,7 +35,7 @@ def _parse_data(self, data):
return CompanyFacts(data)


class CompanyFacts:
class CompanyFacts(BaseDataObjectMixin):
class CompanyFactsSchemaEnum(Enum):
CIK = "cik"
ENTITY_NAME = "entityName"
Expand Down Expand Up @@ -76,7 +77,7 @@ def get_concept(self, taxonomy, fact):

def get_statement_history(self):
"""
Groups facts together by the form type, financial year, and financial period to form a Statment instance
Groups facts together by the form type, financial year, and financial period to form a Statement instance
@return: List[Statement]
"""
filing_map = {}
Expand Down Expand Up @@ -105,7 +106,7 @@ def __get_form_period_map_for_concept(concept):
return form_period_unit_map


class StatementHistory:
class StatementHistory(BaseDataObjectMixin):
def __init__(self, form_period_filing_map):
self.__form_period_filing_map = form_period_filing_map

Expand Down Expand Up @@ -165,11 +166,11 @@ def get_statements_for_date_range(self, start_date=None, end_date=None, date_for
return result


class Statement:
class Statement(BaseDataObjectMixin):
def __init__(self, facts):
"""
Contains an aggregation of all facts available for a company for a particular form type, fiscal year, and fiscal period
@facts: Initial Fact instance to initialize object attributes
@facts: Initial Unit -> Fact map instance to initialize object attributes
"""
fact = facts[list(facts.keys())[0]]
self.start = fact.start
Expand All @@ -179,16 +180,30 @@ def __init__(self, facts):
self.fiscal_period = fact.fiscal_period
self.form = fact.form
self.filed = fact.filed
self.__facts_map = facts
self.__facts_map = self.__initialize_facts_map(facts, fact.concept_name)

@staticmethod
def __initialize_facts_map(facts, concept_name):
return {concept_name: facts}

def add_fact_to_map(self, fact_name, unit_to_val_map):
self.__facts_map[fact_name] = unit_to_val_map

def get_facts_for_unit(self, fact_name, unit):
return self.__facts_map[fact_name][unit]

def list_all_facts(self):
return self.__facts_map.keys()

def get_all_facts(self):
"""
Returns all facts for the given Statement
@return: dict, map of fact -> unit
"""
return self.__facts_map


class HasFactMixin:
class HasFactMixin(BaseDataObjectMixin):
UNITS = "units"

def __init__(self, data, tag):
Expand Down Expand Up @@ -225,7 +240,7 @@ def __init__(self, data, concept_name):
self.description = data.get(self.ConceptSchemaEnum.DESCRIPTION.value)


class Fact:
class Fact(BaseDataObjectMixin):
class FactSchemaEnum(Enum):
START = "start"
END = "end"
Expand Down
6 changes: 6 additions & 0 deletions secpy/core/mixins/base_data_object_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import json


class BaseDataObjectMixin:
def to_json(self):
return json.dumps(self, default=lambda o: o.__dict__)
9 changes: 6 additions & 3 deletions secpy/frames.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import Enum

from secpy.core.endpoint_enum import EndpointEnum
from secpy.core.mixins.base_data_object_mixin import BaseDataObjectMixin
from secpy.core.mixins.base_endpoint_mixin import BaseEndpointMixin
from secpy.core.utils.period_format_opts import PeriodFormatOpts

Expand All @@ -11,7 +12,7 @@ class FramesEndpoint(BaseEndpointMixin):
"""
_endpoint = EndpointEnum.FRAMES

def get_company_concept_for_ticker(self, taxonomy, concept, unit, period_format, use_instantaneous=False):
def get_company_concept_frame(self, taxonomy, concept, unit, period_format, use_instantaneous=False):
period_format_arg = PeriodFormatOpts.format_period_format_arg(period_format, use_instantaneous)
response = self._validate_args_and_make_request(self._endpoint,
TAXONOMY=taxonomy,
Expand All @@ -23,7 +24,9 @@ def get_company_concept_for_ticker(self, taxonomy, concept, unit, period_format,



class Frames:


class Frames(BaseDataObjectMixin):
class FramesSchemaEnum(Enum):
TAXONOMY = "taxonomy"
TAG = "tag"
Expand Down Expand Up @@ -54,7 +57,7 @@ def __set_company_frames(self, data):
return [CompanyFrame(obj) for obj in company_frames_arr]


class CompanyFrame:
class CompanyFrame(BaseDataObjectMixin):
class CompanyFrameSchemaEnum(Enum):
ACCN = "accn"
CIK = "cik"
Expand Down
7 changes: 4 additions & 3 deletions secpy/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from secpy.core.bulk_data import BulkDataEndpoint
from secpy.core.endpoint_enum import EndpointEnum
from secpy.core.mixins.base_data_object_mixin import BaseDataObjectMixin
from secpy.core.mixins.base_endpoint_mixin import BaseEndpointMixin
from secpy.core.network_client import NetworkClient
from secpy.core.utils.cik_opts import CIKOpts
Expand Down Expand Up @@ -42,7 +43,7 @@ def _parse_data(self, data):
return Submissions(data)


class Submissions:
class Submissions(BaseDataObjectMixin):
class SubmissionsSchemaEnum(Enum):
CIK = "cik"
ENTITY_TYPE = "entityType"
Expand Down Expand Up @@ -105,7 +106,7 @@ def __set_filings(self, data):
return Filings(filings, self.cik)


class Address:
class Address(BaseDataObjectMixin):
class AddressesSchemaEnum(Enum):
STREET_1 = "street1"
STREET_2 = "street2"
Expand All @@ -127,7 +128,7 @@ def __init__(self, data):
self.zip_code = data[self.AddressesSchemaEnum.ZIP_CODE.value]


class HasFilingsMixin:
class HasFilingsMixin(BaseDataObjectMixin):
def __init__(self, cik):
self.cik = cik

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
README = (HERE / "README.md").read_text()

PACKAGE_NAME = "sec-python"
VERSION = "0.1.2-alpha"
VERSION = "0.2.0-alpha"

setup(
name=PACKAGE_NAME,
Expand Down

0 comments on commit cba0295

Please sign in to comment.