コード例 #1
0
    def _render_header(cls, expectations):
        column = cls._get_column_name(expectations)

        new_block = RenderedHeaderContent(
            **{
                "header":
                RenderedStringTemplateContent(
                    **{
                        "content_block_type": "string_template",
                        "string_template": {
                            "template": convert_to_string_and_escape(column),
                            "tag": "h5",
                            "styling": {
                                "classes": ["m-0"]
                            }
                        }
                    }),
                "styling": {
                    "classes": ["col-12"],
                    "header": {
                        "classes": ["alert", "alert-secondary"]
                    }
                }
            })

        return expectations, new_block
 def _render_header(cls, evrs, content_blocks) -> None:
     content_blocks.append(
         RenderedHeaderContent(
             **{
                 "content_block_type":
                 "header",
                 "header":
                 RenderedStringTemplateContent(
                     **{
                         "content_block_type": "string_template",
                         "string_template": {
                             "template": "Overview",
                             "tag": "h5",
                             "styling": {
                                 "classes": ["m-0"]
                             },
                         },
                     }),
                 "styling": {
                     "classes": ["col-12", "p-0"],
                     "header": {
                         "classes": ["alert", "alert-secondary"]
                     },
                 },
             }))
コード例 #3
0
def test_render_header_component():
    header_component_content = RenderedHeaderContent(
        **{
            # "component_type": "header",
            "content_block_type": "header",
            "header": "Overview",
        }).to_json_dict()
    rendered_doc = ge.render.view.view.DefaultJinjaComponentView().render({
        "content_block":
        header_component_content,
        "section_loop": {
            "index": 1
        },
        "content_block_loop": {
            "index": 2
        },
    })
    print(rendered_doc)
    rendered_doc = rendered_doc.replace(" ", "").replace("\t",
                                                         "").replace("\n", "")
    assert (rendered_doc == """
<div id="section-1-content-block-2" >
    <div id="section-1-content-block-2-header" >
        <h5>
            Overview
        </h5>
    </div>
</div>""".replace(" ", "").replace("\t", "").replace("\n", ""))
コード例 #4
0
 def _get_header_content_block(cls,
                               header="",
                               subheader="",
                               highlight=True):
     return RenderedHeaderContent(
         **{
             "content_block_type":
             "header",
             "header":
             RenderedStringTemplateContent(
                 **{
                     "content_block_type": "string_template",
                     "string_template": {
                         "template": header,
                     },
                 }),
             "subheader":
             subheader,
             "styling": {
                 "classes": ["col-12"],
                 "header": {
                     "classes":
                     ["alert", "alert-secondary"] if highlight else []
                 },
             },
         })
コード例 #5
0
    def _render_header(cls, evrs, column_type=None):
        # NOTE: This logic is brittle
        try:
            column_name = evrs[0].expectation_config.kwargs["column"]
        except KeyError:
            column_name = "Table-level expectations"

        return RenderedHeaderContent(
            **{
                "content_block_type":
                "header",
                "header":
                RenderedStringTemplateContent(
                    **{
                        "content_block_type": "string_template",
                        "string_template": {
                            "template": convert_to_string_and_escape(
                                column_name),
                            "tooltip": {
                                "content": "expect_column_to_exist",
                                "placement": "top"
                            },
                            "tag": "h5",
                            "styling": {
                                "classes": ["m-0", "p-0"]
                            }
                        }
                    }),
                "subheader":
                RenderedStringTemplateContent(
                    **{
                        "content_block_type": "string_template",
                        "string_template": {
                            "template":
                            "Type: {column_type}".format(
                                column_type=column_type),
                            "tooltip": {
                                "content":
                                "expect_column_values_to_be_of_type <br>expect_column_values_to_be_in_type_list",
                            },
                            "tag":
                            "h6",
                            "styling": {
                                "classes": ["mt-1", "mb-0"]
                            }
                        }
                    }),
                # {
                #     "template": column_type,
                # },
                "styling": {
                    "classes": ["col-12", "p-0"],
                    "header": {
                        "classes": ["alert", "alert-secondary"]
                    }
                }
            })
