pipeline_penguin.premise_output

PremiseOutputs are used to format and export the validation results;

View Source
"""PremiseOutputs are used to format and export the validation results;

"""

from .output_formatter_log import OutputFormatterLog
from .output_formatter_rsh import OutputFormatterRSH
from .output_exporter_terminal import OutputExporterTerminal
from .output_formatter_json import OutputFormatterJSON
from .output_exporter_http import OutputExporterHTTP

__all__ = [
    "OutputFormatterLog",
    "OutputFormatterRSH",
    "OutputExporterTerminal",
    "OutputFormatterJSON",
    "OutputExporterHTTP",
]
View Source
class OutputFormatterLog(OutputFormatter):
    """Contains the `OutputFormatterLog`constructor, used format the premise results into
    a human-readable message
    """

    def format(self, premise_output: PremiseOutput) -> str:
        """Construct a human-readable message based on the results of a premise validation.

        Args:
            premise_output: PremiseOutput object to be formatted
        Returns:
            str: Human-readable message with PremiseOutput's data
        """
        data_premise = premise_output.data_premise
        output_data = premise_output.to_serializeble_dict()

        json_data = json.dumps(output_data, indent=4, sort_keys=True, cls=NpEncoder)

        msg = f"Results of {data_premise.name} validation:\n{json_data}"
        return msg

Contains the OutputFormatterLogconstructor, used format the premise results into a human-readable message

#   OutputFormatterLog()
View Source
    def format(self, premise_output: PremiseOutput) -> str:
        """Construct a human-readable message based on the results of a premise validation.

        Args:
            premise_output: PremiseOutput object to be formatted
        Returns:
            str: Human-readable message with PremiseOutput's data
        """
        data_premise = premise_output.data_premise
        output_data = premise_output.to_serializeble_dict()

        json_data = json.dumps(output_data, indent=4, sort_keys=True, cls=NpEncoder)

        msg = f"Results of {data_premise.name} validation:\n{json_data}"
        return msg

Construct a human-readable message based on the results of a premise validation.

Args: premise_output: PremiseOutput object to be formatted Returns: str: Human-readable message with PremiseOutput's data

View Source
class OutputFormatterRSH(OutputFormatter):
    """Contains the `OutputFormatterRSH` constructor, used to sent data_premises results to an RSH cloud function."""

    def format(
        self,
        premise_output: PremiseOutput,
        project: str,
        spec: str,
        deploy: str,
        code: str,
        description: str,
    ) -> str:
        """Converts a premise_output into the json payload needed for an Raft Suite Hub endpoint.

        List of parameters with data contained by the resulting json::

        | Parameters                   | Type | Example                               | Description                                             |
        |------------------------------|------|---------------------------------------|---------------------------------------------------------|
        | body.project                 | str  | Project A                             | Name of the project                                     |
        | body.module                  | str  | pipeline-penguin                      | Name of the module                                      |
        | body.spec                    | str  | analytics_to_bigquery                 | Name of the pipeline                                    |
        | body.deploy                  | str  | 0.2                                   | Version of the Pipeline Penguin                         |
        | body.code                    | str  | 00-00                                 | Type of validation code and its status                  |
        | body.description             | str  | Checking if there is null on column X | Description of the validation done                      |
        | body.payload.data_premise    | str  | check_null                            | Name of the DataPremise                                 |
        | body.payload.data_node       | str  | data_a                                | Name of the DataNode                                    |
        | body.payload.column          | str  | product_id                            | Name of the column                                      |
        | body.payload.pass_validation | bool | true                                  | Indicated whether the data passed the validation or not |
        | body.payload.failed_count    | int  | 5                                     | Count of rows that failed the validation                |
        | body.payload.failed_values   | dict |                                       | Dict of examples that failed the validation             |


        Args:
            premise_output (PremiseOutput): PremiseOutput object to be formatted
            url (str): URL for the RSH cloud function
            project (str): Project name running the validations
            spec (str): Name of the pipeline
            deploy (str): Version of the Pipeline Penguin
            code (str): Type of validation code and its status
            description (str): Description of the validation done
        Returns:
            str: stringfied json with the premise_output's data.
        """
        payload = {
            "project": project,
            "module": "pipeline-penguin",
            "spec": spec,
            "deploy": deploy,
            "code": code,
            "description": description,
            "payload": {
                "data_premise": premise_output.data_premise,
                "data_node": premise_output.data_node,
                "column": premise_output.column,
                "pass_validation": premise_output.pass_validation,
                "failed_count": premise_output.failed_count,
                "failed_values": premise_output.failed_values.to_json(),
            },
        }

        return payload

