# Path: marcotti/models/common/suppliers.py
# class Suppliers(BaseSchema):
#     __tablename__ = "suppliers"
# 
#     id = Column(Integer, Sequence('supplier_id_seq', start=1000), primary_key=True)
#     name = Column(Unicode(40), nullable=False)
# 
#     def __repr__(self):
#         return u"<Supplier(id={0}, name={1})>".format(self.id, self.name).encode('utf-8')


from datetime import date
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from marcotti.models.common.suppliers import Suppliers
import pandas as pd
        1. Combine data extracted from data sources.
        2. Transform and validate combined data into IDs and enums in the Marcotti database.
        3. Load transformed data into the database if it is not already there.

        :param entity: Data model name
        :param data: Data payloads from XML and/or CSV sources, in lists of dictionaries
        """
        getattr(self.loader, entity)(getattr(self.transformer, entity)(self.combiner(*data)))

    @staticmethod
    def combiner(*data_dicts):
        """
        Combine data from primary and supplemental data sources using unique ID of primary records.

        Returns a Pandas DataFrame of the combined data.

        :param data_dicts: List of data payloads from data sources, primary source first in list.
        :return: DataFrame of combined data.
        """
        data_frames = [pd.DataFrame(data) for data in data_dicts]
        if len(data_frames) > 1:
            new_frames = [data_frame.dropna(axis=1, how='all') for data_frame in data_frames]
            return pd.merge(*new_frames, on=['remote_id'])
        return data_frames[0]


class WorkflowBase(object):

    def __init__(self, session, supplier):
        self.session = session

# Path: marcotti/models/common/suppliers.py
# class Suppliers(BaseSchema):
#     __tablename__ = "suppliers"
# 
#     id = Column(Integer, Sequence('supplier_id_seq', start=1000), primary_key=True)
#     name = Column(Unicode(40), nullable=False)
# 
#     def __repr__(self):
#         return u"<Supplier(id={0}, name={1})>".format(self.id, self.name).encode('utf-8')


# Path: marcotti/etl/base/workflows.py
from datetime import date
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from marcotti.models.common.suppliers import Suppliers
import pandas as pd

        1. Combine data extracted from data sources.
        2. Transform and validate combined data into IDs and enums in the Marcotti database.
        3. Load transformed data into the database if it is not already there.

        :param entity: Data model name
        :param data: Data payloads from XML and/or CSV sources, in lists of dictionaries
        """
        getattr(self.loader, entity)(getattr(self.transformer, entity)(self.combiner(*data)))

    @staticmethod
    def combiner(*data_dicts):
        """
        Combine data from primary and supplemental data sources using unique ID of primary records.

        Returns a Pandas DataFrame of the combined data.

        :param data_dicts: List of data payloads from data sources, primary source first in list.
        :return: DataFrame of combined data.
        """
        data_frames = [pd.DataFrame(data) for data in data_dicts]
        if len(data_frames) > 1:
            new_frames = [data_frame.dropna(axis=1, how='all') for data_frame in data_frames]
            return pd.merge(*new_frames, on=['remote_id'])
        return data_frames[0]


class WorkflowBase(object):

    def __init__(self, session, supplier):
        self.session = session

        self.supplier_id = self.get_id(Suppliers, name=supplier) if supplier else None