コード例 #6
0
def test_render_section_page():
    section = RenderedSectionContent(
        **{
            "section_name": None,
            "content_blocks": [
                RenderedHeaderContent(
                    **{
                        "content_block_type": "header",
                        "header": "Overview",
                    }
                ),
                RenderedTableContent(
                    **{
                        "content_block_type": "table",
                        "header": "Dataset info",
                        "table": [
                            ["Number of variables", "12"],
                            ["Number of observations", "891"],
                        ],
                        "styling": {
                            "classes": ["col-6", "table-responsive"],
                            "styles": {"margin-top": "20px"},
                            "body": {"classes": ["table", "table-sm"]},
                        },
                    }
                ),
            ],
        }
    )

    rendered_doc = ge.render.view.view.DefaultMarkdownPageView().render(
        RenderedDocumentContent(sections=[section])
    )

    rendered_doc = rendered_doc.replace(" ", "").replace("\t", "").replace("\n", "")

    assert (
        rendered_doc
        == """
        #ValidationResults
        ##Overview
        ###Datasetinfo
        ||||------------|------------|Numberofvariables|12Numberofobservations|891
        -----------------------------------------------------------
        Poweredby[GreatExpectations](https://greatexpectations.io/)
        """.replace(
            " ", ""
        )
        .replace("\t", "")
        .replace("\n", "")
    )
コード例 #7
0
 def _render_expectation_suite_header(cls):
     return RenderedHeaderContent(
         **{
             "content_block_type":
             "header",
             "header":
             RenderedStringTemplateContent(
                 **{
                     "content_block_type": "string_template",
                     "string_template": {
                         "template": "Overview",
                         "tag": "h5",
                         "styling": {
                             "classes": ["m-0"]
                         },
                     },
                 }),
             "styling": {
                 "classes": ["col-12"],
                 "header": {
                     "classes": ["alert", "alert-secondary"]
                 },
             },
         })
コード例 #8
0
    def _render_validation_header(cls, validation_results):
        success = validation_results.success
        expectation_suite_name = validation_results.meta[
            "expectation_suite_name"]
        expectation_suite_path_components = (
            [".." for _ in range(len(expectation_suite_name.split(".")) + 3)] +
            ["expectations"] + str(expectation_suite_name).split("."))
        expectation_suite_path = (
            f"{os.path.join(*expectation_suite_path_components)}.html")
        # TODO: deprecate dual batch api support in 0.14
        batch_kwargs = (validation_results.meta.get("batch_kwargs", {})
                        or validation_results.meta.get("batch_spec", {}) or {})
        data_asset_name = batch_kwargs.get("data_asset_name")

        if success:
            success = "Succeeded"
            html_success_icon = (
                '<i class="fas fa-check-circle text-success" aria-hidden="true"></i>'
            )
        else:
            success = "Failed"
            html_success_icon = (
                '<i class="fas fa-times text-danger" aria-hidden="true"></i>')

        return RenderedHeaderContent(
            **{
                "content_block_type":
                "header",
                "header":
                RenderedStringTemplateContent(
                    **{
                        "content_block_type": "string_template",
                        "string_template": {
                            "template": "Overview",
                            "tag": "h5",
                            "styling": {
                                "classes": ["m-0"]
                            },
                        },
                    }),
                "subheader":
                RenderedStringTemplateContent(
                    **{
                        "content_block_type": "string_template",
                        "string_template": {
                            "template":
                            "${suite_title} ${expectation_suite_name}\n ${data_asset} ${data_asset_name}\n ${status_title} ${html_success_icon} ${success}",
                            "params": {
                                "suite_title": "Expectation Suite:",
                                "data_asset": "Data asset:",
                                "data_asset_name": data_asset_name,
                                "status_title": "Status:",
                                "expectation_suite_name":
                                expectation_suite_name,
                                "success": success,
                                "html_success_icon": html_success_icon,
                            },
                            "styling": {
                                "params": {
                                    "suite_title": {
                                        "classes": ["h6"]
                                    },
                                    "status_title": {
                                        "classes": ["h6"]
                                    },
                                    "expectation_suite_name": {
                                        "tag": "a",
                                        "attributes": {
                                            "href": expectation_suite_path
                                        },
                                    },
                                },
                                "classes": ["mb-0", "mt-1"],
                            },
                        },
                    }),
                "styling": {
                    "classes": ["col-12", "p-0"],
                    "header": {
                        "classes": ["alert", "alert-secondary"]
                    },
                },
            })