Contains the OutputFormatterRSH constructor, used to sent data_premises results to an RSH cloud function.

#   OutputFormatterRSH()
#   def format( self, premise_output: pipeline_penguin.core.premise_output.premise_output.PremiseOutput, project: str, spec: str, deploy: str, code: str, description: str ) -> str:
View Source
    def format(
        self,
        premise_output: PremiseOutput,
        project: str,
        spec: str,
        deploy: str,
        code: str,
        description: str,
    ) -> str:
        """Converts a premise_output into the json payload needed for an Raft Suite Hub endpoint.

        List of parameters with data contained by the resulting json::

        | Parameters                   | Type | Example                               | Description                                             |
        |------------------------------|------|---------------------------------------|---------------------------------------------------------|
        | body.project                 | str  | Project A                             | Name of the project                                     |
        | body.module                  | str  | pipeline-penguin                      | Name of the module                                      |
        | body.spec                    | str  | analytics_to_bigquery                 | Name of the pipeline                                    |
        | body.deploy                  | str  | 0.2                                   | Version of the Pipeline Penguin                         |
        | body.code                    | str  | 00-00                                 | Type of validation code and its status                  |
        | body.description             | str  | Checking if there is null on column X | Description of the validation done                      |
        | body.payload.data_premise    | str  | check_null                            | Name of the DataPremise                                 |
        | body.payload.data_node       | str  | data_a                                | Name of the DataNode                                    |
        | body.payload.column          | str  | product_id                            | Name of the column                                      |
        | body.payload.pass_validation | bool | true                                  | Indicated whether the data passed the validation or not |
        | body.payload.failed_count    | int  | 5                                     | Count of rows that failed the validation                |
        | body.payload.failed_values   | dict |                                       | Dict of examples that failed the validation             |


        Args:
            premise_output (PremiseOutput): PremiseOutput object to be formatted
            url (str): URL for the RSH cloud function
            project (str): Project name running the validations
            spec (str): Name of the pipeline
            deploy (str): Version of the Pipeline Penguin
            code (str): Type of validation code and its status
            description (str): Description of the validation done
        Returns:
            str: stringfied json with the premise_output's data.
        """
        payload = {
            "project": project,
            "module": "pipeline-penguin",
            "spec": spec,
            "deploy": deploy,
            "code": code,
            "description": description,
            "payload": {
                "data_premise": premise_output.data_premise,
                "data_node": premise_output.data_node,
                "column": premise_output.column,
                "pass_validation": premise_output.pass_validation,
                "failed_count": premise_output.failed_count,
                "failed_values": premise_output.failed_values.to_json(),
            },
        }

        return payload

Converts a premise_output into the json payload needed for an Raft Suite Hub endpoint.

List of parameters with data contained by the resulting json::

Parameters Type Example Description
body.project str Project A Name of the project
body.module str pipeline-penguin Name of the module
body.spec str analytics_to_bigquery Name of the pipeline
body.deploy str 0.2 Version of the Pipeline Penguin
body.code str 00-00 Type of validation code and its status
body.description str Checking if there is null on column X Description of the validation done
body.payload.data_premise str check_null Name of the DataPremise
body.payload.data_node str data_a Name of the DataNode
body.payload.column str product_id Name of the column
body.payload.pass_validation bool true Indicated whether the data passed the validation or not
body.payload.failed_count int 5 Count of rows that failed the validation
body.payload.failed_values dict Dict of examples that failed the validation