コード例 #9
0
def test_render_section_page():
    section = RenderedSectionContent(
        **{
            "section_name":
            None,
            "content_blocks": [
                RenderedHeaderContent(**{
                    "content_block_type": "header",
                    "header": "Overview",
                }),
                RenderedTableContent(
                    **{
                        "content_block_type":
                        "table",
                        "header":
                        "Dataset info",
                        "table": [
                            ["Number of variables", "12"],
                            ["Number of observations", "891"],
                        ],
                        "styling": {
                            "classes": ["col-6", "table-responsive"],
                            "styles": {
                                "margin-top": "20px"
                            },
                            "body": {
                                "classes": ["table", "table-sm"]
                            },
                        },
                    }),
            ],
        }).to_json_dict()

    rendered_doc = ge.render.view.view.DefaultJinjaSectionView().render({
        "section":
        section,
        "section_loop": {
            "index": 1
        },
    })  # .replace(" ", "").replace("\t", "").replace("\n", "")

    print(rendered_doc)

    rendered_doc = rendered_doc.replace(" ", "").replace("\t",
                                                         "").replace("\n", "")
    assert (
        rendered_doc ==
        """<div id="section-1" class="ge-section container-fluid mb-1 pb-1 pl-sm-3 px-0">
    <div class="row" >
<div id="content-block-1" >
    <div id="content-block-1-header" >
        <h5>
            Overview
        </h5>
    </div>
</div>
<div id="content-block-2" class="col-6 table-responsive" style="margin-top:20px;" >
    <div id="content-block-2-header" >
            <h5>
                Dataset info
            </h5>
        </div>
<table
  id="content-block-2-body"
  class="table table-sm"
  data-toggle="table"
>
      <thead hidden>
        <tr>
            <th>
            </th>
            <th>
            </th>
        </tr>
      </thead>
    <tbody>
      <tr>
          <td id="content-block-2-cell-1-1" ><div class="show-scrollbars">Number of variables</div></td><td id="content-block-2-cell-1-2" ><div class="show-scrollbars">12</div></td></tr><tr>
          <td id="content-block-2-cell-2-1" ><div class="show-scrollbars">Number of observations</div></td><td id="content-block-2-cell-2-2" ><div class="show-scrollbars">891</div></td></tr></tbody>
</table>
</div>
    </div>
</div>""".replace(" ", "").replace("\t", "").replace("\n", ""))
コード例 #10
0
    def render(cls, index_links_dict):
        sections = []
        cta_object = index_links_dict.pop("cta_object", None)

        try:
            content_blocks = []
            # site name header
            site_name_header_block = RenderedHeaderContent(
                **{
                    "content_block_type":
                    "header",
                    "header":
                    RenderedStringTemplateContent(
                        **{
                            "content_block_type": "string_template",
                            "string_template": {
                                "template": "$title_prefix | $site_name",
                                "params": {
                                    "site_name": index_links_dict.get(
                                        "site_name"),
                                    "title_prefix": "Data Docs",
                                },
                                "styling": {
                                    "params": {
                                        "title_prefix": {
                                            "tag": "strong"
                                        }
                                    }
                                },
                            },
                        }),
                    "styling": {
                        "classes": ["col-12", "ge-index-page-site-name-title"],
                        "header": {
                            "classes": ["alert", "alert-secondary"]
                        },
                    },
                })
            content_blocks.append(site_name_header_block)

            tabs = []

            if index_links_dict.get("validations_links"):
                tabs.append({
                    "tab_name":
                    "Validation Results",
                    "tab_content":
                    cls._generate_validation_results_link_table(
                        index_links_dict),
                })
            if index_links_dict.get("profiling_links"):
                tabs.append({
                    "tab_name":
                    "Profiling Results",
                    "tab_content":
                    cls._generate_profiling_results_link_table(
                        index_links_dict),
                })
            if index_links_dict.get("expectations_links"):
                tabs.append({
                    "tab_name":
                    "Expectation Suites",
                    "tab_content":
                    cls._generate_expectation_suites_link_table(
                        index_links_dict),
                })

            tabs_content_block = RenderedTabsContent(
                **{
                    "tabs": tabs,
                    "styling": {
                        "classes": ["col-12", "ge-index-page-tabs-container"],
                    },
                })

            content_blocks.append(tabs_content_block)

            section = RenderedSectionContent(
                **{
                    "section_name": index_links_dict.get("site_name"),
                    "content_blocks": content_blocks,
                })
            sections.append(section)

            index_page_document = RenderedDocumentContent(
                **{
                    "renderer_type": "SiteIndexPageRenderer",
                    "utm_medium": "index-page",
                    "sections": sections,
                })

            if cta_object:
                index_page_document.cta_footer = CallToActionRenderer.render(
                    cta_object)

            return index_page_document

        except Exception as e:
            exception_message = f"""\
An unexpected Exception occurred during data docs rendering.  Because of this error, certain parts of data docs will \
not be rendered properly and/or may not appear altogether.  Please use the trace, included in this message, to \
diagnose and repair the underlying issue.  Detailed information follows:
            """
            exception_traceback = traceback.format_exc()
            exception_message += (
                f'{type(e).__name__}: "{str(e)}".  Traceback: "{exception_traceback}".'
            )
            logger.error(exception_message)
コード例 #11
0
    def render(cls, index_links_dict):

        sections = []
        cta_object = index_links_dict.pop("cta_object", None)

        try:
            content_blocks = []
            # site name header
            site_name_header_block = RenderedHeaderContent(
                **{
                    "content_block_type":
                    "header",
                    "header":
                    RenderedStringTemplateContent(
                        **{
                            "content_block_type": "string_template",
                            "string_template": {
                                "template": "$title_prefix | $site_name",
                                "params": {
                                    "site_name": index_links_dict.get(
                                        "site_name"),
                                    "title_prefix": "Data Docs"
                                },
                                "styling": {
                                    "params": {
                                        "title_prefix": {
                                            "tag": "strong"
                                        }
                                    }
                                },
                            }
                        }),
                    "styling": {
                        "classes": ["col-12", "ge-index-page-site-name-title"],
                        "header": {
                            "classes": ["alert", "alert-secondary"]
                        }
                    }
                })
            content_blocks.append(site_name_header_block)

            table_rows = []
            table_header_row = []
            link_list_keys_to_render = []

            header_dict = OrderedDict(
                [["expectations_links", "Expectation Suite"],
                 ["validations_links", "Validation Results (run_id)"]])

            for link_lists_key, header in header_dict.items():
                if index_links_dict.get(link_lists_key):
                    class_header_str = link_lists_key.replace("_", "-")
                    class_str = "ge-index-page-table-{}-header".format(
                        class_header_str)
                    header = RenderedStringTemplateContent(
                        **{
                            "content_block_type": "string_template",
                            "string_template": {
                                "template": header,
                                "params": {},
                                "styling": {
                                    "classes": [class_str],
                                }
                            }
                        })
                    table_header_row.append(header)
                    link_list_keys_to_render.append(link_lists_key)

            generator_table = RenderedTableContent(
                **{
                    "content_block_type": "table",
                    "header_row": table_header_row,
                    "table": table_rows,
                    "styling": {
                        "classes": ["col-12", "ge-index-page-table-container"],
                        "styles": {
                            "margin-top": "10px"
                        },
                        "body": {
                            "classes": [
                                "table", "table-sm",
                                "ge-index-page-generator-table"
                            ]
                        }
                    }
                })

            table_rows += cls._generate_links_table_rows(
                index_links_dict,
                link_list_keys_to_render=link_list_keys_to_render)

            content_blocks.append(generator_table)

            if index_links_dict.get("profiling_links"):
                profiling_table_rows = []
                for profiling_link_dict in index_links_dict.get(
                        "profiling_links"):
                    profiling_table_rows.append([
                        RenderedStringTemplateContent(
                            **{
                                "content_block_type": "string_template",
                                "string_template": {
                                    "template": "$link_text",
                                    "params": {
                                        "link_text":
                                        profiling_link_dict[
                                            "expectation_suite_name"] + "." +
                                        profiling_link_dict["batch_identifier"]
                                    },
                                    "tag": "a",
                                    "styling": {
                                        "attributes": {
                                            "href":
                                            profiling_link_dict["filepath"]
                                        },
                                        "classes": [
                                            "ge-index-page-table-expectation-suite-link"
                                        ]
                                    }
                                },
                            })
                    ])
                content_blocks.append(
                    RenderedTableContent(
                        **{
                            "content_block_type": "table",
                            "header_row": ["Profiling Results"],
                            "table": profiling_table_rows,
                            "styling": {
                                "classes":
                                ["col-12", "ge-index-page-table-container"],
                                "styles": {
                                    "margin-top": "10px"
                                },
                                "body": {
                                    "classes": [
                                        "table", "table-sm",
                                        "ge-index-page-generator-table"
                                    ]
                                }
                            }
                        }))

            section = RenderedSectionContent(
                **{
                    "section_name": index_links_dict.get("site_name"),
                    "content_blocks": content_blocks
                })
            sections.append(section)

            index_page_document = RenderedDocumentContent(
                **{
                    "renderer_type": "SiteIndexPageRenderer",
                    "utm_medium": "index-page",
                    "sections": sections
                })

            if cta_object:
                index_page_document.cta_footer = CallToActionRenderer.render(
                    cta_object)

            return index_page_document

        except Exception as e:
            exception_message = f'''\
An unexpected Exception occurred during data docs rendering.  Because of this error, certain parts of data docs will \
not be rendered properly and/or may not appear altogether.  Please use the trace, included in this message, to \
diagnose and repair the underlying issue.  Detailed information follows:  
            '''
            exception_traceback = traceback.format_exc()
            exception_message += f'{type(e).__name__}: "{str(e)}".  Traceback: "{exception_traceback}".'
            logger.error(exception_message, e, exc_info=True)