Args: premise_output (PremiseOutput): PremiseOutput object to be formatted url (str): URL for the RSH cloud function project (str): Project name running the validations spec (str): Name of the pipeline deploy (str): Version of the Pipeline Penguin code (str): Type of validation code and its status description (str): Description of the validation done Returns: str: stringfied json with the premise_output's data.

View Source
class OutputExporterTerminal(OutputExporter):
    """Contains the `OutputExporterTerminal` constructor,used to send send the formatter's results to the console."""

    def export_output(self, content: str):
        """Sends a message to the console

        Args:
            content (str): message to be printed out
        """
        print(content)

Contains the OutputExporterTerminal constructor,used to send send the formatter's results to the console.

#   OutputExporterTerminal()
#   def export_output(self, content: str):
View Source
    def export_output(self, content: str):
        """Sends a message to the console

        Args:
            content (str): message to be printed out
        """
        print(content)

Sends a message to the console

Args: content (str): message to be printed out

View Source
class OutputFormatterJSON(OutputFormatter):
    """Contains the `OutputFormatterJSON`constructor, used format the premise
    results into a JavaScript Object Notation
    """

    def format(self, premise_output: PremiseOutput) -> str:
        """Abstract method for transforming the given PremiseOutput into the desired format."""

        premise_output_result = premise_output.to_serializeble_dict()
        json_premise_output_result = json.dumps(premise_output_result)

        return json_premise_output_result

Contains the OutputFormatterJSONconstructor, used format the premise results into a JavaScript Object Notation

#   OutputFormatterJSON()
View Source
    def format(self, premise_output: PremiseOutput) -> str:
        """Abstract method for transforming the given PremiseOutput into the desired format."""

        premise_output_result = premise_output.to_serializeble_dict()
        json_premise_output_result = json.dumps(premise_output_result)

        return json_premise_output_result

Abstract method for transforming the given PremiseOutput into the desired format.

View Source
class OutputExporterHTTP(OutputExporter):
    """Contains the `OutputExporterHTTP` constructor, used to send data_premises results to an HTTP endpoint"""

    def export_output(
        self,
        body: dict,
        url: str,
        method: str = "POST",
        credentials: Credentials = None,
    ):
        """Sends a request to a given HTTP destination

        Args:
            url (str): HTTP(s) address for sending the request
            method (str, optional): Method to use (GET, POST, PUT, etc). Defaults to "POST".
            body (dict, optional): Body of the request. Defaults to {}.
            credentials (Credentials, optional): Credentials to use for an authorized google request. Defaults to None.
        """
        response = ""

        if method == "POST":
            response = requests.post(url, body)
            pass

        return response

Contains the OutputExporterHTTP constructor, used to send data_premises results to an HTTP endpoint

#   OutputExporterHTTP()
#   def export_output( self, body: dict, url: str, method: str = 'POST', credentials: google.oauth2.service_account.Credentials = None ):
View Source
    def export_output(
        self,
        body: dict,
        url: str,
        method: str = "POST",
        credentials: Credentials = None,
    ):
        """Sends a request to a given HTTP destination

        Args:
            url (str): HTTP(s) address for sending the request
            method (str, optional): Method to use (GET, POST, PUT, etc). Defaults to "POST".
            body (dict, optional): Body of the request. Defaults to {}.
            credentials (Credentials, optional): Credentials to use for an authorized google request. Defaults to None.
        """
        response = ""

        if method == "POST":
            response = requests.post(url, body)
            pass

        return response

Sends a request to a given HTTP destination

Args: url (str): HTTP(s) address for sending the request method (str, optional): Method to use (GET, POST, PUT, etc). Defaults to "POST". body (dict, optional): Body of the request. Defaults to {}. credentials (Credentials, optional): Credentials to use for an authorized google request. Defaults to None.