コード例 #12
0
    def render(cls, index_links_dict):

        sections = []
        cta_object = index_links_dict.pop("cta_object", None)

        try:
            content_blocks = []
            # site name header
            site_name_header_block = RenderedHeaderContent(
                **{
                    "content_block_type":
                    "header",
                    "header":
                    RenderedStringTemplateContent(
                        **{
                            "content_block_type": "string_template",
                            "string_template": {
                                "template": "$title_prefix | $site_name",
                                "params": {
                                    "site_name": index_links_dict.get(
                                        "site_name"),
                                    "title_prefix": "Data Docs"
                                },
                                "styling": {
                                    "params": {
                                        "title_prefix": {
                                            "tag": "strong"
                                        }
                                    }
                                },
                            }
                        }),
                    "styling": {
                        "classes": ["col-12", "ge-index-page-site-name-title"],
                        "header": {
                            "classes": ["alert", "alert-secondary"]
                        }
                    }
                })
            content_blocks.append(site_name_header_block)

            table_rows = []
            table_header_row = []
            link_list_keys_to_render = []

            header_dict = OrderedDict(
                [["expectations_links", "Expectation Suite"],
                 ["validations_links", "Validation Results (run_id)"]])

            for link_lists_key, header in header_dict.items():
                if index_links_dict.get(link_lists_key):
                    class_header_str = link_lists_key.replace("_", "-")
                    class_str = "ge-index-page-table-{}-header".format(
                        class_header_str)
                    header = RenderedStringTemplateContent(
                        **{
                            "content_block_type": "string_template",
                            "string_template": {
                                "template": header,
                                "params": {},
                                "styling": {
                                    "classes": [class_str],
                                }
                            }
                        })
                    table_header_row.append(header)
                    link_list_keys_to_render.append(link_lists_key)

            generator_table = RenderedTableContent(
                **{
                    "content_block_type": "table",
                    "header_row": table_header_row,
                    "table": table_rows,
                    "styling": {
                        "classes": ["col-12", "ge-index-page-table-container"],
                        "styles": {
                            "margin-top": "10px"
                        },
                        "body": {
                            "classes": [
                                "table", "table-sm",
                                "ge-index-page-generator-table"
                            ]
                        }
                    }
                })

            table_rows += cls._generate_links_table_rows(
                index_links_dict,
                link_list_keys_to_render=link_list_keys_to_render)

            content_blocks.append(generator_table)

            if index_links_dict.get("profiling_links"):
                profiling_table_rows = []
                for profiling_link_dict in index_links_dict.get(
                        "profiling_links"):
                    profiling_table_rows.append([
                        RenderedStringTemplateContent(
                            **{
                                "content_block_type": "string_template",
                                "string_template": {
                                    "template": "$link_text",
                                    "params": {
                                        "link_text":
                                        profiling_link_dict[
                                            "expectation_suite_name"] + "." +
                                        profiling_link_dict["batch_identifier"]
                                    },
                                    "tag": "a",
                                    "styling": {
                                        "attributes": {
                                            "href":
                                            profiling_link_dict["filepath"]
                                        },
                                        "classes": [
                                            "ge-index-page-table-expectation-suite-link"
                                        ]
                                    }
                                },
                            })
                    ])
                content_blocks.append(
                    RenderedTableContent(
                        **{
                            "content_block_type": "table",
                            "header_row": ["Profiling Results"],
                            "table": profiling_table_rows,
                            "styling": {
                                "classes":
                                ["col-12", "ge-index-page-table-container"],
                                "styles": {
                                    "margin-top": "10px"
                                },
                                "body": {
                                    "classes": [
                                        "table", "table-sm",
                                        "ge-index-page-generator-table"
                                    ]
                                }
                            }
                        }))

            section = RenderedSectionContent(
                **{
                    "section_name": index_links_dict.get("site_name"),
                    "content_blocks": content_blocks
                })
            sections.append(section)

            index_page_document = RenderedDocumentContent(
                **{
                    "renderer_type": "SiteIndexPageRenderer",
                    "utm_medium": "index-page",
                    "sections": sections
                })

            if cta_object:
                index_page_document.cta_footer = CallToActionRenderer.render(
                    cta_object)

            return index_page_document

        except Exception as e:
            logger.error("Exception occurred during data docs rendering: ",
                         e,
                         exc_info=True)